@modern-js/app-tools 1.21.2 → 2.0.0-beta.0
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 +139 -0
- package/dist/js/modern/analyze/constants.js +1 -0
- package/dist/js/modern/analyze/generateCode.js +118 -16
- package/dist/js/modern/analyze/getBundleEntry.js +3 -2
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +198 -0
- package/dist/js/modern/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +8 -28
- package/dist/js/modern/analyze/getClientRoutes/index.js +2 -0
- package/dist/js/modern/analyze/getClientRoutes/utils.js +21 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +31 -12
- package/dist/js/modern/analyze/index.js +2 -1
- package/dist/js/modern/analyze/nestedRoutes.js +127 -0
- package/dist/js/modern/analyze/templates.js +164 -10
- package/dist/js/modern/analyze/utils.js +2 -1
- package/dist/js/modern/builder/builderPlugins/compatModern.js +226 -0
- package/dist/js/modern/builder/createHtmlConfig.js +58 -0
- package/dist/js/modern/builder/createOutputConfig.js +67 -0
- package/dist/js/modern/builder/createSourceConfig.js +85 -0
- package/dist/js/modern/builder/createToolsConfig.js +94 -0
- package/dist/js/modern/builder/index.js +106 -0
- package/dist/js/modern/builder/share.js +48 -0
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +37 -0
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +44 -0
- package/dist/js/modern/commands/build.js +41 -95
- package/dist/js/modern/commands/dev.js +15 -19
- package/dist/js/modern/commands/inspect.js +17 -58
- package/dist/js/modern/commands/start.js +2 -1
- package/dist/js/modern/index.js +14 -4
- package/dist/js/modern/locale/en.js +0 -1
- package/dist/js/modern/locale/zh.js +0 -1
- package/dist/js/modern/utils/commands.js +5 -0
- package/dist/js/modern/utils/createCompiler.js +37 -40
- package/dist/js/modern/utils/createServer.js +16 -0
- package/dist/js/modern/utils/printInstructions.js +1 -1
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/generateCode.js +121 -14
- package/dist/js/node/analyze/getBundleEntry.js +3 -2
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +221 -0
- package/dist/js/node/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +16 -35
- package/dist/js/node/analyze/getClientRoutes/index.js +21 -0
- package/dist/js/node/analyze/getClientRoutes/utils.js +42 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +30 -11
- package/dist/js/node/analyze/index.js +2 -1
- package/dist/js/node/analyze/nestedRoutes.js +144 -0
- package/dist/js/node/analyze/templates.js +167 -10
- package/dist/js/node/analyze/utils.js +6 -2
- package/dist/js/node/builder/builderPlugins/compatModern.js +245 -0
- package/dist/js/node/builder/createHtmlConfig.js +76 -0
- package/dist/js/node/builder/createOutputConfig.js +75 -0
- package/dist/js/node/builder/createSourceConfig.js +99 -0
- package/dist/js/node/builder/createToolsConfig.js +103 -0
- package/dist/js/node/builder/index.js +129 -0
- package/dist/js/node/builder/share.js +63 -0
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +46 -0
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +53 -0
- package/dist/js/node/commands/build.js +44 -98
- package/dist/js/node/commands/dev.js +13 -23
- package/dist/js/node/commands/inspect.js +18 -74
- package/dist/js/node/commands/start.js +3 -1
- package/dist/js/node/index.js +19 -2
- package/dist/js/node/locale/en.js +0 -1
- package/dist/js/node/locale/zh.js +0 -1
- package/dist/js/node/utils/commands.js +14 -0
- package/dist/js/node/utils/createCompiler.js +43 -49
- package/dist/js/node/utils/createServer.js +21 -2
- package/dist/js/node/utils/printInstructions.js +1 -1
- package/dist/js/treeshaking/analyze/constants.js +16 -0
- package/dist/js/treeshaking/analyze/generateCode.js +412 -0
- package/dist/js/treeshaking/analyze/getBundleEntry.js +77 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +210 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +211 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +2 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +27 -0
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +109 -0
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +153 -0
- package/dist/js/treeshaking/analyze/getServerRoutes.js +170 -0
- package/dist/js/treeshaking/analyze/index.js +214 -0
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +18 -0
- package/dist/js/treeshaking/analyze/nestedRoutes.js +207 -0
- package/dist/js/treeshaking/analyze/templates.js +189 -0
- package/dist/js/treeshaking/analyze/utils.js +95 -0
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +231 -0
- package/dist/js/treeshaking/builder/createHtmlConfig.js +59 -0
- package/dist/js/treeshaking/builder/createOutputConfig.js +67 -0
- package/dist/js/treeshaking/builder/createSourceConfig.js +100 -0
- package/dist/js/treeshaking/builder/createToolsConfig.js +90 -0
- package/dist/js/treeshaking/builder/index.js +172 -0
- package/dist/js/treeshaking/builder/share.js +50 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +58 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +53 -0
- package/dist/js/treeshaking/commands/build.js +168 -0
- package/dist/js/treeshaking/commands/deploy.js +29 -0
- package/dist/js/treeshaking/commands/dev.js +146 -0
- package/dist/js/treeshaking/commands/index.js +3 -0
- package/dist/js/treeshaking/commands/inspect.js +52 -0
- package/dist/js/treeshaking/commands/start.js +78 -0
- package/dist/js/treeshaking/exports/server.js +1 -0
- package/dist/js/treeshaking/hooks.js +21 -0
- package/dist/js/treeshaking/index.js +304 -0
- package/dist/js/treeshaking/locale/en.js +34 -0
- package/dist/js/treeshaking/locale/index.js +9 -0
- package/dist/js/treeshaking/locale/zh.js +34 -0
- package/dist/js/treeshaking/utils/commands.js +5 -0
- package/dist/js/treeshaking/utils/config.js +140 -0
- package/dist/js/treeshaking/utils/createCompiler.js +117 -0
- package/dist/js/treeshaking/utils/createServer.js +83 -0
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +68 -0
- package/dist/js/treeshaking/utils/language.js +5 -0
- package/dist/js/treeshaking/utils/printInstructions.js +35 -0
- package/dist/js/treeshaking/utils/routes.js +33 -0
- package/dist/js/treeshaking/utils/types.js +0 -0
- package/dist/types/analyze/constants.d.ts +1 -0
- package/dist/types/analyze/generateCode.d.ts +1 -1
- package/dist/types/analyze/{getClientRoutes.d.ts → getClientRoutes/getRoutes.d.ts} +2 -7
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +15 -0
- package/dist/types/analyze/getClientRoutes/index.d.ts +2 -0
- package/dist/types/analyze/getClientRoutes/utils.d.ts +5 -0
- package/dist/types/analyze/index.d.ts +2 -2
- package/dist/types/analyze/nestedRoutes.d.ts +5 -0
- package/dist/types/analyze/templates.d.ts +17 -3
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +14 -0
- package/dist/types/builder/createHtmlConfig.d.ts +6 -0
- package/dist/types/builder/createOutputConfig.d.ts +3 -0
- package/dist/types/builder/createSourceConfig.d.ts +5 -0
- package/dist/types/builder/createToolsConfig.d.ts +13 -0
- package/dist/types/builder/index.d.ts +19 -0
- package/dist/types/builder/share.d.ts +26 -0
- package/dist/types/builder/webpackPlugins/htmlAsyncChunkPlugin.d.ts +8 -0
- package/dist/types/builder/webpackPlugins/htmlBottomTemplate.d.ts +10 -0
- package/dist/types/commands/build.d.ts +2 -1
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/commands/inspect.d.ts +5 -6
- package/dist/types/commands/start.d.ts +2 -1
- package/dist/types/hooks.d.ts +15 -10
- package/dist/types/index.d.ts +4 -2
- package/dist/types/locale/en.d.ts +0 -1
- package/dist/types/locale/index.d.ts +0 -2
- package/dist/types/locale/zh.d.ts +0 -1
- package/dist/types/utils/commands.d.ts +1 -0
- package/dist/types/utils/createCompiler.d.ts +9 -10
- package/dist/types/utils/createServer.d.ts +8 -1
- package/dist/types/utils/printInstructions.d.ts +3 -2
- package/dist/types/utils/types.d.ts +2 -3
- package/package.json +25 -43
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { isUseSSRBundle } from '@modern-js/utils';
|
|
5
|
+
import createBuilder from "../builder";
|
|
6
|
+
export var inspect = /*#__PURE__*/function () {
|
|
7
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, options) {
|
|
8
|
+
var resolvedConfig, appContext, targets, builder;
|
|
9
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
10
|
+
while (1) {
|
|
11
|
+
switch (_context.prev = _context.next) {
|
|
12
|
+
case 0:
|
|
13
|
+
resolvedConfig = api.useResolvedConfigContext();
|
|
14
|
+
appContext = api.useAppContext();
|
|
15
|
+
targets = ['web'];
|
|
16
|
+
|
|
17
|
+
if (resolvedConfig.output.enableModernMode) {
|
|
18
|
+
targets.push('modern-web');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (isUseSSRBundle(resolvedConfig)) {
|
|
22
|
+
targets.push('node');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_context.next = 7;
|
|
26
|
+
return createBuilder({
|
|
27
|
+
target: targets,
|
|
28
|
+
appContext: appContext,
|
|
29
|
+
normalizedConfig: resolvedConfig
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
case 7:
|
|
33
|
+
builder = _context.sent;
|
|
34
|
+
return _context.abrupt("return", builder.inspectConfig({
|
|
35
|
+
env: options.env,
|
|
36
|
+
verbose: options.verbose,
|
|
37
|
+
outputPath: join(builder.context.distPath, options.output),
|
|
38
|
+
writeToDisk: true
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
case 9:
|
|
42
|
+
case "end":
|
|
43
|
+
return _context.stop();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, _callee);
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
return function inspect(_x, _x2) {
|
|
50
|
+
return _ref.apply(this, arguments);
|
|
51
|
+
};
|
|
52
|
+
}();
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import { logger, chalk, isApiOnly } from '@modern-js/utils';
|
|
4
|
+
import server from '@modern-js/prod-server';
|
|
5
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
6
|
+
import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
7
|
+
export var start = /*#__PURE__*/function () {
|
|
8
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(api) {
|
|
9
|
+
var _userConfig$source;
|
|
10
|
+
|
|
11
|
+
var appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, app;
|
|
12
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
13
|
+
while (1) {
|
|
14
|
+
switch (_context2.prev = _context2.next) {
|
|
15
|
+
case 0:
|
|
16
|
+
appContext = api.useAppContext();
|
|
17
|
+
userConfig = api.useResolvedConfigContext();
|
|
18
|
+
hookRunners = api.useHookRunners();
|
|
19
|
+
appDirectory = appContext.appDirectory, port = appContext.port, serverConfigFile = appContext.serverConfigFile;
|
|
20
|
+
logger.log(chalk.cyan("Starting the modern server..."));
|
|
21
|
+
_context2.next = 7;
|
|
22
|
+
return isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
|
|
23
|
+
|
|
24
|
+
case 7:
|
|
25
|
+
apiOnly = _context2.sent;
|
|
26
|
+
_context2.next = 10;
|
|
27
|
+
return server({
|
|
28
|
+
pwd: appDirectory,
|
|
29
|
+
config: userConfig,
|
|
30
|
+
serverConfigFile: serverConfigFile,
|
|
31
|
+
internalPlugins: injectDataLoaderPlugin(appContext.serverInternalPlugins),
|
|
32
|
+
apiOnly: apiOnly
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
case 10:
|
|
36
|
+
app = _context2.sent;
|
|
37
|
+
app.listen(port, /*#__PURE__*/function () {
|
|
38
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err) {
|
|
39
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
40
|
+
while (1) {
|
|
41
|
+
switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
if (!err) {
|
|
44
|
+
_context.next = 2;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
throw err;
|
|
49
|
+
|
|
50
|
+
case 2:
|
|
51
|
+
_context.next = 4;
|
|
52
|
+
return printInstructions(hookRunners, appContext, userConfig);
|
|
53
|
+
|
|
54
|
+
case 4:
|
|
55
|
+
case "end":
|
|
56
|
+
return _context.stop();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}, _callee);
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
return function (_x2) {
|
|
63
|
+
return _ref2.apply(this, arguments);
|
|
64
|
+
};
|
|
65
|
+
}());
|
|
66
|
+
|
|
67
|
+
case 12:
|
|
68
|
+
case "end":
|
|
69
|
+
return _context2.stop();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, _callee2);
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
return function start(_x) {
|
|
76
|
+
return _ref.apply(this, arguments);
|
|
77
|
+
};
|
|
78
|
+
}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineServerConfig as defineConfig } from "../utils/config";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createAsyncWaterfall, createAsyncWorkflow } from '@modern-js/plugin';
|
|
2
|
+
export var beforeDev = createAsyncWorkflow();
|
|
3
|
+
export var afterDev = createAsyncWorkflow();
|
|
4
|
+
export var beforeCreateCompiler = createAsyncWorkflow();
|
|
5
|
+
export var afterCreateCompiler = createAsyncWorkflow();
|
|
6
|
+
export var beforePrintInstructions = createAsyncWaterfall();
|
|
7
|
+
export var beforeBuild = createAsyncWorkflow();
|
|
8
|
+
export var afterBuild = createAsyncWorkflow();
|
|
9
|
+
export var beforeDeploy = createAsyncWorkflow();
|
|
10
|
+
export var afterDeploy = createAsyncWorkflow();
|
|
11
|
+
export var hooks = {
|
|
12
|
+
beforeDev: beforeDev,
|
|
13
|
+
afterDev: afterDev,
|
|
14
|
+
beforeCreateCompiler: beforeCreateCompiler,
|
|
15
|
+
afterCreateCompiler: afterCreateCompiler,
|
|
16
|
+
beforePrintInstructions: beforePrintInstructions,
|
|
17
|
+
beforeBuild: beforeBuild,
|
|
18
|
+
afterBuild: afterBuild,
|
|
19
|
+
beforeDeploy: beforeDeploy,
|
|
20
|
+
afterDeploy: afterDeploy
|
|
21
|
+
};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { defineConfig, cli } from '@modern-js/core';
|
|
6
|
+
import LintPlugin from '@modern-js/plugin-jarvis';
|
|
7
|
+
import { cleanRequireCache, emptyDir, Import } from '@modern-js/utils';
|
|
8
|
+
import AnalyzePlugin from "./analyze";
|
|
9
|
+
import { hooks } from "./hooks";
|
|
10
|
+
import { i18n, localeKeys } from "./locale";
|
|
11
|
+
import { getLocaleLanguage } from "./utils/language";
|
|
12
|
+
import { getCommand } from "./utils/commands";
|
|
13
|
+
export { defineConfig, hooks };
|
|
14
|
+
var upgradeModel = Import.lazy('@modern-js/upgrade', require);
|
|
15
|
+
export default (function () {
|
|
16
|
+
return {
|
|
17
|
+
name: '@modern-js/app-tools',
|
|
18
|
+
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-router-legacy', '@modern-js/plugin-polyfill'],
|
|
19
|
+
registerHook: hooks,
|
|
20
|
+
usePlugins: [AnalyzePlugin(), LintPlugin()],
|
|
21
|
+
setup: function setup(api) {
|
|
22
|
+
var locale = getLocaleLanguage();
|
|
23
|
+
i18n.changeLanguage({
|
|
24
|
+
locale: locale
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
commands: function commands(_ref) {
|
|
28
|
+
var program = _ref.program;
|
|
29
|
+
program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).action( /*#__PURE__*/function () {
|
|
30
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
31
|
+
var _yield$import, dev;
|
|
32
|
+
|
|
33
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
34
|
+
while (1) {
|
|
35
|
+
switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
_context.next = 2;
|
|
38
|
+
return import("./commands/dev");
|
|
39
|
+
|
|
40
|
+
case 2:
|
|
41
|
+
_yield$import = _context.sent;
|
|
42
|
+
dev = _yield$import.dev;
|
|
43
|
+
_context.next = 6;
|
|
44
|
+
return dev(api, options);
|
|
45
|
+
|
|
46
|
+
case 6:
|
|
47
|
+
case "end":
|
|
48
|
+
return _context.stop();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, _callee);
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
return function (_x) {
|
|
55
|
+
return _ref2.apply(this, arguments);
|
|
56
|
+
};
|
|
57
|
+
}());
|
|
58
|
+
program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).action( /*#__PURE__*/function () {
|
|
59
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
60
|
+
var _yield$import2, build;
|
|
61
|
+
|
|
62
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
63
|
+
while (1) {
|
|
64
|
+
switch (_context2.prev = _context2.next) {
|
|
65
|
+
case 0:
|
|
66
|
+
_context2.next = 2;
|
|
67
|
+
return import("./commands/build");
|
|
68
|
+
|
|
69
|
+
case 2:
|
|
70
|
+
_yield$import2 = _context2.sent;
|
|
71
|
+
build = _yield$import2.build;
|
|
72
|
+
_context2.next = 6;
|
|
73
|
+
return build(api, options);
|
|
74
|
+
|
|
75
|
+
case 6:
|
|
76
|
+
// force exit after build.
|
|
77
|
+
// eslint-disable-next-line no-process-exit
|
|
78
|
+
process.exit(0);
|
|
79
|
+
|
|
80
|
+
case 7:
|
|
81
|
+
case "end":
|
|
82
|
+
return _context2.stop();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}, _callee2);
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
return function (_x2) {
|
|
89
|
+
return _ref3.apply(this, arguments);
|
|
90
|
+
};
|
|
91
|
+
}());
|
|
92
|
+
program.command('start').usage('[options]').description(i18n.t(localeKeys.command.start.describe)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).action( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
93
|
+
var _yield$import3, start;
|
|
94
|
+
|
|
95
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
96
|
+
while (1) {
|
|
97
|
+
switch (_context3.prev = _context3.next) {
|
|
98
|
+
case 0:
|
|
99
|
+
_context3.next = 2;
|
|
100
|
+
return import("./commands/start");
|
|
101
|
+
|
|
102
|
+
case 2:
|
|
103
|
+
_yield$import3 = _context3.sent;
|
|
104
|
+
start = _yield$import3.start;
|
|
105
|
+
_context3.next = 6;
|
|
106
|
+
return start(api);
|
|
107
|
+
|
|
108
|
+
case 6:
|
|
109
|
+
case "end":
|
|
110
|
+
return _context3.stop();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}, _callee3);
|
|
114
|
+
})));
|
|
115
|
+
program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).description(i18n.t(localeKeys.command.deploy.describe)).action( /*#__PURE__*/function () {
|
|
116
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(options) {
|
|
117
|
+
var _yield$import4, build, _yield$import5, deploy;
|
|
118
|
+
|
|
119
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
120
|
+
while (1) {
|
|
121
|
+
switch (_context4.prev = _context4.next) {
|
|
122
|
+
case 0:
|
|
123
|
+
_context4.next = 2;
|
|
124
|
+
return import("./commands/build");
|
|
125
|
+
|
|
126
|
+
case 2:
|
|
127
|
+
_yield$import4 = _context4.sent;
|
|
128
|
+
build = _yield$import4.build;
|
|
129
|
+
_context4.next = 6;
|
|
130
|
+
return build(api);
|
|
131
|
+
|
|
132
|
+
case 6:
|
|
133
|
+
_context4.next = 8;
|
|
134
|
+
return import("./commands/deploy");
|
|
135
|
+
|
|
136
|
+
case 8:
|
|
137
|
+
_yield$import5 = _context4.sent;
|
|
138
|
+
deploy = _yield$import5.deploy;
|
|
139
|
+
_context4.next = 12;
|
|
140
|
+
return deploy(api, options);
|
|
141
|
+
|
|
142
|
+
case 12:
|
|
143
|
+
// eslint-disable-next-line no-process-exit
|
|
144
|
+
process.exit(0);
|
|
145
|
+
|
|
146
|
+
case 13:
|
|
147
|
+
case "end":
|
|
148
|
+
return _context4.stop();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}, _callee4);
|
|
152
|
+
}));
|
|
153
|
+
|
|
154
|
+
return function (_x3) {
|
|
155
|
+
return _ref5.apply(this, arguments);
|
|
156
|
+
};
|
|
157
|
+
}());
|
|
158
|
+
program.command('new').usage('[options]').description(i18n.t(localeKeys.command["new"].describe)).option('-d, --debug', i18n.t(localeKeys.command["new"].debug), false).option('-c, --config <config>', i18n.t(localeKeys.command["new"].config)).option('--dist-tag <tag>', i18n.t(localeKeys.command["new"].distTag)).option('--registry', i18n.t(localeKeys.command["new"].registry)).action( /*#__PURE__*/function () {
|
|
159
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(options) {
|
|
160
|
+
var _yield$import6, MWANewAction;
|
|
161
|
+
|
|
162
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
163
|
+
while (1) {
|
|
164
|
+
switch (_context5.prev = _context5.next) {
|
|
165
|
+
case 0:
|
|
166
|
+
_context5.next = 2;
|
|
167
|
+
return import('@modern-js/new-action');
|
|
168
|
+
|
|
169
|
+
case 2:
|
|
170
|
+
_yield$import6 = _context5.sent;
|
|
171
|
+
MWANewAction = _yield$import6.MWANewAction;
|
|
172
|
+
_context5.next = 6;
|
|
173
|
+
return MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
|
|
174
|
+
locale: locale
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
case 6:
|
|
178
|
+
case "end":
|
|
179
|
+
return _context5.stop();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, _callee5);
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
return function (_x4) {
|
|
186
|
+
return _ref6.apply(this, arguments);
|
|
187
|
+
};
|
|
188
|
+
}());
|
|
189
|
+
program.command('inspect').description('inspect internal webpack config').option("--env <env>", i18n.t(localeKeys.command.inspect.env), 'development').option('--output <output>', i18n.t(localeKeys.command.inspect.output), '/').option('--verbose', i18n.t(localeKeys.command.inspect.verbose)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).action( /*#__PURE__*/function () {
|
|
190
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(options) {
|
|
191
|
+
var _yield$import7, inspect;
|
|
192
|
+
|
|
193
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
194
|
+
while (1) {
|
|
195
|
+
switch (_context6.prev = _context6.next) {
|
|
196
|
+
case 0:
|
|
197
|
+
_context6.next = 2;
|
|
198
|
+
return import("./commands/inspect");
|
|
199
|
+
|
|
200
|
+
case 2:
|
|
201
|
+
_yield$import7 = _context6.sent;
|
|
202
|
+
inspect = _yield$import7.inspect;
|
|
203
|
+
inspect(api, options);
|
|
204
|
+
|
|
205
|
+
case 5:
|
|
206
|
+
case "end":
|
|
207
|
+
return _context6.stop();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}, _callee6);
|
|
211
|
+
}));
|
|
212
|
+
|
|
213
|
+
return function (_x5) {
|
|
214
|
+
return _ref7.apply(this, arguments);
|
|
215
|
+
};
|
|
216
|
+
}());
|
|
217
|
+
upgradeModel.defineCommand(program.command('upgrade'));
|
|
218
|
+
},
|
|
219
|
+
prepare: function prepare() {
|
|
220
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
221
|
+
var command, appContext;
|
|
222
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
223
|
+
while (1) {
|
|
224
|
+
switch (_context7.prev = _context7.next) {
|
|
225
|
+
case 0:
|
|
226
|
+
command = getCommand();
|
|
227
|
+
|
|
228
|
+
if (!(command === 'dev' || command === 'build')) {
|
|
229
|
+
_context7.next = 5;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
appContext = api.useAppContext();
|
|
234
|
+
_context7.next = 5;
|
|
235
|
+
return emptyDir(appContext.distDirectory);
|
|
236
|
+
|
|
237
|
+
case 5:
|
|
238
|
+
case "end":
|
|
239
|
+
return _context7.stop();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}, _callee7);
|
|
243
|
+
}))();
|
|
244
|
+
},
|
|
245
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
246
|
+
fileChange: function fileChange(e) {
|
|
247
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
248
|
+
var filename, eventType, appContext, appDirectory, srcDirectory, absolutePath, _yield$import8, closeServer;
|
|
249
|
+
|
|
250
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
251
|
+
while (1) {
|
|
252
|
+
switch (_context8.prev = _context8.next) {
|
|
253
|
+
case 0:
|
|
254
|
+
filename = e.filename, eventType = e.eventType;
|
|
255
|
+
appContext = api.useAppContext();
|
|
256
|
+
appDirectory = appContext.appDirectory, srcDirectory = appContext.srcDirectory;
|
|
257
|
+
absolutePath = path.resolve(appDirectory, filename);
|
|
258
|
+
|
|
259
|
+
if (!(!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink'))) {
|
|
260
|
+
_context8.next = 13;
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
_context8.next = 7;
|
|
265
|
+
return import("./utils/createServer");
|
|
266
|
+
|
|
267
|
+
case 7:
|
|
268
|
+
_yield$import8 = _context8.sent;
|
|
269
|
+
closeServer = _yield$import8.closeServer;
|
|
270
|
+
_context8.next = 11;
|
|
271
|
+
return closeServer();
|
|
272
|
+
|
|
273
|
+
case 11:
|
|
274
|
+
_context8.next = 13;
|
|
275
|
+
return cli.restart();
|
|
276
|
+
|
|
277
|
+
case 13:
|
|
278
|
+
case "end":
|
|
279
|
+
return _context8.stop();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}, _callee8);
|
|
283
|
+
}))();
|
|
284
|
+
},
|
|
285
|
+
beforeRestart: function beforeRestart() {
|
|
286
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
287
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
288
|
+
while (1) {
|
|
289
|
+
switch (_context9.prev = _context9.next) {
|
|
290
|
+
case 0:
|
|
291
|
+
cleanRequireCache([require.resolve("./analyze")]);
|
|
292
|
+
|
|
293
|
+
case 1:
|
|
294
|
+
case "end":
|
|
295
|
+
return _context9.stop();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}, _callee9);
|
|
299
|
+
}))();
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export var EN_LOCALE = {
|
|
2
|
+
command: {
|
|
3
|
+
shared: {
|
|
4
|
+
analyze: 'analyze bundle size',
|
|
5
|
+
config: 'specify config file'
|
|
6
|
+
},
|
|
7
|
+
dev: {
|
|
8
|
+
describe: 'start dev server',
|
|
9
|
+
entry: 'compiler by entry',
|
|
10
|
+
apiOnly: 'start api server only'
|
|
11
|
+
},
|
|
12
|
+
build: {
|
|
13
|
+
describe: 'build application'
|
|
14
|
+
},
|
|
15
|
+
start: {
|
|
16
|
+
describe: 'start server'
|
|
17
|
+
},
|
|
18
|
+
deploy: {
|
|
19
|
+
describe: 'deploy application'
|
|
20
|
+
},
|
|
21
|
+
"new": {
|
|
22
|
+
describe: 'generator runner for MWA project',
|
|
23
|
+
debug: 'using debug mode to log something',
|
|
24
|
+
config: 'set default generator config(json string)',
|
|
25
|
+
distTag: "use specified tag version for it's generator",
|
|
26
|
+
registry: 'set npm registry url to run npm command'
|
|
27
|
+
},
|
|
28
|
+
inspect: {
|
|
29
|
+
env: 'specify env mode',
|
|
30
|
+
output: 'specify inspect content output path',
|
|
31
|
+
verbose: 'show full function definitions in output'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export var ZH_LOCALE = {
|
|
2
|
+
command: {
|
|
3
|
+
shared: {
|
|
4
|
+
analyze: '分析构建产物体积,查看各个模块打包后的大小',
|
|
5
|
+
config: '指定配置文件路径,可以为相对路径或绝对路径'
|
|
6
|
+
},
|
|
7
|
+
dev: {
|
|
8
|
+
describe: '本地开发命令',
|
|
9
|
+
entry: '指定入口,编译特定的页面',
|
|
10
|
+
apiOnly: '仅启动 API 接口服务'
|
|
11
|
+
},
|
|
12
|
+
build: {
|
|
13
|
+
describe: '构建应用命令'
|
|
14
|
+
},
|
|
15
|
+
start: {
|
|
16
|
+
describe: '应用启动命令'
|
|
17
|
+
},
|
|
18
|
+
deploy: {
|
|
19
|
+
describe: '部署应用命令'
|
|
20
|
+
},
|
|
21
|
+
"new": {
|
|
22
|
+
describe: 'MWA 项目中执行生成器',
|
|
23
|
+
debug: '开启 Debug 模式,打印调试日志信息',
|
|
24
|
+
config: '生成器运行默认配置(JSON 字符串)',
|
|
25
|
+
distTag: '生成器使用特殊的 npm Tag 版本',
|
|
26
|
+
registry: '生成器运行过程中定制 npm Registry'
|
|
27
|
+
},
|
|
28
|
+
inspect: {
|
|
29
|
+
env: '查看指定环境下的配置',
|
|
30
|
+
output: '指定在 dist 目录下输出的路径',
|
|
31
|
+
verbose: '在结果中展示函数的完整内容'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { bundle } from '@modern-js/node-bundle-require';
|
|
7
|
+
import { CONFIG_FILE_EXTENSIONS, fs, getServerConfig, OUTPUT_CONFIG_FILE } from '@modern-js/utils';
|
|
8
|
+
export var defineServerConfig = function defineServerConfig(config) {
|
|
9
|
+
return config;
|
|
10
|
+
};
|
|
11
|
+
export var buildServerConfig = /*#__PURE__*/function () {
|
|
12
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
13
|
+
var appDirectory, distDirectory, configFile, options, configFilePath, getOutputFile, configHelperFilePath, helperCode;
|
|
14
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
15
|
+
while (1) {
|
|
16
|
+
switch (_context2.prev = _context2.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
appDirectory = _ref.appDirectory, distDirectory = _ref.distDirectory, configFile = _ref.configFile, options = _ref.options;
|
|
19
|
+
_context2.next = 3;
|
|
20
|
+
return getServerConfig(appDirectory, configFile);
|
|
21
|
+
|
|
22
|
+
case 3:
|
|
23
|
+
configFilePath = _context2.sent;
|
|
24
|
+
|
|
25
|
+
getOutputFile = /*#__PURE__*/function () {
|
|
26
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(filepath) {
|
|
27
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
28
|
+
while (1) {
|
|
29
|
+
switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
return _context.abrupt("return", path.resolve(distDirectory, "".concat(filepath.replace(new RegExp(CONFIG_FILE_EXTENSIONS.join('|')), ''), ".js")));
|
|
32
|
+
|
|
33
|
+
case 1:
|
|
34
|
+
case "end":
|
|
35
|
+
return _context.stop();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, _callee);
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
return function getOutputFile(_x2) {
|
|
42
|
+
return _ref3.apply(this, arguments);
|
|
43
|
+
};
|
|
44
|
+
}();
|
|
45
|
+
|
|
46
|
+
if (!configFilePath) {
|
|
47
|
+
_context2.next = 14;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
configHelperFilePath = path.normalize(path.join(distDirectory, './config-helper.js'));
|
|
52
|
+
helperCode = "\n export const defineConfig = (config) => config;\n ";
|
|
53
|
+
_context2.next = 10;
|
|
54
|
+
return fs.ensureDir(distDirectory);
|
|
55
|
+
|
|
56
|
+
case 10:
|
|
57
|
+
_context2.next = 12;
|
|
58
|
+
return fs.writeFile(configHelperFilePath, helperCode);
|
|
59
|
+
|
|
60
|
+
case 12:
|
|
61
|
+
_context2.next = 14;
|
|
62
|
+
return bundle(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
|
|
63
|
+
getOutputFile: getOutputFile,
|
|
64
|
+
esbuildPlugins: [{
|
|
65
|
+
name: 'native-build-config',
|
|
66
|
+
setup: function setup(ctx) {
|
|
67
|
+
ctx.onResolve({
|
|
68
|
+
filter: /app-tools\/server/
|
|
69
|
+
}, function () {
|
|
70
|
+
return {
|
|
71
|
+
path: configHelperFilePath
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}]
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
case 14:
|
|
79
|
+
case "end":
|
|
80
|
+
return _context2.stop();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}, _callee2);
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
return function buildServerConfig(_x) {
|
|
87
|
+
return _ref2.apply(this, arguments);
|
|
88
|
+
};
|
|
89
|
+
}();
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* 处理循环引用的 replacer
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
export var safeReplacer = function safeReplacer() {
|
|
96
|
+
var cache = [];
|
|
97
|
+
var keyCache = [];
|
|
98
|
+
return function (key, value) {
|
|
99
|
+
if (_typeof(value) === 'object' && value !== null) {
|
|
100
|
+
var index = cache.indexOf(value);
|
|
101
|
+
|
|
102
|
+
if (index !== -1) {
|
|
103
|
+
return "[Circular ".concat(keyCache[index], "]");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
cache.push(value);
|
|
107
|
+
keyCache.push(key || 'root');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return value;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
export var emitResolvedConfig = /*#__PURE__*/function () {
|
|
114
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(appDirectory, resolvedConfig) {
|
|
115
|
+
var _resolvedConfig$outpu;
|
|
116
|
+
|
|
117
|
+
var outputPath;
|
|
118
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
119
|
+
while (1) {
|
|
120
|
+
switch (_context3.prev = _context3.next) {
|
|
121
|
+
case 0:
|
|
122
|
+
outputPath = path.join(appDirectory, (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$outpu = resolvedConfig.output) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.path) || './dist', OUTPUT_CONFIG_FILE);
|
|
123
|
+
_context3.next = 3;
|
|
124
|
+
return fs.writeJSON(outputPath, resolvedConfig, {
|
|
125
|
+
spaces: 2,
|
|
126
|
+
replacer: safeReplacer()
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
case 3:
|
|
130
|
+
case "end":
|
|
131
|
+
return _context3.stop();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, _callee3);
|
|
135
|
+
}));
|
|
136
|
+
|
|
137
|
+
return function emitResolvedConfig(_x3, _x4) {
|
|
138
|
+
return _ref4.apply(this, arguments);
|
|
139
|
+
};
|
|
140
|
+
}();
|