@gravity-ui/app-builder 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +46 -0
- package/dist/commands/build/build-lib.d.ts +2 -0
- package/dist/commands/build/build-lib.js +39 -0
- package/dist/commands/build/build-service/client.d.ts +2 -0
- package/dist/commands/build/build-service/client.js +8 -0
- package/dist/commands/build/build-service/index.d.ts +2 -0
- package/dist/commands/build/build-service/index.js +46 -0
- package/dist/commands/build/build-service/server.d.ts +2 -0
- package/dist/commands/build/build-service/server.js +44 -0
- package/dist/commands/build/index.d.ts +2 -0
- package/dist/commands/build/index.js +33 -0
- package/dist/commands/dev/client.d.ts +3 -0
- package/dist/commands/dev/client.js +98 -0
- package/dist/commands/dev/index.d.ts +2 -0
- package/dist/commands/dev/index.js +101 -0
- package/dist/commands/dev/server.d.ts +3 -0
- package/dist/commands/dev/server.js +38 -0
- package/dist/common/babel/index.d.ts +15 -0
- package/dist/common/babel/index.js +17 -0
- package/dist/common/babel/ui-preset.d.ts +1 -0
- package/dist/common/babel/ui-preset.js +71 -0
- package/dist/common/child-process/controllable-script.d.ts +19 -0
- package/dist/common/child-process/controllable-script.js +125 -0
- package/dist/common/child-process/utils.d.ts +1 -0
- package/dist/common/child-process/utils.js +68 -0
- package/dist/common/command.d.ts +4 -0
- package/dist/common/command.js +2 -0
- package/dist/common/config.d.ts +5 -0
- package/dist/common/config.js +155 -0
- package/dist/common/env.d.ts +1 -0
- package/dist/common/env.js +5 -0
- package/dist/common/library/index.d.ts +2 -0
- package/dist/common/library/index.js +302 -0
- package/dist/common/links/link.d.ts +1 -0
- package/dist/common/links/link.js +109 -0
- package/dist/common/links/unlink.d.ts +3 -0
- package/dist/common/links/unlink.js +72 -0
- package/dist/common/logger/colors.d.ts +12 -0
- package/dist/common/logger/colors.js +8 -0
- package/dist/common/logger/index.d.ts +47 -0
- package/dist/common/logger/index.js +120 -0
- package/dist/common/logger/pretty-time.d.ts +2 -0
- package/dist/common/logger/pretty-time.js +51 -0
- package/dist/common/models/index.d.ts +184 -0
- package/dist/common/models/index.js +11 -0
- package/dist/common/package.d.ts +19 -0
- package/dist/common/package.js +42 -0
- package/dist/common/paths.d.ts +20 -0
- package/dist/common/paths.js +28 -0
- package/dist/common/s3-upload/compress.d.ts +2 -0
- package/dist/common/s3-upload/compress.js +23 -0
- package/dist/common/s3-upload/index.d.ts +3 -0
- package/dist/common/s3-upload/index.js +7 -0
- package/dist/common/s3-upload/s3-client.d.ts +20 -0
- package/dist/common/s3-upload/s3-client.js +111 -0
- package/dist/common/s3-upload/upload.d.ts +14 -0
- package/dist/common/s3-upload/upload.js +117 -0
- package/dist/common/s3-upload/webpack-plugin.d.ts +18 -0
- package/dist/common/s3-upload/webpack-plugin.js +53 -0
- package/dist/common/tempData.d.ts +13 -0
- package/dist/common/tempData.js +43 -0
- package/dist/common/typescript/compile.d.ts +5 -0
- package/dist/common/typescript/compile.js +72 -0
- package/dist/common/typescript/diagnostic.d.ts +2 -0
- package/dist/common/typescript/diagnostic.js +46 -0
- package/dist/common/typescript/transformers.d.ts +2 -0
- package/dist/common/typescript/transformers.js +114 -0
- package/dist/common/typescript/utils.d.ts +10 -0
- package/dist/common/typescript/utils.js +53 -0
- package/dist/common/typescript/watch.d.ts +7 -0
- package/dist/common/typescript/watch.js +60 -0
- package/dist/common/utils.d.ts +2 -0
- package/dist/common/utils.js +19 -0
- package/dist/common/webpack/compile.d.ts +2 -0
- package/dist/common/webpack/compile.js +31 -0
- package/dist/common/webpack/config.d.ts +23 -0
- package/dist/common/webpack/config.js +662 -0
- package/dist/common/webpack/progress-plugin.d.ts +11 -0
- package/dist/common/webpack/progress-plugin.js +64 -0
- package/dist/common/webpack/public-path.d.ts +1 -0
- package/dist/common/webpack/public-path.js +2 -0
- package/dist/common/webpack/storybook.d.ts +13 -0
- package/dist/common/webpack/storybook.js +86 -0
- package/dist/common/webpack/utils.d.ts +7 -0
- package/dist/common/webpack/utils.js +71 -0
- package/dist/create-cli.d.ts +54 -0
- package/dist/create-cli.js +221 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/package.json +154 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ProgressPlugin = void 0;
|
|
27
|
+
const webpack = __importStar(require("webpack"));
|
|
28
|
+
const pretty_time_1 = require("../logger/pretty-time");
|
|
29
|
+
class ProgressPlugin extends webpack.ProgressPlugin {
|
|
30
|
+
constructor({ logger }) {
|
|
31
|
+
super();
|
|
32
|
+
this._state = {};
|
|
33
|
+
this.handler = (percent, message, ...details) => {
|
|
34
|
+
const progress = Math.floor(percent * 100);
|
|
35
|
+
this._logger.status(`${this._logger.colors.green(`${progress}%`)} - ${this._logger.colors.yellow(message)}${details.length > 0 ? `: ${this._logger.colors.dim(...details)}` : ''}`);
|
|
36
|
+
};
|
|
37
|
+
this._logger = logger;
|
|
38
|
+
}
|
|
39
|
+
apply(compiler) {
|
|
40
|
+
super.apply(compiler);
|
|
41
|
+
hook(compiler, 'compile', () => {
|
|
42
|
+
this._logger.message('Start compilation');
|
|
43
|
+
this._logger.message(`Webpack v${compiler.webpack.version}`);
|
|
44
|
+
this._state.start = process.hrtime.bigint();
|
|
45
|
+
});
|
|
46
|
+
hook(compiler, 'invalid', (fileName, changeTime) => {
|
|
47
|
+
this._logger.verbose(`Invalidate file: ${fileName} at ${changeTime}`);
|
|
48
|
+
});
|
|
49
|
+
hook(compiler, 'done', (stats) => {
|
|
50
|
+
const time = this._state.start ? ' in ' + (0, pretty_time_1.elapsedTime)(this._state.start) : '';
|
|
51
|
+
const hasErrors = stats.hasErrors();
|
|
52
|
+
if (hasErrors) {
|
|
53
|
+
this._logger.error('Compiled with some errors' + time);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this._logger.success('Compiled successfully' + time);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ProgressPlugin = ProgressPlugin;
|
|
62
|
+
function hook(compiler, hookName, callback) {
|
|
63
|
+
compiler.hooks[hookName].tap(`app-builder: ${hookName}`, callback);
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare let __webpack_public_path__: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebpackMode } from './config';
|
|
2
|
+
import type { ClientConfig } from '../models';
|
|
3
|
+
import type * as Webpack from 'webpack';
|
|
4
|
+
type Mode = `${WebpackMode}`;
|
|
5
|
+
export declare function configureServiceWebpackConfig(mode: Mode, storybookConfig: Webpack.Configuration): Promise<Webpack.Configuration>;
|
|
6
|
+
export declare function configureWebpackConfigForStorybook(mode: Mode, userConfig?: ClientConfig): Promise<{
|
|
7
|
+
module: {
|
|
8
|
+
rules: Webpack.RuleSetRule[];
|
|
9
|
+
};
|
|
10
|
+
resolve: Webpack.ResolveOptions;
|
|
11
|
+
plugins: (((this: Webpack.Compiler, compiler: Webpack.Compiler) => void) | Webpack.WebpackPluginInstance)[];
|
|
12
|
+
}>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.configureWebpackConfigForStorybook = exports.configureServiceWebpackConfig = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
|
|
9
|
+
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
10
|
+
const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
|
|
11
|
+
const config_1 = require("./config");
|
|
12
|
+
const config_2 = require("../config");
|
|
13
|
+
const models_1 = require("../models");
|
|
14
|
+
async function configureServiceWebpackConfig(mode, storybookConfig) {
|
|
15
|
+
var _a, _b, _c, _d, _e;
|
|
16
|
+
const serviceConfig = await (0, config_2.getProjectConfig)(mode === "production" /* WebpackMode.Prod */ ? 'build' : 'dev', {});
|
|
17
|
+
if (!(0, models_1.isServiceConfig)(serviceConfig)) {
|
|
18
|
+
throw new Error('configureServiceWebpackConfig can be used only for services, but got the library config');
|
|
19
|
+
}
|
|
20
|
+
const webpackConfig = await configureWebpackConfigForStorybook(mode, serviceConfig.client);
|
|
21
|
+
return Object.assign(Object.assign({}, storybookConfig), { plugins: [...((_a = storybookConfig.plugins) !== null && _a !== void 0 ? _a : []), ...webpackConfig.plugins], resolve: Object.assign(Object.assign(Object.assign({}, storybookConfig.resolve), webpackConfig.resolve), { alias: Object.assign(Object.assign({}, (_b = storybookConfig.resolve) === null || _b === void 0 ? void 0 : _b.alias), webpackConfig.resolve.alias), modules: [
|
|
22
|
+
...(((_c = storybookConfig.resolve) === null || _c === void 0 ? void 0 : _c.modules) || []),
|
|
23
|
+
...(webpackConfig.resolve.modules || []),
|
|
24
|
+
], extensions: [
|
|
25
|
+
...((_e = (_d = storybookConfig.resolve) === null || _d === void 0 ? void 0 : _d.extensions) !== null && _e !== void 0 ? _e : []),
|
|
26
|
+
...(webpackConfig.resolve.extensions || []),
|
|
27
|
+
] }), module: Object.assign(Object.assign({}, storybookConfig.module), { rules: webpackConfig.module.rules }) });
|
|
28
|
+
}
|
|
29
|
+
exports.configureServiceWebpackConfig = configureServiceWebpackConfig;
|
|
30
|
+
async function configureWebpackConfigForStorybook(mode, userConfig = {}) {
|
|
31
|
+
var _a;
|
|
32
|
+
const isEnvDevelopment = mode === "development" /* WebpackMode.Dev */;
|
|
33
|
+
const isEnvProduction = mode === "production" /* WebpackMode.Prod */;
|
|
34
|
+
const config = await (0, config_2.normalizeConfig)({
|
|
35
|
+
client: Object.assign(Object.assign({}, userConfig), { includes: ((_a = userConfig.includes) !== null && _a !== void 0 ? _a : []).concat(['.storybook']) }),
|
|
36
|
+
});
|
|
37
|
+
const helperOptions = {
|
|
38
|
+
isEnvDevelopment,
|
|
39
|
+
isEnvProduction,
|
|
40
|
+
config: config.client,
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
module: {
|
|
44
|
+
rules: (0, config_1.configureModuleRules)(helperOptions),
|
|
45
|
+
},
|
|
46
|
+
resolve: (0, config_1.configureResolve)(helperOptions),
|
|
47
|
+
plugins: configurePlugins(helperOptions),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.configureWebpackConfigForStorybook = configureWebpackConfigForStorybook;
|
|
51
|
+
function configurePlugins({ isEnvDevelopment, isEnvProduction, config }) {
|
|
52
|
+
const plugins = [];
|
|
53
|
+
if (config.definitions) {
|
|
54
|
+
// eslint-disable-next-line security/detect-non-literal-require
|
|
55
|
+
const webpack = require(path_1.default.resolve(process.cwd(), 'node_modules/webpack'));
|
|
56
|
+
plugins.push(new webpack.DefinePlugin(Object.assign({}, config.definitions)));
|
|
57
|
+
}
|
|
58
|
+
if (config.monaco) {
|
|
59
|
+
const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
60
|
+
plugins.push(new MonacoEditorWebpackPlugin(Object.assign(Object.assign({}, config.monaco), {
|
|
61
|
+
// currently, workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
62
|
+
// service instead
|
|
63
|
+
publicPath: '/' })));
|
|
64
|
+
}
|
|
65
|
+
if (isEnvDevelopment) {
|
|
66
|
+
plugins.push(new react_refresh_webpack_plugin_1.default());
|
|
67
|
+
}
|
|
68
|
+
if (isEnvProduction) {
|
|
69
|
+
plugins.push(new mini_css_extract_plugin_1.default({
|
|
70
|
+
filename: 'css/[name].[contenthash:8].css',
|
|
71
|
+
chunkFilename: 'css/[name].[contenthash:8].chunk.css',
|
|
72
|
+
ignoreOrder: true,
|
|
73
|
+
}));
|
|
74
|
+
plugins.push(new css_minimizer_webpack_plugin_1.default({
|
|
75
|
+
minimizerOptions: {
|
|
76
|
+
preset: [
|
|
77
|
+
'default',
|
|
78
|
+
{
|
|
79
|
+
svgo: false,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
return plugins;
|
|
86
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type webpack from 'webpack';
|
|
2
|
+
import type { Logger } from '../logger';
|
|
3
|
+
export declare function webpackCompilerHandlerFactory(logger: Logger, onCompilationEnd?: () => void): (err?: Error, stats?: webpack.Stats) => Promise<void>;
|
|
4
|
+
export declare function resolveTsconfigPathsToAlias(tsConfigPath: string): {
|
|
5
|
+
aliases: Record<string, string[]>;
|
|
6
|
+
modules: string[];
|
|
7
|
+
} | undefined;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveTsconfigPathsToAlias = exports.webpackCompilerHandlerFactory = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const pretty_time_1 = require("../logger/pretty-time");
|
|
10
|
+
function webpackCompilerHandlerFactory(logger, onCompilationEnd) {
|
|
11
|
+
return async (err, stats) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
logger.panic(err.message, err);
|
|
14
|
+
}
|
|
15
|
+
if (stats) {
|
|
16
|
+
logger.message('Stats:\n' +
|
|
17
|
+
stats.toString({
|
|
18
|
+
preset: 'errors-warnings',
|
|
19
|
+
colors: process.stdout.isTTY,
|
|
20
|
+
assets: logger.isVerbose,
|
|
21
|
+
modules: logger.isVerbose,
|
|
22
|
+
entrypoints: logger.isVerbose,
|
|
23
|
+
timings: logger.isVerbose,
|
|
24
|
+
}));
|
|
25
|
+
if (stats.hasErrors()) {
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (onCompilationEnd) {
|
|
30
|
+
await onCompilationEnd();
|
|
31
|
+
}
|
|
32
|
+
const time = (stats === null || stats === void 0 ? void 0 : stats.endTime) - (stats === null || stats === void 0 ? void 0 : stats.startTime);
|
|
33
|
+
logger.success(`Client was successfully compiled in ${(0, pretty_time_1.prettyTime)(BigInt(time) * BigInt(1000000))}`);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.webpackCompilerHandlerFactory = webpackCompilerHandlerFactory;
|
|
37
|
+
const endStarRe = /\/?\*$/;
|
|
38
|
+
function resolveTsconfigPathsToAlias(tsConfigPath) {
|
|
39
|
+
if (!fs_1.default.existsSync(tsConfigPath) || !fs_1.default.statSync(tsConfigPath).isFile) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const { paths = {}, baseUrl } = readJsonConfig(tsConfigPath).compilerOptions || {};
|
|
43
|
+
if (!baseUrl) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const basePath = path_1.default.resolve(path_1.default.dirname(tsConfigPath), baseUrl);
|
|
47
|
+
const aliases = {};
|
|
48
|
+
const modules = [];
|
|
49
|
+
for (const [key, value] of Object.entries(paths)) {
|
|
50
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const name = key.replace(endStarRe, '');
|
|
54
|
+
if (name === '' || name === '.') {
|
|
55
|
+
modules.push(...value.map((v) => path_1.default.resolve(basePath, `${v}`.replace(endStarRe, ''))));
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
aliases[name] = value.map((v) => path_1.default.resolve(basePath, `${v}`.replace(endStarRe, '')));
|
|
59
|
+
}
|
|
60
|
+
return { aliases, modules };
|
|
61
|
+
}
|
|
62
|
+
exports.resolveTsconfigPathsToAlias = resolveTsconfigPathsToAlias;
|
|
63
|
+
function readJsonConfig(pathname) {
|
|
64
|
+
try {
|
|
65
|
+
const json = fs_1.default.readFileSync(pathname, 'utf-8');
|
|
66
|
+
return Object.assign({}, JSON.parse(json));
|
|
67
|
+
}
|
|
68
|
+
catch (_a) {
|
|
69
|
+
throw new Error(`Couldn't read config ${pathname}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type CliArgs = Awaited<ReturnType<typeof createCli>>;
|
|
2
|
+
export declare function createCli(argv: string[]): {
|
|
3
|
+
[x: string]: unknown;
|
|
4
|
+
verbose: boolean;
|
|
5
|
+
inspect: number | undefined;
|
|
6
|
+
target: "client" | "server" | undefined;
|
|
7
|
+
c: unknown;
|
|
8
|
+
env: string[] | undefined;
|
|
9
|
+
inspectBrk: number | undefined;
|
|
10
|
+
"inspect-brk": number | undefined;
|
|
11
|
+
entryFilter: string[] | undefined;
|
|
12
|
+
"entry-filter": string[] | undefined;
|
|
13
|
+
disableReactRefresh: boolean | undefined;
|
|
14
|
+
"disable-react-refresh": boolean | undefined;
|
|
15
|
+
lazyCompilation: boolean | undefined;
|
|
16
|
+
"lazy-compilation": boolean | undefined;
|
|
17
|
+
reactProfiling: boolean | undefined;
|
|
18
|
+
"react-profiling": boolean | undefined;
|
|
19
|
+
analyzeBundle: "true" | "statoscope" | undefined;
|
|
20
|
+
"analyze-bundle": "true" | "statoscope" | undefined;
|
|
21
|
+
disableForkTsChecker: boolean | undefined;
|
|
22
|
+
"disable-fork-ts-checker": boolean | undefined;
|
|
23
|
+
disableSourceMapGeneration: boolean | undefined;
|
|
24
|
+
"disable-source-map-generation": boolean | undefined;
|
|
25
|
+
cdn: "false" | undefined;
|
|
26
|
+
_: (string | number)[];
|
|
27
|
+
$0: string;
|
|
28
|
+
} | Promise<{
|
|
29
|
+
[x: string]: unknown;
|
|
30
|
+
verbose: boolean;
|
|
31
|
+
inspect: number | undefined;
|
|
32
|
+
target: "client" | "server" | undefined;
|
|
33
|
+
c: unknown;
|
|
34
|
+
env: string[] | undefined;
|
|
35
|
+
inspectBrk: number | undefined;
|
|
36
|
+
"inspect-brk": number | undefined;
|
|
37
|
+
entryFilter: string[] | undefined;
|
|
38
|
+
"entry-filter": string[] | undefined;
|
|
39
|
+
disableReactRefresh: boolean | undefined;
|
|
40
|
+
"disable-react-refresh": boolean | undefined;
|
|
41
|
+
lazyCompilation: boolean | undefined;
|
|
42
|
+
"lazy-compilation": boolean | undefined;
|
|
43
|
+
reactProfiling: boolean | undefined;
|
|
44
|
+
"react-profiling": boolean | undefined;
|
|
45
|
+
analyzeBundle: "true" | "statoscope" | undefined;
|
|
46
|
+
"analyze-bundle": "true" | "statoscope" | undefined;
|
|
47
|
+
disableForkTsChecker: boolean | undefined;
|
|
48
|
+
"disable-fork-ts-checker": boolean | undefined;
|
|
49
|
+
disableSourceMapGeneration: boolean | undefined;
|
|
50
|
+
"disable-source-map-generation": boolean | undefined;
|
|
51
|
+
cdn: "false" | undefined;
|
|
52
|
+
_: (string | number)[];
|
|
53
|
+
$0: string;
|
|
54
|
+
}>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createCli = void 0;
|
|
7
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
+
const helpers_1 = require("yargs/helpers");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const logger_1 = __importDefault(require("./common/logger"));
|
|
11
|
+
const config_1 = require("./common/config");
|
|
12
|
+
const models_1 = require("./common/models");
|
|
13
|
+
function createCli(argv) {
|
|
14
|
+
const cli = (0, yargs_1.default)(argv).parserConfiguration({
|
|
15
|
+
'boolean-negation': false,
|
|
16
|
+
});
|
|
17
|
+
cli.scriptName('app-builder')
|
|
18
|
+
.usage('Usage: $0 <command> [options]')
|
|
19
|
+
.env('APP_BUILDER')
|
|
20
|
+
.alias('h', 'help')
|
|
21
|
+
.alias('v', 'version');
|
|
22
|
+
try {
|
|
23
|
+
cli.version('version', 'Show the version of the app-builder CLI package in the current project', getVersionInfo());
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
// ignore
|
|
27
|
+
}
|
|
28
|
+
return cli
|
|
29
|
+
.option('verbose', {
|
|
30
|
+
default: false,
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
describe: 'Turn on verbose output',
|
|
33
|
+
global: true,
|
|
34
|
+
})
|
|
35
|
+
.option('c', {
|
|
36
|
+
alias: 'config',
|
|
37
|
+
describe: 'Configuration file to use',
|
|
38
|
+
})
|
|
39
|
+
.option('env', {
|
|
40
|
+
describe: 'Environment passed to the configuration when it is a function.',
|
|
41
|
+
type: 'array',
|
|
42
|
+
string: true,
|
|
43
|
+
coerce: (args) => {
|
|
44
|
+
if (!args) {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
return args.reduce((values, value) => {
|
|
48
|
+
if (value.endsWith('=')) {
|
|
49
|
+
value = value.concat('""');
|
|
50
|
+
}
|
|
51
|
+
// This ensures we're only splitting by the first `=`
|
|
52
|
+
const [allKeys, val] = value.split(/[=](.+)/, 2);
|
|
53
|
+
if (typeof allKeys === 'string') {
|
|
54
|
+
const splitKeys = allKeys.split(/\.(?!$)/);
|
|
55
|
+
let prevRef = values;
|
|
56
|
+
splitKeys.forEach((someKey, index) => {
|
|
57
|
+
if (!prevRef[someKey]) {
|
|
58
|
+
prevRef[someKey] = {};
|
|
59
|
+
}
|
|
60
|
+
if (typeof prevRef[someKey] === 'string') {
|
|
61
|
+
prevRef[someKey] = {};
|
|
62
|
+
}
|
|
63
|
+
if (index === splitKeys.length - 1) {
|
|
64
|
+
if (typeof val === 'string') {
|
|
65
|
+
prevRef[someKey] = val;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
prevRef[someKey] = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
prevRef = prevRef[someKey];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return values;
|
|
75
|
+
}, {});
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
.command({
|
|
79
|
+
command: 'dev',
|
|
80
|
+
describe: 'Start development server. Watches files, rebuilds, and hot reloads if something changes',
|
|
81
|
+
builder: (_) => _.option('target', {
|
|
82
|
+
describe: 'Select compilation unit',
|
|
83
|
+
choices: ['client', 'server'],
|
|
84
|
+
})
|
|
85
|
+
.option('inspect', {
|
|
86
|
+
group: 'Server',
|
|
87
|
+
type: 'number',
|
|
88
|
+
describe: 'Opens a port for debugging',
|
|
89
|
+
})
|
|
90
|
+
.option('inspect-brk', {
|
|
91
|
+
group: 'Server',
|
|
92
|
+
type: 'number',
|
|
93
|
+
describe: 'Opens a port for debugging. Will block until debugger is attached',
|
|
94
|
+
})
|
|
95
|
+
.option('entry-filter', {
|
|
96
|
+
group: 'Client',
|
|
97
|
+
type: 'string',
|
|
98
|
+
describe: 'Filters entries from src/ui/entries/* included in webpack bundle',
|
|
99
|
+
array: true,
|
|
100
|
+
})
|
|
101
|
+
.option('disable-fork-ts-checker', {
|
|
102
|
+
group: 'Client',
|
|
103
|
+
describe: 'Disable typescript checks',
|
|
104
|
+
type: 'boolean',
|
|
105
|
+
})
|
|
106
|
+
.option('disable-react-refresh', {
|
|
107
|
+
group: 'Client',
|
|
108
|
+
describe: 'Disable react-refresh',
|
|
109
|
+
type: 'boolean',
|
|
110
|
+
})
|
|
111
|
+
.option('lazy-compilation', {
|
|
112
|
+
group: 'Client',
|
|
113
|
+
type: 'boolean',
|
|
114
|
+
describe: 'Enable lazy compilation',
|
|
115
|
+
}),
|
|
116
|
+
handler: handlerP(getCommandHandler('dev', (args, cmd) => {
|
|
117
|
+
if ((0, models_1.isLibraryConfig)(args)) {
|
|
118
|
+
throw new Error('dev command can be used only for services, but got the library config');
|
|
119
|
+
}
|
|
120
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
121
|
+
if (args.server) {
|
|
122
|
+
if (args.server.inspect !== undefined) {
|
|
123
|
+
args.server.inspect = args.server.inspect || 9229;
|
|
124
|
+
}
|
|
125
|
+
if (args.server.inspectBrk !== undefined) {
|
|
126
|
+
args.server.inspectBrk = args.server.inspectBrk || 9229;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
cmd(args);
|
|
130
|
+
// Return an empty promise to prevent handlerP from exiting early.
|
|
131
|
+
// The development server shouldn't ever exit until the user directly
|
|
132
|
+
// kills it so this is fine.
|
|
133
|
+
return new Promise(() => { });
|
|
134
|
+
})),
|
|
135
|
+
})
|
|
136
|
+
.command({
|
|
137
|
+
command: 'build',
|
|
138
|
+
describe: 'Make production build',
|
|
139
|
+
builder: (_) => _.option('target', {
|
|
140
|
+
describe: 'Select compilation unit',
|
|
141
|
+
choices: ['client', 'server'],
|
|
142
|
+
})
|
|
143
|
+
.option('entry-filter', {
|
|
144
|
+
group: 'Client',
|
|
145
|
+
type: 'string',
|
|
146
|
+
describe: 'Filters entries from src/ui/entries/* included in webpack bundle',
|
|
147
|
+
array: true,
|
|
148
|
+
})
|
|
149
|
+
.option('react-profiling', {
|
|
150
|
+
group: 'Client',
|
|
151
|
+
describe: 'Enable react profiling',
|
|
152
|
+
type: 'boolean',
|
|
153
|
+
})
|
|
154
|
+
.option('analyze-bundle', {
|
|
155
|
+
group: 'Client',
|
|
156
|
+
describe: 'Analyze bundle',
|
|
157
|
+
choices: ['true', 'statoscope'],
|
|
158
|
+
})
|
|
159
|
+
.option('disable-fork-ts-checker', {
|
|
160
|
+
group: 'Client',
|
|
161
|
+
describe: 'Disable typescript checks',
|
|
162
|
+
type: 'boolean',
|
|
163
|
+
})
|
|
164
|
+
.option('disable-source-map-generation', {
|
|
165
|
+
group: 'Client',
|
|
166
|
+
describe: 'Disable source map generation',
|
|
167
|
+
type: 'boolean',
|
|
168
|
+
})
|
|
169
|
+
.option('cdn', {
|
|
170
|
+
group: 'Client',
|
|
171
|
+
describe: 'Disable upload files to CDN',
|
|
172
|
+
choices: ['false'],
|
|
173
|
+
}),
|
|
174
|
+
handler: handlerP(getCommandHandler('build')),
|
|
175
|
+
})
|
|
176
|
+
.wrap(cli.terminalWidth())
|
|
177
|
+
.strict()
|
|
178
|
+
.demandCommand(1, `Pass --help to see all available commands and options.`)
|
|
179
|
+
.recommendCommands()
|
|
180
|
+
.parse((0, helpers_1.hideBin)(argv));
|
|
181
|
+
}
|
|
182
|
+
exports.createCli = createCli;
|
|
183
|
+
function getVersionInfo() {
|
|
184
|
+
const { version } = require('../package.json');
|
|
185
|
+
return `app-builder CLI version: ${version}`;
|
|
186
|
+
}
|
|
187
|
+
function handlerP(fn) {
|
|
188
|
+
return (args) => {
|
|
189
|
+
Promise.resolve(fn(args)).then(() => process.exit(0), (err) => logger_1.default.panic(err));
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function getCommandHandler(command, handler) {
|
|
193
|
+
return async (argv) => {
|
|
194
|
+
logger_1.default.setVerbose(Boolean(argv.verbose));
|
|
195
|
+
const config = await (0, config_1.getProjectConfig)(command, argv);
|
|
196
|
+
const args = Object.assign(Object.assign({}, config), { logger: logger_1.default });
|
|
197
|
+
const localCmd = resolveLocalCommand(command);
|
|
198
|
+
logger_1.default.verbose(`running command: ${command}`);
|
|
199
|
+
return handler ? handler(args, localCmd) : localCmd(args);
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function resolveLocalCommand(command) {
|
|
203
|
+
try {
|
|
204
|
+
const cmdPath = path_1.default.resolve(__dirname, `commands/${command}`);
|
|
205
|
+
if (!cmdPath)
|
|
206
|
+
return logger_1.default.panic(`There was a problem loading the ${command} command.`);
|
|
207
|
+
logger_1.default.verbose(`loading command from: ${cmdPath}`);
|
|
208
|
+
// eslint-disable-next-line security/detect-non-literal-require
|
|
209
|
+
let cmd = require(cmdPath);
|
|
210
|
+
if (cmd.__esModule) {
|
|
211
|
+
cmd = cmd.default;
|
|
212
|
+
}
|
|
213
|
+
if (cmd instanceof Function) {
|
|
214
|
+
return cmd;
|
|
215
|
+
}
|
|
216
|
+
return logger_1.default.panic(`Handler for command "${command}" is not a function.`);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
return logger_1.default.panic(`There was a problem loading the "${command}" command.`, err);
|
|
220
|
+
}
|
|
221
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { configureWebpackConfigForStorybook, configureServiceWebpackConfig, } from './common/webpack/storybook';
|
|
2
|
+
export { createTransformPathsToLocalModules } from './common/typescript/transformers';
|
|
3
|
+
export type { ProjectConfig, ServiceConfig, LibraryConfig } from './common/models';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransformPathsToLocalModules = exports.configureServiceWebpackConfig = exports.configureWebpackConfigForStorybook = void 0;
|
|
4
|
+
var storybook_1 = require("./common/webpack/storybook");
|
|
5
|
+
Object.defineProperty(exports, "configureWebpackConfigForStorybook", { enumerable: true, get: function () { return storybook_1.configureWebpackConfigForStorybook; } });
|
|
6
|
+
Object.defineProperty(exports, "configureServiceWebpackConfig", { enumerable: true, get: function () { return storybook_1.configureServiceWebpackConfig; } });
|
|
7
|
+
var transformers_1 = require("./common/typescript/transformers");
|
|
8
|
+
Object.defineProperty(exports, "createTransformPathsToLocalModules", { enumerable: true, get: function () { return transformers_1.createTransformPathsToLocalModules; } });
|