@modern-js/app-tools 2.52.0 → 2.53.1-alpha.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/dist/cjs/plugins/deploy/dependencies/index.js +1 -11
- package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +4 -14
- package/dist/esm/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/esm/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +2 -12
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/js/modern/analyze/constants.js +15 -0
- package/dist/js/modern/analyze/generateCode.js +179 -0
- package/dist/js/modern/analyze/getBundleEntry.js +75 -0
- package/dist/js/modern/analyze/getClientRoutes.js +219 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +74 -0
- package/dist/js/modern/analyze/getHtmlTemplate.js +82 -0
- package/dist/js/modern/analyze/getServerRoutes.js +192 -0
- package/dist/js/modern/analyze/index.js +148 -0
- package/dist/js/modern/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/modern/analyze/makeLegalIdentifier.js +16 -0
- package/dist/js/modern/analyze/templates.js +88 -0
- package/dist/js/modern/analyze/utils.js +92 -0
- package/dist/js/modern/commands/build.js +154 -0
- package/dist/js/modern/commands/deploy.js +5 -0
- package/dist/js/modern/commands/dev.js +95 -0
- package/dist/js/modern/commands/index.js +3 -0
- package/dist/js/modern/commands/inspect.js +69 -0
- package/dist/js/modern/commands/start.js +31 -0
- package/dist/js/modern/exports/server.js +1 -0
- package/dist/js/modern/hooks.js +21 -0
- package/dist/js/modern/index.js +109 -0
- package/dist/js/modern/locale/en.js +35 -0
- package/dist/js/modern/locale/index.js +9 -0
- package/dist/js/modern/locale/zh.js +35 -0
- package/dist/js/modern/utils/config.js +78 -0
- package/dist/js/modern/utils/createCompiler.js +61 -0
- package/dist/js/modern/utils/createServer.js +18 -0
- package/dist/js/modern/utils/getSpecifiedEntries.js +36 -0
- package/dist/js/modern/utils/language.js +5 -0
- package/dist/js/modern/utils/printInstructions.js +11 -0
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +36 -0
- package/dist/js/node/analyze/generateCode.js +208 -0
- package/dist/js/node/analyze/getBundleEntry.js +89 -0
- package/dist/js/node/analyze/getClientRoutes.js +241 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +90 -0
- package/dist/js/node/analyze/getHtmlTemplate.js +106 -0
- package/dist/js/node/analyze/getServerRoutes.js +208 -0
- package/dist/js/node/analyze/index.js +178 -0
- package/dist/js/node/analyze/isDefaultExportFunction.js +50 -0
- package/dist/js/node/analyze/makeLegalIdentifier.js +24 -0
- package/dist/js/node/analyze/templates.js +106 -0
- package/dist/js/node/analyze/utils.js +113 -0
- package/dist/js/node/commands/build.js +174 -0
- package/dist/js/node/commands/deploy.js +14 -0
- package/dist/js/node/commands/dev.js +120 -0
- package/dist/js/node/commands/index.js +44 -0
- package/dist/js/node/commands/inspect.js +98 -0
- package/dist/js/node/commands/start.js +47 -0
- package/dist/js/node/exports/server.js +13 -0
- package/dist/js/node/hooks.js +39 -0
- package/dist/js/node/index.js +141 -0
- package/dist/js/node/locale/en.js +42 -0
- package/dist/js/node/locale/index.js +20 -0
- package/dist/js/node/locale/zh.js +42 -0
- package/dist/js/node/utils/config.js +103 -0
- package/dist/js/node/utils/createCompiler.js +81 -0
- package/dist/js/node/utils/createServer.js +35 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +46 -0
- package/dist/js/node/utils/language.js +13 -0
- package/dist/js/node/utils/printInstructions.js +22 -0
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
- package/package.json +17 -17
@@ -0,0 +1,120 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.dev = void 0;
|
7
|
+
|
8
|
+
var _utils = require("@modern-js/utils");
|
9
|
+
|
10
|
+
var _core = require("@modern-js/core");
|
11
|
+
|
12
|
+
var _createCompiler = require("../utils/createCompiler");
|
13
|
+
|
14
|
+
var _createServer = require("../utils/createServer");
|
15
|
+
|
16
|
+
var _routes = require("../utils/routes");
|
17
|
+
|
18
|
+
var _printInstructions = require("../utils/printInstructions");
|
19
|
+
|
20
|
+
var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
|
21
|
+
|
22
|
+
var _config = require("../utils/config");
|
23
|
+
|
24
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
25
|
+
|
26
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
27
|
+
|
28
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
29
|
+
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
31
|
+
|
32
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
33
|
+
|
34
|
+
const dev = async (api, options) => {
|
35
|
+
let userConfig = api.useResolvedConfigContext();
|
36
|
+
const appContext = api.useAppContext();
|
37
|
+
const hookRunners = api.useHookRunners();
|
38
|
+
userConfig = _objectSpread(_objectSpread({}, userConfig), {}, {
|
39
|
+
cliOptions: options
|
40
|
+
});
|
41
|
+
|
42
|
+
_core.ResolvedConfigContext.set(userConfig);
|
43
|
+
|
44
|
+
const {
|
45
|
+
appDirectory,
|
46
|
+
distDirectory,
|
47
|
+
port,
|
48
|
+
apiOnly,
|
49
|
+
entrypoints,
|
50
|
+
serverConfigFile
|
51
|
+
} = appContext;
|
52
|
+
const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
|
53
|
+
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
54
|
+
checkedEntries
|
55
|
+
}));
|
56
|
+
appContext.checkedEntries = checkedEntries;
|
57
|
+
|
58
|
+
_utils.fs.emptyDirSync(distDirectory);
|
59
|
+
|
60
|
+
await (0, _config.buildServerConfig)({
|
61
|
+
appDirectory,
|
62
|
+
distDirectory,
|
63
|
+
configFile: serverConfigFile,
|
64
|
+
options: {
|
65
|
+
esbuildOptions: {
|
66
|
+
watch: true
|
67
|
+
}
|
68
|
+
}
|
69
|
+
});
|
70
|
+
await hookRunners.beforeDev();
|
71
|
+
let compiler = null;
|
72
|
+
|
73
|
+
if (!apiOnly) {
|
74
|
+
const {
|
75
|
+
getWebpackConfig,
|
76
|
+
WebpackConfigTarget
|
77
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/webpack')));
|
78
|
+
const webpackConfigs = [(0, _utils.isSSR)(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE, appContext, userConfig), getWebpackConfig(WebpackConfigTarget.CLIENT, appContext, userConfig)].filter(Boolean);
|
79
|
+
compiler = await (0, _createCompiler.createCompiler)({
|
80
|
+
api,
|
81
|
+
webpackConfigs,
|
82
|
+
userConfig,
|
83
|
+
appContext
|
84
|
+
});
|
85
|
+
}
|
86
|
+
|
87
|
+
await (0, _routes.generateRoutes)(appContext);
|
88
|
+
const app = await (0, _createServer.createServer)({
|
89
|
+
dev: _objectSpread(_objectSpread({}, {
|
90
|
+
client: {
|
91
|
+
port: port.toString()
|
92
|
+
},
|
93
|
+
devMiddleware: {
|
94
|
+
writeToDisk: file => !file.includes('.hot-update.')
|
95
|
+
},
|
96
|
+
hot: true,
|
97
|
+
liveReload: true,
|
98
|
+
port,
|
99
|
+
https: userConfig.dev.https
|
100
|
+
}), userConfig.tools.devServer),
|
101
|
+
compiler,
|
102
|
+
pwd: appDirectory,
|
103
|
+
config: userConfig,
|
104
|
+
serverConfigFile,
|
105
|
+
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
106
|
+
});
|
107
|
+
app.listen(port, async err => {
|
108
|
+
if (err) {
|
109
|
+
throw err;
|
110
|
+
}
|
111
|
+
|
112
|
+
if (apiOnly) {
|
113
|
+
return (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
114
|
+
}
|
115
|
+
|
116
|
+
return _utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
117
|
+
});
|
118
|
+
};
|
119
|
+
|
120
|
+
exports.dev = dev;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _dev = require("./dev");
|
8
|
+
|
9
|
+
Object.keys(_dev).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _dev[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _dev[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
19
|
+
|
20
|
+
var _build = require("./build");
|
21
|
+
|
22
|
+
Object.keys(_build).forEach(function (key) {
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
24
|
+
if (key in exports && exports[key] === _build[key]) return;
|
25
|
+
Object.defineProperty(exports, key, {
|
26
|
+
enumerable: true,
|
27
|
+
get: function () {
|
28
|
+
return _build[key];
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
32
|
+
|
33
|
+
var _start = require("./start");
|
34
|
+
|
35
|
+
Object.keys(_start).forEach(function (key) {
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
37
|
+
if (key in exports && exports[key] === _start[key]) return;
|
38
|
+
Object.defineProperty(exports, key, {
|
39
|
+
enumerable: true,
|
40
|
+
get: function () {
|
41
|
+
return _start[key];
|
42
|
+
}
|
43
|
+
});
|
44
|
+
});
|
@@ -0,0 +1,98 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.printInspectResult = exports.inspect = exports.getTagByWebpackTarget = exports.formatWebpackConfig = void 0;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var _webpack = require("@modern-js/webpack");
|
11
|
+
|
12
|
+
var _utils = require("@modern-js/utils");
|
13
|
+
|
14
|
+
var _webpackChain = _interopRequireDefault(require("@modern-js/utils/webpack-chain"));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
const formatWebpackConfig = (config, verbose) => {
|
19
|
+
const stringify = _webpackChain.default.toString;
|
20
|
+
return `module.exports = ${stringify(config, {
|
21
|
+
verbose
|
22
|
+
})};`;
|
23
|
+
};
|
24
|
+
|
25
|
+
exports.formatWebpackConfig = formatWebpackConfig;
|
26
|
+
|
27
|
+
const inspect = (api, options) => {
|
28
|
+
process.env.NODE_ENV = options.env;
|
29
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
30
|
+
const appContext = api.useAppContext();
|
31
|
+
const outputFiles = [];
|
32
|
+
outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.CLIENT, appContext, resolvedConfig, options));
|
33
|
+
|
34
|
+
if (resolvedConfig.output.enableModernMode) {
|
35
|
+
outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.MODERN, appContext, resolvedConfig, options));
|
36
|
+
}
|
37
|
+
|
38
|
+
if ((0, _utils.isUseSSRBundle)(resolvedConfig)) {
|
39
|
+
outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.NODE, appContext, resolvedConfig, options));
|
40
|
+
}
|
41
|
+
|
42
|
+
_utils.logger.success('Inspect succeed, you can open following files to view the full webpack config: \n');
|
43
|
+
|
44
|
+
outputFiles.forEach(file => {
|
45
|
+
_utils.logger.log(` - ${_utils.chalk.yellow(_path.default.relative(appContext.appDirectory, file))}`);
|
46
|
+
});
|
47
|
+
|
48
|
+
_utils.logger.log();
|
49
|
+
};
|
50
|
+
|
51
|
+
exports.inspect = inspect;
|
52
|
+
|
53
|
+
const getTagByWebpackTarget = webpackTarget => {
|
54
|
+
switch (webpackTarget) {
|
55
|
+
case _webpack.WebpackConfigTarget.CLIENT:
|
56
|
+
return 'client';
|
57
|
+
|
58
|
+
case _webpack.WebpackConfigTarget.MODERN:
|
59
|
+
return 'modern';
|
60
|
+
|
61
|
+
case _webpack.WebpackConfigTarget.NODE:
|
62
|
+
return 'ssr';
|
63
|
+
|
64
|
+
default:
|
65
|
+
throw Error(`Unsupported webpack target: ${webpackTarget}`);
|
66
|
+
}
|
67
|
+
};
|
68
|
+
|
69
|
+
exports.getTagByWebpackTarget = getTagByWebpackTarget;
|
70
|
+
|
71
|
+
const printInspectResult = (webpackTarget, appContext, resolvedConfig, options) => {
|
72
|
+
const webpackConfig = (0, _webpack.getWebpackConfig)(webpackTarget, appContext, resolvedConfig);
|
73
|
+
const {
|
74
|
+
output,
|
75
|
+
verbose,
|
76
|
+
console = true
|
77
|
+
} = options;
|
78
|
+
const outputPath = output ? _path.default.posix.join(appContext.distDirectory, output) : appContext.distDirectory;
|
79
|
+
const tag = getTagByWebpackTarget(webpackTarget);
|
80
|
+
const outputFile = `webpack.${tag}.inspect.js`;
|
81
|
+
|
82
|
+
const outputFilePath = _path.default.posix.join(outputPath, outputFile);
|
83
|
+
|
84
|
+
const rawWebpackConfig = formatWebpackConfig(webpackConfig, verbose);
|
85
|
+
|
86
|
+
_utils.fs.outputFileSync(outputFilePath, rawWebpackConfig);
|
87
|
+
|
88
|
+
if (console) {
|
89
|
+
_utils.logger.log(`
|
90
|
+
webpack config for ${tag} build:
|
91
|
+
${rawWebpackConfig}
|
92
|
+
`);
|
93
|
+
}
|
94
|
+
|
95
|
+
return outputFilePath;
|
96
|
+
};
|
97
|
+
|
98
|
+
exports.printInspectResult = printInspectResult;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.start = void 0;
|
7
|
+
|
8
|
+
var _utils = require("@modern-js/utils");
|
9
|
+
|
10
|
+
var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
|
11
|
+
|
12
|
+
var _printInstructions = require("../utils/printInstructions");
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
const start = async api => {
|
17
|
+
var _userConfig$source;
|
18
|
+
|
19
|
+
const appContext = api.useAppContext();
|
20
|
+
const userConfig = api.useResolvedConfigContext();
|
21
|
+
const hookRunners = api.useHookRunners();
|
22
|
+
const {
|
23
|
+
appDirectory,
|
24
|
+
port,
|
25
|
+
serverConfigFile
|
26
|
+
} = appContext;
|
27
|
+
|
28
|
+
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
29
|
+
|
30
|
+
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
|
31
|
+
const app = await (0, _prodServer.default)({
|
32
|
+
pwd: appDirectory,
|
33
|
+
config: userConfig,
|
34
|
+
plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
|
35
|
+
serverConfigFile,
|
36
|
+
apiOnly
|
37
|
+
});
|
38
|
+
app.listen(port, async err => {
|
39
|
+
if (err) {
|
40
|
+
throw err;
|
41
|
+
}
|
42
|
+
|
43
|
+
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
44
|
+
});
|
45
|
+
};
|
46
|
+
|
47
|
+
exports.start = start;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "defineConfig", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _config.defineServerConfig;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
|
13
|
+
var _config = require("../utils/config");
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.hooks = exports.beforePrintInstructions = exports.beforeDev = exports.beforeDeploy = exports.beforeCreateCompiler = exports.beforeBuild = exports.afterDev = exports.afterDeploy = exports.afterCreateCompiler = exports.afterBuild = void 0;
|
7
|
+
|
8
|
+
var _plugin = require("@modern-js/plugin");
|
9
|
+
|
10
|
+
const beforeDev = (0, _plugin.createAsyncWorkflow)();
|
11
|
+
exports.beforeDev = beforeDev;
|
12
|
+
const afterDev = (0, _plugin.createAsyncWorkflow)();
|
13
|
+
exports.afterDev = afterDev;
|
14
|
+
const beforeCreateCompiler = (0, _plugin.createAsyncWorkflow)();
|
15
|
+
exports.beforeCreateCompiler = beforeCreateCompiler;
|
16
|
+
const afterCreateCompiler = (0, _plugin.createAsyncWorkflow)();
|
17
|
+
exports.afterCreateCompiler = afterCreateCompiler;
|
18
|
+
const beforePrintInstructions = (0, _plugin.createAsyncWaterfall)();
|
19
|
+
exports.beforePrintInstructions = beforePrintInstructions;
|
20
|
+
const beforeBuild = (0, _plugin.createAsyncWorkflow)();
|
21
|
+
exports.beforeBuild = beforeBuild;
|
22
|
+
const afterBuild = (0, _plugin.createAsyncWorkflow)();
|
23
|
+
exports.afterBuild = afterBuild;
|
24
|
+
const beforeDeploy = (0, _plugin.createAsyncWorkflow)();
|
25
|
+
exports.beforeDeploy = beforeDeploy;
|
26
|
+
const afterDeploy = (0, _plugin.createAsyncWorkflow)();
|
27
|
+
exports.afterDeploy = afterDeploy;
|
28
|
+
const hooks = {
|
29
|
+
beforeDev,
|
30
|
+
afterDev,
|
31
|
+
beforeCreateCompiler,
|
32
|
+
afterCreateCompiler,
|
33
|
+
beforePrintInstructions,
|
34
|
+
beforeBuild,
|
35
|
+
afterBuild,
|
36
|
+
beforeDeploy,
|
37
|
+
afterDeploy
|
38
|
+
};
|
39
|
+
exports.hooks = hooks;
|
@@ -0,0 +1,141 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
Object.defineProperty(exports, "defineConfig", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function () {
|
10
|
+
return _core.defineConfig;
|
11
|
+
}
|
12
|
+
});
|
13
|
+
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
15
|
+
|
16
|
+
var _core = require("@modern-js/core");
|
17
|
+
|
18
|
+
var _pluginJarvis = _interopRequireDefault(require("@modern-js/plugin-jarvis"));
|
19
|
+
|
20
|
+
var _utils = require("@modern-js/utils");
|
21
|
+
|
22
|
+
var _analyze = _interopRequireDefault(require("./analyze"));
|
23
|
+
|
24
|
+
var _hooks = require("./hooks");
|
25
|
+
|
26
|
+
var _locale = require("./locale");
|
27
|
+
|
28
|
+
var _language = require("./utils/language");
|
29
|
+
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31
|
+
|
32
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
33
|
+
|
34
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
35
|
+
|
36
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
37
|
+
|
38
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
39
|
+
|
40
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
41
|
+
|
42
|
+
const upgradeModel = _utils.Import.lazy('@modern-js/upgrade', require);
|
43
|
+
|
44
|
+
var _default = () => ({
|
45
|
+
name: '@modern-js/app-tools',
|
46
|
+
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
|
47
|
+
registerHook: _hooks.hooks,
|
48
|
+
usePlugins: [(0, _analyze.default)(), (0, _pluginJarvis.default)()],
|
49
|
+
setup: api => {
|
50
|
+
const locale = (0, _language.getLocaleLanguage)();
|
51
|
+
|
52
|
+
_locale.i18n.changeLanguage({
|
53
|
+
locale
|
54
|
+
});
|
55
|
+
|
56
|
+
return {
|
57
|
+
commands({
|
58
|
+
program
|
59
|
+
}) {
|
60
|
+
program.command('dev').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).option('-e --entry [entry...]', _locale.i18n.t(_locale.localeKeys.command.dev.entry)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.shared.analyze)).option('--api-only', _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).action(async options => {
|
61
|
+
const {
|
62
|
+
dev
|
63
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/dev")));
|
64
|
+
await dev(api, options);
|
65
|
+
});
|
66
|
+
program.command('build').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.build.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.shared.analyze)).action(async options => {
|
67
|
+
const {
|
68
|
+
build
|
69
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
|
70
|
+
await build(api, options); // force exit after build.
|
71
|
+
// eslint-disable-next-line no-process-exit
|
72
|
+
|
73
|
+
process.exit(0);
|
74
|
+
});
|
75
|
+
program.command('start').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.start.describe)).option('--api-only', _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async () => {
|
76
|
+
const {
|
77
|
+
start
|
78
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/start")));
|
79
|
+
await start(api);
|
80
|
+
});
|
81
|
+
program.command('deploy').usage('[options]').option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).description(_locale.i18n.t(_locale.localeKeys.command.deploy.describe)).action(async options => {
|
82
|
+
const {
|
83
|
+
build
|
84
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
|
85
|
+
await build(api);
|
86
|
+
const {
|
87
|
+
deploy
|
88
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/deploy")));
|
89
|
+
await deploy(api, options); // eslint-disable-next-line no-process-exit
|
90
|
+
|
91
|
+
process.exit(0);
|
92
|
+
});
|
93
|
+
program.command('new').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option('-d, --debug', _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option('-c, --config <config>', _locale.i18n.t(_locale.localeKeys.command.new.config)).option('--dist-tag <tag>', _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option('--registry', _locale.i18n.t(_locale.localeKeys.command.new.registry)).action(async options => {
|
94
|
+
const {
|
95
|
+
MWANewAction
|
96
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/new-action')));
|
97
|
+
await MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
|
98
|
+
locale
|
99
|
+
}));
|
100
|
+
});
|
101
|
+
program.command('inspect').description('inspect internal webpack config').option(`--env <env>`, _locale.i18n.t(_locale.localeKeys.command.inspect.env), 'development').option('--output <output>', _locale.i18n.t(_locale.localeKeys.command.inspect.output), '/').option('--no-console', _locale.i18n.t(_locale.localeKeys.command.inspect.noConsole)).option('--verbose', _locale.i18n.t(_locale.localeKeys.command.inspect.verbose)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async options => {
|
102
|
+
const {
|
103
|
+
inspect
|
104
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/inspect")));
|
105
|
+
inspect(api, options);
|
106
|
+
});
|
107
|
+
upgradeModel.defineCommand(program.command('upgrade'));
|
108
|
+
},
|
109
|
+
|
110
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
111
|
+
async fileChange(e) {
|
112
|
+
const {
|
113
|
+
filename,
|
114
|
+
eventType
|
115
|
+
} = e;
|
116
|
+
const appContext = api.useAppContext();
|
117
|
+
const {
|
118
|
+
appDirectory,
|
119
|
+
srcDirectory
|
120
|
+
} = appContext;
|
121
|
+
|
122
|
+
const absolutePath = _path.default.resolve(appDirectory, filename);
|
123
|
+
|
124
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
125
|
+
const {
|
126
|
+
closeServer
|
127
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./utils/createServer")));
|
128
|
+
await closeServer();
|
129
|
+
await _core.cli.restart();
|
130
|
+
}
|
131
|
+
},
|
132
|
+
|
133
|
+
async beforeRestart() {
|
134
|
+
(0, _utils.cleanRequireCache)([require.resolve("./analyze")]);
|
135
|
+
}
|
136
|
+
|
137
|
+
};
|
138
|
+
}
|
139
|
+
});
|
140
|
+
|
141
|
+
exports.default = _default;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.EN_LOCALE = void 0;
|
7
|
+
const EN_LOCALE = {
|
8
|
+
command: {
|
9
|
+
shared: {
|
10
|
+
analyze: 'analyze bundle size',
|
11
|
+
config: 'specify config file'
|
12
|
+
},
|
13
|
+
dev: {
|
14
|
+
describe: 'start dev server',
|
15
|
+
entry: 'compiler by entry',
|
16
|
+
apiOnly: 'start api server only'
|
17
|
+
},
|
18
|
+
build: {
|
19
|
+
describe: 'build application'
|
20
|
+
},
|
21
|
+
start: {
|
22
|
+
describe: 'start server'
|
23
|
+
},
|
24
|
+
deploy: {
|
25
|
+
describe: 'deploy application'
|
26
|
+
},
|
27
|
+
new: {
|
28
|
+
describe: 'generator runner for MWA project',
|
29
|
+
debug: 'using debug mode to log something',
|
30
|
+
config: 'set default generator config(json string)',
|
31
|
+
distTag: `use specified tag version for it's generator`,
|
32
|
+
registry: 'set npm registry url to run npm command'
|
33
|
+
},
|
34
|
+
inspect: {
|
35
|
+
env: 'specify env mode',
|
36
|
+
output: 'specify inspect content output path',
|
37
|
+
noConsole: 'do not log the result in terminal',
|
38
|
+
verbose: 'show full function definitions in output'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
};
|
42
|
+
exports.EN_LOCALE = EN_LOCALE;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.localeKeys = exports.i18n = void 0;
|
7
|
+
|
8
|
+
var _pluginI18n = require("@modern-js/plugin-i18n");
|
9
|
+
|
10
|
+
var _zh = require("./zh");
|
11
|
+
|
12
|
+
var _en = require("./en");
|
13
|
+
|
14
|
+
const i18n = new _pluginI18n.I18n();
|
15
|
+
exports.i18n = i18n;
|
16
|
+
const localeKeys = i18n.init('zh', {
|
17
|
+
zh: _zh.ZH_LOCALE,
|
18
|
+
en: _en.EN_LOCALE
|
19
|
+
});
|
20
|
+
exports.localeKeys = localeKeys;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ZH_LOCALE = void 0;
|
7
|
+
const ZH_LOCALE = {
|
8
|
+
command: {
|
9
|
+
shared: {
|
10
|
+
analyze: '分析构建产物体积,查看各个模块打包后的大小',
|
11
|
+
config: '指定配置文件路径,可以为相对路径或绝对路径'
|
12
|
+
},
|
13
|
+
dev: {
|
14
|
+
describe: '本地开发命令',
|
15
|
+
entry: '指定入口,编译特定的页面',
|
16
|
+
apiOnly: '仅启动 API 接口服务'
|
17
|
+
},
|
18
|
+
build: {
|
19
|
+
describe: '构建应用命令'
|
20
|
+
},
|
21
|
+
start: {
|
22
|
+
describe: '应用启动命令'
|
23
|
+
},
|
24
|
+
deploy: {
|
25
|
+
describe: '部署应用命令'
|
26
|
+
},
|
27
|
+
new: {
|
28
|
+
describe: 'MWA 项目中执行生成器',
|
29
|
+
debug: '开启 Debug 模式,打印调试日志信息',
|
30
|
+
config: '生成器运行默认配置(JSON 字符串)',
|
31
|
+
distTag: '生成器使用特殊的 npm Tag 版本',
|
32
|
+
registry: '生成器运行过程中定制 npm Registry'
|
33
|
+
},
|
34
|
+
inspect: {
|
35
|
+
env: '查看指定环境下的配置',
|
36
|
+
output: '指定在 dist 目录下输出的路径',
|
37
|
+
noConsole: '不在终端中输出完整结果',
|
38
|
+
verbose: '在结果中展示函数的完整内容'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
};
|
42
|
+
exports.ZH_LOCALE = ZH_LOCALE;
|