@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.
Files changed (41) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/js/modern/analyze/index.js +13 -4
  3. package/dist/js/modern/analyze/nestedRoutes.js +5 -1
  4. package/dist/js/modern/builder/index.js +4 -4
  5. package/dist/js/modern/commands/dev.js +1 -23
  6. package/dist/js/modern/hooks.js +0 -2
  7. package/dist/js/modern/index.js +8 -0
  8. package/dist/js/modern/locale/en.js +3 -1
  9. package/dist/js/modern/locale/zh.js +3 -1
  10. package/dist/js/modern/utils/generateWatchFiles.js +55 -0
  11. package/dist/js/modern/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +9 -8
  12. package/dist/js/node/analyze/index.js +10 -2
  13. package/dist/js/node/analyze/nestedRoutes.js +5 -1
  14. package/dist/js/node/builder/index.js +4 -4
  15. package/dist/js/node/commands/dev.js +1 -23
  16. package/dist/js/node/hooks.js +0 -2
  17. package/dist/js/node/index.js +8 -0
  18. package/dist/js/node/locale/en.js +3 -1
  19. package/dist/js/node/locale/zh.js +3 -1
  20. package/dist/js/node/utils/{createFileWatcher.js → generateWatchFiles.js} +12 -66
  21. package/dist/js/node/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +12 -11
  22. package/dist/js/treeshaking/analyze/index.js +25 -11
  23. package/dist/js/treeshaking/analyze/nestedRoutes.js +12 -3
  24. package/dist/js/treeshaking/builder/index.js +5 -5
  25. package/dist/js/treeshaking/commands/dev.js +13 -31
  26. package/dist/js/treeshaking/hooks.js +0 -2
  27. package/dist/js/treeshaking/index.js +14 -0
  28. package/dist/js/treeshaking/locale/en.js +3 -1
  29. package/dist/js/treeshaking/locale/zh.js +3 -1
  30. package/dist/js/treeshaking/utils/{createFileWatcher.js → generateWatchFiles.js} +16 -85
  31. package/dist/js/treeshaking/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +8 -7
  32. package/dist/types/locale/en.d.ts +2 -0
  33. package/dist/types/locale/index.d.ts +4 -0
  34. package/dist/types/locale/zh.d.ts +2 -0
  35. package/dist/types/types/hooks.d.ts +0 -5
  36. package/dist/types/utils/generateWatchFiles.d.ts +3 -0
  37. package/dist/types/utils/getSelectedEntries.d.ts +6 -0
  38. package/package.json +22 -22
  39. package/dist/js/modern/utils/createFileWatcher.js +0 -115
  40. package/dist/types/utils/createFileWatcher.d.ts +0 -4
  41. 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 getSpecifiedEntries_exports = {};
39
- __export(getSpecifiedEntries_exports, {
40
- getSpecifiedEntries: () => getSpecifiedEntries
38
+ var getSelectedEntries_exports = {};
39
+ __export(getSelectedEntries_exports, {
40
+ getSelectedEntries: () => getSelectedEntries
41
41
  });
42
- module.exports = __toCommonJS(getSpecifiedEntries_exports);
42
+ module.exports = __toCommonJS(getSelectedEntries_exports);
43
43
  var import_utils = require("@modern-js/utils");
44
- const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, function* () {
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 "You must choose at least one topping.";
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
- `can not found entry ${name}, compiler entry should in ${entryNames.join(
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
- getSpecifiedEntries
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, defaultChecked, initialRoutes, routes, htmlTemplates, command, buildCommands, normalizedConfig, builder;
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: defaultChecked,
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
- 11
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 10:
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 = 11;
516
- case 11:
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, ref, ref1, err, finalRoute;
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
- (ref = route.children) === null || ref === void 0 ? void 0 : ref.push(childRoute);
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
- (ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(pageRoute);
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 PluginNodePolyfill, _tools, esbuildOptions, PluginEsbuild;
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
- PluginNodePolyfill = _state.sent().PluginNodePolyfill;
338
+ builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
339
339
  builder.addPlugins([
340
- PluginNodePolyfill()
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
- PluginEsbuild = _state.sent().PluginEsbuild;
354
+ builderPluginEsbuild = _state.sent().builderPluginEsbuild;
355
355
  builder.addPlugins([
356
- PluginEsbuild({
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, entrypoints, serverConfigFile, checkedEntries, serverInternalPlugins, serverOptions, app, server;
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, entrypoints = appContext.entrypoints, serverConfigFile = appContext.serverConfigFile;
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 2:
213
+ case 1:
226
214
  _state.sent();
227
215
  return [
228
216
  4,
229
217
  hookRunners.beforeDev()
230
218
  ];
231
- case 3:
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 4:
228
+ case 3:
241
229
  _state.sent();
242
230
  return [
243
231
  4,
244
232
  getServerInternalPlugins(api)
245
233
  ];
246
- case 5:
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
- 7
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 6:
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
- 9
276
+ 8
289
277
  ];
290
- case 7:
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 8:
286
+ case 7:
299
287
  server = _state.sent().server;
300
288
  setServer(server);
301
- _state.label = 9;
302
- case 9:
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"
@@ -7,7 +7,9 @@ var ZH_LOCALE = {
7
7
  dev: {
8
8
  describe: "本地开发命令",
9
9
  entry: "指定入口,编译特定的页面",
10
- apiOnly: "仅启动 API 接口服务"
10
+ apiOnly: "仅启动 API 接口服务",
11
+ selectEntry: "请选择需要构建的入口",
12
+ requireEntry: "请至少选择一个入口"
11
13
  },
12
14
  build: {
13
15
  describe: "构建应用命令"
@@ -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 { isDev, chokidar, createDebugger, isTest, getServerConfig } from "@modern-js/utils";
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
- var debug = createDebugger("watch-files");
185
- var md5 = function(data) {
186
- return crypto.createHash("md5").update(data).digest("hex");
187
- };
188
- var hashMap = /* @__PURE__ */ new Map();
189
- var createFileWatcher = function() {
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
- return [
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 2:
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
- watcher
271
- ];
272
- case 3:
273
- return [
274
- 2
204
+ [
205
+ "".concat(configPath, "/html"),
206
+ configFile || "./config"
207
+ ].concat(_toConsumableArray(dependencies))
275
208
  ];
276
209
  }
277
210
  });
278
211
  });
279
- return function createFileWatcher(appContext, configDir, hooksRunner) {
280
- return _ref.apply(this, arguments);
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
- var getSpecifiedEntries = function() {
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 "You must choose at least one topping.";
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("can not found entry ".concat(name, ", compiler entry should in ").concat(entryNames.join(", ")));
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 getSpecifiedEntries(entry, entrypoints) {
182
+ return function getSelectedEntries(entry, entrypoints) {
182
183
  return _ref.apply(this, arguments);
183
184
  };
184
185
  }();
185
- export { getSpecifiedEntries };
186
+ export { getSelectedEntries };
@@ -8,6 +8,8 @@ export declare const EN_LOCALE: {
8
8
  describe: string;
9
9
  entry: string;
10
10
  apiOnly: string;
11
+ selectEntry: string;
12
+ requireEntry: string;
11
13
  };
12
14
  build: {
13
15
  describe: string;
@@ -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;
@@ -8,6 +8,8 @@ export declare const ZH_LOCALE: {
8
8
  describe: string;
9
9
  entry: string;
10
10
  apiOnly: string;
11
+ selectEntry: string;
12
+ requireEntry: string;
11
13
  };
12
14
  build: {
13
15
  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[]>;
@@ -0,0 +1,6 @@
1
+ import { Entrypoint } from '@modern-js/types';
2
+ /**
3
+ * Allow user to select entrypoints to build.
4
+ */
5
+
6
+ export declare const getSelectedEntries: (entry: string[] | boolean, entrypoints: Entrypoint[]) => Promise<string[]>;