@modern-js/app-tools 2.1.0 → 2.2.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 +47 -0
- package/dist/js/modern/analyze/index.js +13 -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 +8 -0
- 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 +10 -2
- 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 +8 -0
- 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 +25 -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 +14 -0
- 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/createFileWatcher.js +0 -115
- package/dist/types/utils/createFileWatcher.d.ts +0 -4
- package/dist/types/utils/getSpecifiedEntries.d.ts +0 -2
|
@@ -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,14 @@ 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 } 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 { getCommand } from "../utils/commands";
|
|
230
|
+
import { getCommand, isDevCommand } from "../utils/commands";
|
|
231
|
+
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
231
232
|
import { initialNormalizedConfig } from "../config";
|
|
232
233
|
import { getServerLoadersFile, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
|
233
234
|
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
|
@@ -242,7 +243,7 @@ var analyze_default = function() {
|
|
|
242
243
|
return {
|
|
243
244
|
prepare: function prepare() {
|
|
244
245
|
return _asyncToGenerator(function() {
|
|
245
|
-
var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints,
|
|
246
|
+
var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes, htmlTemplates, checkedEntries, entry, command, buildCommands, normalizedConfig, builder;
|
|
246
247
|
return __generator(this, function(_state) {
|
|
247
248
|
switch(_state.label){
|
|
248
249
|
case 0:
|
|
@@ -301,9 +302,6 @@ var analyze_default = function() {
|
|
|
301
302
|
4
|
|
302
303
|
]), getBundleEntry = ref2[0].getBundleEntry, getServerRoutes = ref2[1].getServerRoutes, generateCode = ref2[2].generateCode, getHtmlTemplate = ref2[3].getHtmlTemplate;
|
|
303
304
|
entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
304
|
-
defaultChecked = entrypoints.map(function(point) {
|
|
305
|
-
return point.entryName;
|
|
306
|
-
});
|
|
307
305
|
debug("entrypoints: %o", entrypoints);
|
|
308
306
|
initialRoutes = getServerRoutes(entrypoints, {
|
|
309
307
|
appContext: appContext,
|
|
@@ -353,9 +351,25 @@ var analyze_default = function() {
|
|
|
353
351
|
case 9:
|
|
354
352
|
_state.sent();
|
|
355
353
|
debug("add Define Types");
|
|
354
|
+
checkedEntries = entrypoints.map(function(point) {
|
|
355
|
+
return point.entryName;
|
|
356
|
+
});
|
|
357
|
+
if (!isDevCommand()) return [
|
|
358
|
+
3,
|
|
359
|
+
11
|
|
360
|
+
];
|
|
361
|
+
entry = minimist(process.argv.slice(2)).entry;
|
|
362
|
+
return [
|
|
363
|
+
4,
|
|
364
|
+
getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
|
|
365
|
+
];
|
|
366
|
+
case 10:
|
|
367
|
+
checkedEntries = _state.sent();
|
|
368
|
+
_state.label = 11;
|
|
369
|
+
case 11:
|
|
356
370
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
357
371
|
entrypoints: entrypoints,
|
|
358
|
-
checkedEntries:
|
|
372
|
+
checkedEntries: checkedEntries,
|
|
359
373
|
apiOnly: apiOnly,
|
|
360
374
|
serverRoutes: routes,
|
|
361
375
|
htmlTemplates: htmlTemplates
|
|
@@ -371,7 +385,7 @@ var analyze_default = function() {
|
|
|
371
385
|
];
|
|
372
386
|
if (!buildCommands.includes(command)) return [
|
|
373
387
|
3,
|
|
374
|
-
|
|
388
|
+
13
|
|
375
389
|
];
|
|
376
390
|
normalizedConfig = api.useResolvedConfigContext();
|
|
377
391
|
return [
|
|
@@ -505,15 +519,15 @@ var analyze_default = function() {
|
|
|
505
519
|
}
|
|
506
520
|
})
|
|
507
521
|
];
|
|
508
|
-
case
|
|
522
|
+
case 12:
|
|
509
523
|
builder = _state.sent();
|
|
510
524
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
511
525
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
512
526
|
builder: builder
|
|
513
527
|
});
|
|
514
528
|
api.setAppContext(appContext);
|
|
515
|
-
_state.label =
|
|
516
|
-
case
|
|
529
|
+
_state.label = 13;
|
|
530
|
+
case 13:
|
|
517
531
|
return [
|
|
518
532
|
2
|
|
519
533
|
];
|
|
@@ -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(),
|
|
@@ -185,6 +185,7 @@ import { i18n, localeKeys } from "./locale";
|
|
|
185
185
|
import { getLocaleLanguage } from "./utils/language";
|
|
186
186
|
import { getCommand } from "./utils/commands";
|
|
187
187
|
import { restart } from "./utils/restart";
|
|
188
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
188
189
|
export * from "./defineConfig";
|
|
189
190
|
export * from "./types";
|
|
190
191
|
var upgradeModel = Import.lazy("@modern-js/upgrade", require);
|
|
@@ -633,6 +634,19 @@ var src_default = function() {
|
|
|
633
634
|
});
|
|
634
635
|
})();
|
|
635
636
|
},
|
|
637
|
+
watchFiles: function watchFiles() {
|
|
638
|
+
return _asyncToGenerator(function() {
|
|
639
|
+
var appContext, config;
|
|
640
|
+
return __generator(this, function(_state) {
|
|
641
|
+
appContext = api.useAppContext();
|
|
642
|
+
config = api.useResolvedConfigContext();
|
|
643
|
+
return [
|
|
644
|
+
2,
|
|
645
|
+
generateWatchFiles(appContext, config.source.configDir)
|
|
646
|
+
];
|
|
647
|
+
});
|
|
648
|
+
})();
|
|
649
|
+
},
|
|
636
650
|
fileChange: function fileChange(e) {
|
|
637
651
|
return _asyncToGenerator(function() {
|
|
638
652
|
var filename, eventType, appContext, appDirectory, srcDirectory, absolutePath, closeServer;
|
|
@@ -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"
|
|
@@ -147,10 +147,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
|
-
import crypto from "crypto";
|
|
151
|
-
import fs from "fs";
|
|
152
150
|
import path from "path";
|
|
153
|
-
import {
|
|
151
|
+
import { fs, getServerConfig } from "@modern-js/utils";
|
|
154
152
|
var getPackageConfig = function(appDirectory, packageJsonConfig) {
|
|
155
153
|
var PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
|
156
154
|
var json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8"));
|
|
@@ -181,29 +179,17 @@ var addServerConfigToDeps = function() {
|
|
|
181
179
|
return _ref.apply(this, arguments);
|
|
182
180
|
};
|
|
183
181
|
}();
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
var
|
|
190
|
-
var _ref = _asyncToGenerator(function(appContext, configDir, hooksRunner) {
|
|
191
|
-
var appDirectory, configFile, extraFiles, configPath, dependencies, watched, watcher;
|
|
182
|
+
function generateWatchFiles(appContext, configDir) {
|
|
183
|
+
return _generateWatchFiles.apply(this, arguments);
|
|
184
|
+
}
|
|
185
|
+
function _generateWatchFiles() {
|
|
186
|
+
_generateWatchFiles = _asyncToGenerator(function(appContext, configDir) {
|
|
187
|
+
var appDirectory, configFile, configPath, dependencies;
|
|
192
188
|
return __generator(this, function(_state) {
|
|
193
189
|
switch(_state.label){
|
|
194
190
|
case 0:
|
|
195
|
-
if (!(isDev() || isTest())) return [
|
|
196
|
-
3,
|
|
197
|
-
3
|
|
198
|
-
];
|
|
199
191
|
appDirectory = appContext.appDirectory, configFile = appContext.configFile;
|
|
200
|
-
|
|
201
|
-
4,
|
|
202
|
-
hooksRunner.watchFiles()
|
|
203
|
-
];
|
|
204
|
-
case 1:
|
|
205
|
-
extraFiles = _state.sent();
|
|
206
|
-
configPath = path.join(appDirectory, configDir);
|
|
192
|
+
configPath = path.join(appDirectory, configDir || "");
|
|
207
193
|
dependencies = getPackageConfig(appContext.appDirectory, appContext.packageName) ? [
|
|
208
194
|
path.resolve(appDirectory, "./package.json")
|
|
209
195
|
] : [];
|
|
@@ -211,73 +197,18 @@ var createFileWatcher = function() {
|
|
|
211
197
|
4,
|
|
212
198
|
addServerConfigToDeps(dependencies, appContext.appDirectory, appContext.serverConfigFile)
|
|
213
199
|
];
|
|
214
|
-
case
|
|
200
|
+
case 1:
|
|
215
201
|
_state.sent();
|
|
216
|
-
watched = [
|
|
217
|
-
"".concat(configPath, "/html")
|
|
218
|
-
].concat(_toConsumableArray(extraFiles), _toConsumableArray(dependencies), [
|
|
219
|
-
configFile
|
|
220
|
-
]).filter(Boolean);
|
|
221
|
-
debug("watched: %o", watched);
|
|
222
|
-
watcher = chokidar.watch(watched, {
|
|
223
|
-
cwd: appDirectory,
|
|
224
|
-
ignoreInitial: true,
|
|
225
|
-
ignorePermissionErrors: true,
|
|
226
|
-
ignored: [
|
|
227
|
-
/node_modules/,
|
|
228
|
-
"**/__test__/**",
|
|
229
|
-
"**/*.test.(js|jsx|ts|tsx)",
|
|
230
|
-
"**/*.spec.(js|jsx|ts|tsx)",
|
|
231
|
-
"**/*.stories.(js|jsx|ts|tsx)"
|
|
232
|
-
]
|
|
233
|
-
});
|
|
234
|
-
watcher.on("change", function(changed) {
|
|
235
|
-
var lastHash = hashMap.get(changed);
|
|
236
|
-
var currentHash = md5(fs.readFileSync(path.join(appDirectory, changed), "utf8"));
|
|
237
|
-
if (currentHash !== lastHash) {
|
|
238
|
-
debug("file change: %s", changed);
|
|
239
|
-
hashMap.set(changed, currentHash);
|
|
240
|
-
hooksRunner.fileChange({
|
|
241
|
-
filename: changed,
|
|
242
|
-
eventType: "change"
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
watcher.on("add", function(name) {
|
|
247
|
-
debug("add file: %s", name);
|
|
248
|
-
var currentHash = md5(fs.readFileSync(path.join(appDirectory, name), "utf8"));
|
|
249
|
-
hashMap.set(name, currentHash);
|
|
250
|
-
hooksRunner.fileChange({
|
|
251
|
-
filename: name,
|
|
252
|
-
eventType: "add"
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
watcher.on("unlink", function(name) {
|
|
256
|
-
debug("remove file: %s", name);
|
|
257
|
-
if (hashMap.has(name)) {
|
|
258
|
-
hashMap.delete(name);
|
|
259
|
-
}
|
|
260
|
-
hooksRunner.fileChange({
|
|
261
|
-
filename: name,
|
|
262
|
-
eventType: "unlink"
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
watcher.on("error", function(err) {
|
|
266
|
-
throw err;
|
|
267
|
-
});
|
|
268
202
|
return [
|
|
269
203
|
2,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
2
|
|
204
|
+
[
|
|
205
|
+
"".concat(configPath, "/html"),
|
|
206
|
+
configFile || "./config"
|
|
207
|
+
].concat(_toConsumableArray(dependencies))
|
|
275
208
|
];
|
|
276
209
|
}
|
|
277
210
|
});
|
|
278
211
|
});
|
|
279
|
-
return
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}();
|
|
283
|
-
export { addServerConfigToDeps, createFileWatcher };
|
|
212
|
+
return _generateWatchFiles.apply(this, arguments);
|
|
213
|
+
}
|
|
214
|
+
export { addServerConfigToDeps, generateWatchFiles };
|
|
@@ -122,8 +122,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
|
-
import { inquirer } from "@modern-js/utils";
|
|
126
|
-
|
|
125
|
+
import { chalk, inquirer } from "@modern-js/utils";
|
|
126
|
+
import { i18n, localeKeys } from "../locale";
|
|
127
|
+
var getSelectedEntries = function() {
|
|
127
128
|
var _ref = _asyncToGenerator(function(entry, entrypoints) {
|
|
128
129
|
var entryNames, selected;
|
|
129
130
|
return __generator(this, function(_state) {
|
|
@@ -149,10 +150,10 @@ var getSpecifiedEntries = function() {
|
|
|
149
150
|
type: "checkbox",
|
|
150
151
|
name: "selected",
|
|
151
152
|
choices: entryNames,
|
|
152
|
-
message:
|
|
153
|
+
message: i18n.t(localeKeys.command.dev.selectEntry),
|
|
153
154
|
validate: function validate(answer) {
|
|
154
155
|
if (answer.length < 1) {
|
|
155
|
-
return
|
|
156
|
+
return i18n.t(localeKeys.command.dev.requireEntry);
|
|
156
157
|
}
|
|
157
158
|
return true;
|
|
158
159
|
}
|
|
@@ -168,7 +169,7 @@ var getSpecifiedEntries = function() {
|
|
|
168
169
|
case 2:
|
|
169
170
|
entry.forEach(function(name) {
|
|
170
171
|
if (!entryNames.includes(name)) {
|
|
171
|
-
throw new Error("
|
|
172
|
+
throw new Error("Can not found entry ".concat(chalk.yellow(name), ", the entry should be one of ").concat(chalk.yellow(entryNames.join(", "))));
|
|
172
173
|
}
|
|
173
174
|
});
|
|
174
175
|
return [
|
|
@@ -178,8 +179,8 @@ var getSpecifiedEntries = function() {
|
|
|
178
179
|
}
|
|
179
180
|
});
|
|
180
181
|
});
|
|
181
|
-
return function
|
|
182
|
+
return function getSelectedEntries(entry, entrypoints) {
|
|
182
183
|
return _ref.apply(this, arguments);
|
|
183
184
|
};
|
|
184
185
|
}();
|
|
185
|
-
export {
|
|
186
|
+
export { getSelectedEntries };
|
|
@@ -10,6 +10,8 @@ declare const localeKeys: {
|
|
|
10
10
|
describe: string;
|
|
11
11
|
entry: string;
|
|
12
12
|
apiOnly: string;
|
|
13
|
+
selectEntry: string;
|
|
14
|
+
requireEntry: string;
|
|
13
15
|
};
|
|
14
16
|
build: {
|
|
15
17
|
describe: string;
|
|
@@ -44,6 +46,8 @@ declare const localeKeys: {
|
|
|
44
46
|
describe: string;
|
|
45
47
|
entry: string;
|
|
46
48
|
apiOnly: string;
|
|
49
|
+
selectEntry: string;
|
|
50
|
+
requireEntry: string;
|
|
47
51
|
};
|
|
48
52
|
build: {
|
|
49
53
|
describe: string;
|
|
@@ -76,11 +76,6 @@ export type AppToolsHooks = {
|
|
|
76
76
|
}, unknown>;
|
|
77
77
|
beforeDeploy: AsyncWorkflow<Record<string, any>, unknown>;
|
|
78
78
|
afterDeploy: AsyncWorkflow<Record<string, any>, unknown>;
|
|
79
|
-
watchFiles: ParallelWorkflow<void>;
|
|
80
|
-
fileChange: AsyncWorkflow<{
|
|
81
|
-
filename: string;
|
|
82
|
-
eventType: 'add' | 'change' | 'unlink';
|
|
83
|
-
}, void>;
|
|
84
79
|
beforeRestart: AsyncWorkflow<void, void>;
|
|
85
80
|
registerDev: ParallelWorkflow<void, DevToolData>;
|
|
86
81
|
beforeDevTask: ParallelWorkflow<DevToolData, void>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IAppContext } from '../types';
|
|
2
|
+
export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
|
|
3
|
+
export declare function generateWatchFiles(appContext: IAppContext, configDir?: string): Promise<string[]>;
|