@modern-js/app-tools 2.1.0 → 2.3.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 +89 -0
- package/dist/js/modern/analyze/index.js +14 -4
- package/dist/js/modern/analyze/nestedRoutes.js +5 -1
- package/dist/js/modern/builder/index.js +4 -4
- package/dist/js/modern/commands/dev.js +1 -23
- package/dist/js/modern/hooks.js +0 -2
- package/dist/js/modern/index.js +14 -2
- package/dist/js/modern/initialize/index.js +6 -2
- package/dist/js/modern/locale/en.js +3 -1
- package/dist/js/modern/locale/zh.js +3 -1
- package/dist/js/modern/utils/generateWatchFiles.js +55 -0
- package/dist/js/modern/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +9 -8
- package/dist/js/node/analyze/index.js +11 -4
- package/dist/js/node/analyze/nestedRoutes.js +5 -1
- package/dist/js/node/builder/index.js +4 -4
- package/dist/js/node/commands/dev.js +1 -23
- package/dist/js/node/hooks.js +0 -2
- package/dist/js/node/index.js +9 -2
- package/dist/js/node/initialize/index.js +1 -2
- package/dist/js/node/locale/en.js +3 -1
- package/dist/js/node/locale/zh.js +3 -1
- package/dist/js/node/utils/{createFileWatcher.js → generateWatchFiles.js} +12 -66
- package/dist/js/node/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +12 -11
- package/dist/js/treeshaking/analyze/index.js +24 -11
- package/dist/js/treeshaking/analyze/nestedRoutes.js +12 -3
- package/dist/js/treeshaking/builder/index.js +5 -5
- package/dist/js/treeshaking/commands/dev.js +13 -31
- package/dist/js/treeshaking/hooks.js +0 -2
- package/dist/js/treeshaking/index.js +15 -2
- package/dist/js/treeshaking/initialize/index.js +1 -2
- package/dist/js/treeshaking/locale/en.js +3 -1
- package/dist/js/treeshaking/locale/zh.js +3 -1
- package/dist/js/treeshaking/utils/{createFileWatcher.js → generateWatchFiles.js} +16 -85
- package/dist/js/treeshaking/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +8 -7
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/types/hooks.d.ts +0 -5
- package/dist/types/utils/generateWatchFiles.d.ts +3 -0
- package/dist/types/utils/getSelectedEntries.d.ts +6 -0
- package/package.json +22 -22
- package/dist/js/modern/utils/commands.js +0 -13
- package/dist/js/modern/utils/createFileWatcher.js +0 -115
- package/dist/js/node/utils/commands.js +0 -37
- package/dist/js/treeshaking/utils/commands.js +0 -10
- package/dist/types/utils/commands.d.ts +0 -2
- package/dist/types/utils/createFileWatcher.d.ts +0 -4
- package/dist/types/utils/getSpecifiedEntries.d.ts +0 -2
|
@@ -41,20 +41,18 @@ var __async = (__this, __arguments, generator) => {
|
|
|
41
41
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
-
var
|
|
45
|
-
__export(
|
|
44
|
+
var generateWatchFiles_exports = {};
|
|
45
|
+
__export(generateWatchFiles_exports, {
|
|
46
46
|
addServerConfigToDeps: () => addServerConfigToDeps,
|
|
47
|
-
|
|
47
|
+
generateWatchFiles: () => generateWatchFiles
|
|
48
48
|
});
|
|
49
|
-
module.exports = __toCommonJS(
|
|
50
|
-
var import_crypto = __toESM(require("crypto"));
|
|
51
|
-
var import_fs = __toESM(require("fs"));
|
|
49
|
+
module.exports = __toCommonJS(generateWatchFiles_exports);
|
|
52
50
|
var import_path = __toESM(require("path"));
|
|
53
51
|
var import_utils = require("@modern-js/utils");
|
|
54
52
|
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
55
53
|
const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
|
56
54
|
const json = JSON.parse(
|
|
57
|
-
|
|
55
|
+
import_utils.fs.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8")
|
|
58
56
|
);
|
|
59
57
|
return json[packageJsonConfig != null ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
|
60
58
|
};
|
|
@@ -64,14 +62,10 @@ const addServerConfigToDeps = (dependencies, appDirectory, serverConfigFile) =>
|
|
|
64
62
|
dependencies.push(serverConfig);
|
|
65
63
|
}
|
|
66
64
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const hashMap = /* @__PURE__ */ new Map();
|
|
70
|
-
const createFileWatcher = (appContext, configDir, hooksRunner) => __async(void 0, null, function* () {
|
|
71
|
-
if ((0, import_utils.isDev)() || (0, import_utils.isTest)()) {
|
|
65
|
+
function generateWatchFiles(appContext, configDir) {
|
|
66
|
+
return __async(this, null, function* () {
|
|
72
67
|
const { appDirectory, configFile } = appContext;
|
|
73
|
-
const
|
|
74
|
-
const configPath = import_path.default.join(appDirectory, configDir);
|
|
68
|
+
const configPath = import_path.default.join(appDirectory, configDir || "");
|
|
75
69
|
const dependencies = getPackageConfig(
|
|
76
70
|
appContext.appDirectory,
|
|
77
71
|
appContext.packageName
|
|
@@ -81,59 +75,11 @@ const createFileWatcher = (appContext, configDir, hooksRunner) => __async(void 0
|
|
|
81
75
|
appContext.appDirectory,
|
|
82
76
|
appContext.serverConfigFile
|
|
83
77
|
);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
...dependencies,
|
|
88
|
-
configFile
|
|
89
|
-
].filter(Boolean);
|
|
90
|
-
debug(`watched: %o`, watched);
|
|
91
|
-
const watcher = import_utils.chokidar.watch(watched, {
|
|
92
|
-
cwd: appDirectory,
|
|
93
|
-
ignoreInitial: true,
|
|
94
|
-
ignorePermissionErrors: true,
|
|
95
|
-
ignored: [
|
|
96
|
-
/node_modules/,
|
|
97
|
-
"**/__test__/**",
|
|
98
|
-
"**/*.test.(js|jsx|ts|tsx)",
|
|
99
|
-
"**/*.spec.(js|jsx|ts|tsx)",
|
|
100
|
-
"**/*.stories.(js|jsx|ts|tsx)"
|
|
101
|
-
]
|
|
102
|
-
});
|
|
103
|
-
watcher.on("change", (changed) => {
|
|
104
|
-
const lastHash = hashMap.get(changed);
|
|
105
|
-
const currentHash = md5(
|
|
106
|
-
import_fs.default.readFileSync(import_path.default.join(appDirectory, changed), "utf8")
|
|
107
|
-
);
|
|
108
|
-
if (currentHash !== lastHash) {
|
|
109
|
-
debug(`file change: %s`, changed);
|
|
110
|
-
hashMap.set(changed, currentHash);
|
|
111
|
-
hooksRunner.fileChange({ filename: changed, eventType: "change" });
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
watcher.on("add", (name) => {
|
|
115
|
-
debug(`add file: %s`, name);
|
|
116
|
-
const currentHash = md5(
|
|
117
|
-
import_fs.default.readFileSync(import_path.default.join(appDirectory, name), "utf8")
|
|
118
|
-
);
|
|
119
|
-
hashMap.set(name, currentHash);
|
|
120
|
-
hooksRunner.fileChange({ filename: name, eventType: "add" });
|
|
121
|
-
});
|
|
122
|
-
watcher.on("unlink", (name) => {
|
|
123
|
-
debug(`remove file: %s`, name);
|
|
124
|
-
if (hashMap.has(name)) {
|
|
125
|
-
hashMap.delete(name);
|
|
126
|
-
}
|
|
127
|
-
hooksRunner.fileChange({ filename: name, eventType: "unlink" });
|
|
128
|
-
});
|
|
129
|
-
watcher.on("error", (err) => {
|
|
130
|
-
throw err;
|
|
131
|
-
});
|
|
132
|
-
return watcher;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
78
|
+
return [`${configPath}/html`, configFile || "./config", ...dependencies];
|
|
79
|
+
});
|
|
80
|
+
}
|
|
135
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
136
82
|
0 && (module.exports = {
|
|
137
83
|
addServerConfigToDeps,
|
|
138
|
-
|
|
84
|
+
generateWatchFiles
|
|
139
85
|
});
|
|
@@ -35,13 +35,14 @@ var __async = (__this, __arguments, generator) => {
|
|
|
35
35
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
|
-
var
|
|
39
|
-
__export(
|
|
40
|
-
|
|
38
|
+
var getSelectedEntries_exports = {};
|
|
39
|
+
__export(getSelectedEntries_exports, {
|
|
40
|
+
getSelectedEntries: () => getSelectedEntries
|
|
41
41
|
});
|
|
42
|
-
module.exports = __toCommonJS(
|
|
42
|
+
module.exports = __toCommonJS(getSelectedEntries_exports);
|
|
43
43
|
var import_utils = require("@modern-js/utils");
|
|
44
|
-
|
|
44
|
+
var import_locale = require("../locale");
|
|
45
|
+
const getSelectedEntries = (entry, entrypoints) => __async(void 0, null, function* () {
|
|
45
46
|
const entryNames = entrypoints.map((e) => e.entryName);
|
|
46
47
|
if (!entry) {
|
|
47
48
|
return entryNames;
|
|
@@ -52,10 +53,10 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
|
|
|
52
53
|
type: "checkbox",
|
|
53
54
|
name: "selected",
|
|
54
55
|
choices: entryNames,
|
|
55
|
-
message:
|
|
56
|
+
message: import_locale.i18n.t(import_locale.localeKeys.command.dev.selectEntry),
|
|
56
57
|
validate(answer) {
|
|
57
58
|
if (answer.length < 1) {
|
|
58
|
-
return
|
|
59
|
+
return import_locale.i18n.t(import_locale.localeKeys.command.dev.requireEntry);
|
|
59
60
|
}
|
|
60
61
|
return true;
|
|
61
62
|
}
|
|
@@ -66,9 +67,9 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
|
|
|
66
67
|
entry.forEach((name) => {
|
|
67
68
|
if (!entryNames.includes(name)) {
|
|
68
69
|
throw new Error(
|
|
69
|
-
`
|
|
70
|
-
|
|
71
|
-
)}`
|
|
70
|
+
`Can not found entry ${import_utils.chalk.yellow(
|
|
71
|
+
name
|
|
72
|
+
)}, the entry should be one of ${import_utils.chalk.yellow(entryNames.join(", "))}`
|
|
72
73
|
);
|
|
73
74
|
}
|
|
74
75
|
});
|
|
@@ -76,5 +77,5 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
|
|
|
76
77
|
});
|
|
77
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
78
79
|
0 && (module.exports = {
|
|
79
|
-
|
|
80
|
+
getSelectedEntries
|
|
80
81
|
});
|
|
@@ -221,13 +221,13 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
import * as path from "path";
|
|
224
|
-
import { createDebugger, findExists, fs, getEntryOptions, isApiOnly } from "@modern-js/utils";
|
|
224
|
+
import { createDebugger, findExists, fs, getEntryOptions, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
|
|
225
225
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
226
226
|
import { createBuilderForModern } from "../builder";
|
|
227
227
|
import { printInstructions } from "../utils/printInstructions";
|
|
228
228
|
import { generateRoutes } from "../utils/routes";
|
|
229
229
|
import { emitResolvedConfig } from "../utils/config";
|
|
230
|
-
import {
|
|
230
|
+
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
231
231
|
import { initialNormalizedConfig } from "../config";
|
|
232
232
|
import { getServerLoadersFile, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
|
233
233
|
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
|
@@ -242,7 +242,7 @@ var analyze_default = function() {
|
|
|
242
242
|
return {
|
|
243
243
|
prepare: function prepare() {
|
|
244
244
|
return _asyncToGenerator(function() {
|
|
245
|
-
var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints,
|
|
245
|
+
var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes, htmlTemplates, checkedEntries, entry, command, buildCommands, normalizedConfig, builder;
|
|
246
246
|
return __generator(this, function(_state) {
|
|
247
247
|
switch(_state.label){
|
|
248
248
|
case 0:
|
|
@@ -301,9 +301,6 @@ var analyze_default = function() {
|
|
|
301
301
|
4
|
|
302
302
|
]), getBundleEntry = ref2[0].getBundleEntry, getServerRoutes = ref2[1].getServerRoutes, generateCode = ref2[2].generateCode, getHtmlTemplate = ref2[3].getHtmlTemplate;
|
|
303
303
|
entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
304
|
-
defaultChecked = entrypoints.map(function(point) {
|
|
305
|
-
return point.entryName;
|
|
306
|
-
});
|
|
307
304
|
debug("entrypoints: %o", entrypoints);
|
|
308
305
|
initialRoutes = getServerRoutes(entrypoints, {
|
|
309
306
|
appContext: appContext,
|
|
@@ -353,9 +350,25 @@ var analyze_default = function() {
|
|
|
353
350
|
case 9:
|
|
354
351
|
_state.sent();
|
|
355
352
|
debug("add Define Types");
|
|
353
|
+
checkedEntries = entrypoints.map(function(point) {
|
|
354
|
+
return point.entryName;
|
|
355
|
+
});
|
|
356
|
+
if (!isDevCommand()) return [
|
|
357
|
+
3,
|
|
358
|
+
11
|
|
359
|
+
];
|
|
360
|
+
entry = minimist(process.argv.slice(2)).entry;
|
|
361
|
+
return [
|
|
362
|
+
4,
|
|
363
|
+
getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
|
|
364
|
+
];
|
|
365
|
+
case 10:
|
|
366
|
+
checkedEntries = _state.sent();
|
|
367
|
+
_state.label = 11;
|
|
368
|
+
case 11:
|
|
356
369
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
357
370
|
entrypoints: entrypoints,
|
|
358
|
-
checkedEntries:
|
|
371
|
+
checkedEntries: checkedEntries,
|
|
359
372
|
apiOnly: apiOnly,
|
|
360
373
|
serverRoutes: routes,
|
|
361
374
|
htmlTemplates: htmlTemplates
|
|
@@ -371,7 +384,7 @@ var analyze_default = function() {
|
|
|
371
384
|
];
|
|
372
385
|
if (!buildCommands.includes(command)) return [
|
|
373
386
|
3,
|
|
374
|
-
|
|
387
|
+
13
|
|
375
388
|
];
|
|
376
389
|
normalizedConfig = api.useResolvedConfigContext();
|
|
377
390
|
return [
|
|
@@ -505,15 +518,15 @@ var analyze_default = function() {
|
|
|
505
518
|
}
|
|
506
519
|
})
|
|
507
520
|
];
|
|
508
|
-
case
|
|
521
|
+
case 12:
|
|
509
522
|
builder = _state.sent();
|
|
510
523
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
511
524
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
512
525
|
builder: builder
|
|
513
526
|
});
|
|
514
527
|
api.setAppContext(appContext);
|
|
515
|
-
_state.label =
|
|
516
|
-
case
|
|
528
|
+
_state.label = 13;
|
|
529
|
+
case 13:
|
|
517
530
|
return [
|
|
518
531
|
2
|
|
519
532
|
];
|
|
@@ -197,7 +197,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
|
|
|
197
197
|
};
|
|
198
198
|
var walk = function() {
|
|
199
199
|
var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
|
|
200
|
-
var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute,
|
|
200
|
+
var ref, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref1, ref2, err, finalRoute;
|
|
201
201
|
return __generator(this, function(_state) {
|
|
202
202
|
switch(_state.label){
|
|
203
203
|
case 0:
|
|
@@ -286,7 +286,7 @@ var walk = function() {
|
|
|
286
286
|
childRoute = _state.sent();
|
|
287
287
|
if (childRoute) {
|
|
288
288
|
;
|
|
289
|
-
(
|
|
289
|
+
(ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(childRoute);
|
|
290
290
|
}
|
|
291
291
|
_state.label = 8;
|
|
292
292
|
case 8:
|
|
@@ -315,7 +315,7 @@ var walk = function() {
|
|
|
315
315
|
if (pageLoaderFile) {
|
|
316
316
|
pageRoute.loader = pageLoaderFile;
|
|
317
317
|
}
|
|
318
|
-
(
|
|
318
|
+
(ref2 = route.children) === null || ref2 === void 0 ? void 0 : ref2.push(pageRoute);
|
|
319
319
|
}
|
|
320
320
|
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
|
321
321
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
@@ -361,6 +361,15 @@ var walk = function() {
|
|
|
361
361
|
if (isPathlessLayout) {
|
|
362
362
|
delete finalRoute.path;
|
|
363
363
|
}
|
|
364
|
+
route.children = (ref = route.children) === null || ref === void 0 ? void 0 : ref.filter(function(childRoute) {
|
|
365
|
+
return childRoute;
|
|
366
|
+
});
|
|
367
|
+
if (route.children && route.children.length === 0 && !route.index) {
|
|
368
|
+
return [
|
|
369
|
+
2,
|
|
370
|
+
null
|
|
371
|
+
];
|
|
372
|
+
}
|
|
364
373
|
return [
|
|
365
374
|
2,
|
|
366
375
|
finalRoute
|
|
@@ -322,7 +322,7 @@ function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPlugin
|
|
|
322
322
|
}
|
|
323
323
|
function _applyBuilderPlugins() {
|
|
324
324
|
_applyBuilderPlugins = _asyncToGenerator(function(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
325
|
-
var
|
|
325
|
+
var builderPluginNodePolyfill, _tools, esbuildOptions, builderPluginEsbuild;
|
|
326
326
|
return __generator(this, function(_state) {
|
|
327
327
|
switch(_state.label){
|
|
328
328
|
case 0:
|
|
@@ -335,9 +335,9 @@ function _applyBuilderPlugins() {
|
|
|
335
335
|
import("@modern-js/builder-plugin-node-polyfill")
|
|
336
336
|
];
|
|
337
337
|
case 1:
|
|
338
|
-
|
|
338
|
+
builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
|
|
339
339
|
builder.addPlugins([
|
|
340
|
-
|
|
340
|
+
builderPluginNodePolyfill()
|
|
341
341
|
]);
|
|
342
342
|
_state.label = 2;
|
|
343
343
|
case 2:
|
|
@@ -351,9 +351,9 @@ function _applyBuilderPlugins() {
|
|
|
351
351
|
import("@modern-js/builder-plugin-esbuild")
|
|
352
352
|
];
|
|
353
353
|
case 3:
|
|
354
|
-
|
|
354
|
+
builderPluginEsbuild = _state.sent().builderPluginEsbuild;
|
|
355
355
|
builder.addPlugins([
|
|
356
|
-
|
|
356
|
+
builderPluginEsbuild({
|
|
357
357
|
loader: false,
|
|
358
358
|
minimize: applyOptionsChain({}, esbuildOptions)
|
|
359
359
|
})
|
|
@@ -175,16 +175,14 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
import { ResolvedConfigContext } from "@modern-js/core";
|
|
178
|
-
import { createFileWatcher } from "../utils/createFileWatcher";
|
|
179
178
|
import { printInstructions } from "../utils/printInstructions";
|
|
180
179
|
import { setServer, createServer, injectDataLoaderPlugin } from "../utils/createServer";
|
|
181
180
|
import { generateRoutes } from "../utils/routes";
|
|
182
|
-
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
183
181
|
import { buildServerConfig } from "../utils/config";
|
|
184
182
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
185
183
|
var dev = function() {
|
|
186
184
|
var _ref = _asyncToGenerator(function(api, options) {
|
|
187
|
-
var ref, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly,
|
|
185
|
+
var ref, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions, app, server;
|
|
188
186
|
return __generator(this, function(_state) {
|
|
189
187
|
switch(_state.label){
|
|
190
188
|
case 0:
|
|
@@ -198,17 +196,7 @@ var dev = function() {
|
|
|
198
196
|
cliOptions: options
|
|
199
197
|
});
|
|
200
198
|
ResolvedConfigContext.set(normalizedConfig);
|
|
201
|
-
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly,
|
|
202
|
-
return [
|
|
203
|
-
4,
|
|
204
|
-
getSpecifiedEntries(options.entry || false, entrypoints)
|
|
205
|
-
];
|
|
206
|
-
case 1:
|
|
207
|
-
checkedEntries = _state.sent();
|
|
208
|
-
api.setAppContext(_objectSpreadProps(_objectSpread({}, appContext), {
|
|
209
|
-
checkedEntries: checkedEntries
|
|
210
|
-
}));
|
|
211
|
-
appContext.checkedEntries = checkedEntries;
|
|
199
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile;
|
|
212
200
|
return [
|
|
213
201
|
4,
|
|
214
202
|
buildServerConfig({
|
|
@@ -222,13 +210,13 @@ var dev = function() {
|
|
|
222
210
|
}
|
|
223
211
|
})
|
|
224
212
|
];
|
|
225
|
-
case
|
|
213
|
+
case 1:
|
|
226
214
|
_state.sent();
|
|
227
215
|
return [
|
|
228
216
|
4,
|
|
229
217
|
hookRunners.beforeDev()
|
|
230
218
|
];
|
|
231
|
-
case
|
|
219
|
+
case 2:
|
|
232
220
|
_state.sent();
|
|
233
221
|
if (!appContext.builder && !apiOnly) {
|
|
234
222
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
@@ -237,13 +225,13 @@ var dev = function() {
|
|
|
237
225
|
4,
|
|
238
226
|
generateRoutes(appContext)
|
|
239
227
|
];
|
|
240
|
-
case
|
|
228
|
+
case 3:
|
|
241
229
|
_state.sent();
|
|
242
230
|
return [
|
|
243
231
|
4,
|
|
244
232
|
getServerInternalPlugins(api)
|
|
245
233
|
];
|
|
246
|
-
case
|
|
234
|
+
case 4:
|
|
247
235
|
serverInternalPlugins = _state.sent();
|
|
248
236
|
serverOptions = {
|
|
249
237
|
dev: _objectSpread({
|
|
@@ -257,7 +245,7 @@ var dev = function() {
|
|
|
257
245
|
};
|
|
258
246
|
if (!apiOnly) return [
|
|
259
247
|
3,
|
|
260
|
-
|
|
248
|
+
6
|
|
261
249
|
];
|
|
262
250
|
return [
|
|
263
251
|
4,
|
|
@@ -265,7 +253,7 @@ var dev = function() {
|
|
|
265
253
|
compiler: null
|
|
266
254
|
}))
|
|
267
255
|
];
|
|
268
|
-
case
|
|
256
|
+
case 5:
|
|
269
257
|
app = _state.sent();
|
|
270
258
|
app.listen(port, function() {
|
|
271
259
|
var _ref = _asyncToGenerator(function(err) {
|
|
@@ -285,9 +273,9 @@ var dev = function() {
|
|
|
285
273
|
}());
|
|
286
274
|
return [
|
|
287
275
|
3,
|
|
288
|
-
|
|
276
|
+
8
|
|
289
277
|
];
|
|
290
|
-
case
|
|
278
|
+
case 6:
|
|
291
279
|
return [
|
|
292
280
|
4,
|
|
293
281
|
appContext.builder.startDevServer({
|
|
@@ -295,17 +283,11 @@ var dev = function() {
|
|
|
295
283
|
serverOptions: serverOptions
|
|
296
284
|
})
|
|
297
285
|
];
|
|
298
|
-
case
|
|
286
|
+
case 7:
|
|
299
287
|
server = _state.sent().server;
|
|
300
288
|
setServer(server);
|
|
301
|
-
_state.label =
|
|
302
|
-
case
|
|
303
|
-
return [
|
|
304
|
-
4,
|
|
305
|
-
createFileWatcher(appContext, normalizedConfig.source.configDir, hookRunners)
|
|
306
|
-
];
|
|
307
|
-
case 10:
|
|
308
|
-
_state.sent();
|
|
289
|
+
_state.label = 8;
|
|
290
|
+
case 8:
|
|
309
291
|
return [
|
|
310
292
|
2
|
|
311
293
|
];
|
|
@@ -20,8 +20,6 @@ var hooks = {
|
|
|
20
20
|
afterBuild: createAsyncWorkflow(),
|
|
21
21
|
beforeDeploy: createAsyncWorkflow(),
|
|
22
22
|
afterDeploy: createAsyncWorkflow(),
|
|
23
|
-
watchFiles: createParallelWorkflow(),
|
|
24
|
-
fileChange: createAsyncWorkflow(),
|
|
25
23
|
beforeRestart: createAsyncWorkflow(),
|
|
26
24
|
registerDev: createParallelWorkflow(),
|
|
27
25
|
beforeDevTask: createParallelWorkflow(),
|
|
@@ -176,15 +176,15 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
176
176
|
};
|
|
177
177
|
import path from "path";
|
|
178
178
|
import lintPlugin from "@modern-js/plugin-lint";
|
|
179
|
-
import { cleanRequireCache, emptyDir, Import } from "@modern-js/utils";
|
|
179
|
+
import { cleanRequireCache, emptyDir, Import, getCommand } from "@modern-js/utils";
|
|
180
180
|
import { castArray } from "@modern-js/utils/lodash";
|
|
181
181
|
import analyzePlugin from "./analyze";
|
|
182
182
|
import initializePlugin from "./initialize";
|
|
183
183
|
import { hooks } from "./hooks";
|
|
184
184
|
import { i18n, localeKeys } from "./locale";
|
|
185
185
|
import { getLocaleLanguage } from "./utils/language";
|
|
186
|
-
import { getCommand } from "./utils/commands";
|
|
187
186
|
import { restart } from "./utils/restart";
|
|
187
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
188
188
|
export * from "./defineConfig";
|
|
189
189
|
export * from "./types";
|
|
190
190
|
var upgradeModel = Import.lazy("@modern-js/upgrade", require);
|
|
@@ -633,6 +633,19 @@ var src_default = function() {
|
|
|
633
633
|
});
|
|
634
634
|
})();
|
|
635
635
|
},
|
|
636
|
+
watchFiles: function watchFiles() {
|
|
637
|
+
return _asyncToGenerator(function() {
|
|
638
|
+
var appContext, config;
|
|
639
|
+
return __generator(this, function(_state) {
|
|
640
|
+
appContext = api.useAppContext();
|
|
641
|
+
config = api.useResolvedConfigContext();
|
|
642
|
+
return [
|
|
643
|
+
2,
|
|
644
|
+
generateWatchFiles(appContext, config.source.configDir)
|
|
645
|
+
];
|
|
646
|
+
});
|
|
647
|
+
})();
|
|
648
|
+
},
|
|
636
649
|
fileChange: function fileChange(e) {
|
|
637
650
|
return _asyncToGenerator(function() {
|
|
638
651
|
var filename, eventType, appContext, appDirectory, srcDirectory, absolutePath, closeServer;
|
|
@@ -174,9 +174,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
import { ensureAbsolutePath, getPort, isDev } from "@modern-js/utils";
|
|
177
|
+
import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
|
|
178
178
|
import { legacySchema, schema } from "../schema";
|
|
179
|
-
import { isDevCommand } from "../utils/commands";
|
|
180
179
|
import { transformNormalizedConfig } from "../config/initial/transformNormalizedConfig";
|
|
181
180
|
import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig } from "../config";
|
|
182
181
|
var initialize_default = function() {
|
|
@@ -7,7 +7,9 @@ var EN_LOCALE = {
|
|
|
7
7
|
dev: {
|
|
8
8
|
describe: "start dev server",
|
|
9
9
|
entry: "compiler by entry",
|
|
10
|
-
apiOnly: "start api server only"
|
|
10
|
+
apiOnly: "start api server only",
|
|
11
|
+
selectEntry: "Please select the entry that needs to be built",
|
|
12
|
+
requireEntry: "You must choose at least one entry"
|
|
11
13
|
},
|
|
12
14
|
build: {
|
|
13
15
|
describe: "build application"
|