@modern-js/app-tools 2.62.0 → 2.62.1-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. package/bin/modern.js +2 -2
  2. package/dist/cjs/index.js +4 -142
  3. package/dist/cjs/new/compat/hooks.js +160 -0
  4. package/dist/cjs/new/compat/index.js +52 -0
  5. package/dist/cjs/new/compat/utils.js +95 -0
  6. package/dist/cjs/new/constants.js +37 -0
  7. package/dist/cjs/new/context.js +63 -0
  8. package/dist/cjs/new/getConfigFile.js +41 -0
  9. package/dist/cjs/new/index.js +76 -0
  10. package/dist/cjs/new/loadPlugins.js +57 -0
  11. package/dist/cjs/new/run.js +66 -0
  12. package/dist/cjs/new/types/index.js +16 -0
  13. package/dist/cjs/new/utils/index.js +34 -0
  14. package/dist/cjs/old.js +179 -0
  15. package/dist/esm/index.js +2 -248
  16. package/dist/esm/new/compat/hooks.js +418 -0
  17. package/dist/esm/new/compat/index.js +30 -0
  18. package/dist/esm/new/compat/utils.js +69 -0
  19. package/dist/esm/new/constants.js +10 -0
  20. package/dist/esm/new/context.js +30 -0
  21. package/dist/esm/new/getConfigFile.js +11 -0
  22. package/dist/esm/new/index.js +52 -0
  23. package/dist/esm/new/loadPlugins.js +94 -0
  24. package/dist/esm/new/run.js +79 -0
  25. package/dist/esm/new/types/index.js +0 -0
  26. package/dist/esm/new/utils/index.js +33 -0
  27. package/dist/esm/old.js +258 -0
  28. package/dist/esm-node/index.js +2 -130
  29. package/dist/esm-node/new/compat/hooks.js +135 -0
  30. package/dist/esm-node/new/compat/index.js +28 -0
  31. package/dist/esm-node/new/compat/utils.js +69 -0
  32. package/dist/esm-node/new/constants.js +10 -0
  33. package/dist/esm-node/new/context.js +29 -0
  34. package/dist/esm-node/new/getConfigFile.js +7 -0
  35. package/dist/esm-node/new/index.js +49 -0
  36. package/dist/esm-node/new/loadPlugins.js +33 -0
  37. package/dist/esm-node/new/run.js +42 -0
  38. package/dist/esm-node/new/types/index.js +0 -0
  39. package/dist/esm-node/new/utils/index.js +10 -0
  40. package/dist/esm-node/old.js +140 -0
  41. package/dist/types/index.d.ts +2 -6
  42. package/dist/types/new/compat/hooks.d.ts +8 -0
  43. package/dist/types/new/compat/index.d.ts +4 -0
  44. package/dist/types/new/compat/utils.d.ts +6 -0
  45. package/dist/types/new/constants.d.ts +4 -0
  46. package/dist/types/new/context.d.ts +32 -0
  47. package/dist/types/new/getConfigFile.d.ts +1 -0
  48. package/dist/types/new/index.d.ts +15 -0
  49. package/dist/types/new/loadPlugins.d.ts +9 -0
  50. package/dist/types/new/run.d.ts +14 -0
  51. package/dist/types/new/types/index.d.ts +89 -0
  52. package/dist/types/new/utils/index.d.ts +1 -0
  53. package/dist/types/old.d.ts +20 -0
  54. package/package.json +16 -8
@@ -0,0 +1,69 @@
1
+ function transformHookRunner(hookRunnerName) {
2
+ switch (hookRunnerName) {
3
+ case "beforeConfig":
4
+ return "onBeforeConfig";
5
+ case "prepare":
6
+ return "onPrepare";
7
+ case "afterPrepare":
8
+ return "onAfterPrepare";
9
+ case "beforeGenerateRoutes":
10
+ return "onBeforeGenerateRoutes";
11
+ case "beforePrintInstructions":
12
+ return "onBeforePrintInstructions";
13
+ case "resolvedConfig":
14
+ return "modifyResolvedConfig";
15
+ case "commands":
16
+ return "addCommand";
17
+ case "watchFiles":
18
+ return "addWatchFiles";
19
+ case "filedChange":
20
+ return "onFileChanged";
21
+ case "beforeCreateCompiler":
22
+ return "onBeforeCreateCompiler";
23
+ case "afterCreateCompiler":
24
+ return "onAfterCreateCompiler";
25
+ case "beforeBuild":
26
+ return "onBeforeBuild";
27
+ case "afterBuild":
28
+ return "onAfterBuild";
29
+ case "beforeDev":
30
+ return "onBeforeDev";
31
+ case "afterDev":
32
+ return "onAfterDev";
33
+ case "beforeDeploy":
34
+ return "onBeforeDeploy";
35
+ case "afterDeploy":
36
+ return "onAfterDeploy";
37
+ case "beforeExit":
38
+ return "onBeforeExit";
39
+ case "beforeRestart":
40
+ return "onBeforeRestart";
41
+ case "htmlPartials":
42
+ return "modifyHtmlPartials";
43
+ default:
44
+ return hookRunnerName;
45
+ }
46
+ }
47
+ function transformHookParams(hookRunnerName, params) {
48
+ switch (hookRunnerName) {
49
+ case "resolvedConfig":
50
+ return {
51
+ resolved: params
52
+ };
53
+ default:
54
+ return params;
55
+ }
56
+ }
57
+ function transformHookResult(hookRunnerName, result) {
58
+ switch (hookRunnerName) {
59
+ case "resolvedConfig":
60
+ return result.resolved;
61
+ default:
62
+ return result;
63
+ }
64
+ }
65
+ export {
66
+ transformHookParams,
67
+ transformHookResult,
68
+ transformHookRunner
69
+ };
@@ -0,0 +1,10 @@
1
+ var PACKAGE_JSON_CONFIG_NAME = "modernConfig";
2
+ var DEFAULT_CONFIG_FILE = "modern.config";
3
+ var DEFAULT_SERVER_CONFIG_FILE = "modern.server-runtime.config";
4
+ var DEFAULT_RUNTIME_CONFIG_FILE = "modern.runtime";
5
+ export {
6
+ DEFAULT_CONFIG_FILE,
7
+ DEFAULT_RUNTIME_CONFIG_FILE,
8
+ DEFAULT_SERVER_CONFIG_FILE,
9
+ PACKAGE_JSON_CONFIG_NAME
10
+ };
@@ -0,0 +1,30 @@
1
+ import path from "path";
2
+ import { address } from "@modern-js/utils";
3
+ var initAppContext = function(param) {
4
+ var appDirectory = param.appDirectory, runtimeConfigFile = param.runtimeConfigFile, options = param.options, serverConfigFile = param.serverConfigFile;
5
+ var _ref = options || {}, _ref_metaName = _ref.metaName, metaName = _ref_metaName === void 0 ? "modern-js" : _ref_metaName, _ref_apiDir = _ref.apiDir, apiDir = _ref_apiDir === void 0 ? "api" : _ref_apiDir, _ref_distDir = _ref.distDir, distDir = _ref_distDir === void 0 ? "" : _ref_distDir, _ref_sharedDir = _ref.sharedDir, sharedDir = _ref_sharedDir === void 0 ? "shared" : _ref_sharedDir;
6
+ return {
7
+ metaName,
8
+ runtimeConfigFile,
9
+ serverConfigFile,
10
+ ip: address.ip(),
11
+ port: 0,
12
+ moduleType: require(path.resolve(appDirectory, "./package.json")).type || "commonjs",
13
+ apiDirectory: path.resolve(appDirectory, apiDir),
14
+ lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
15
+ sharedDirectory: path.resolve(appDirectory, sharedDir),
16
+ distDirectory: distDir,
17
+ serverPlugins: [],
18
+ internalDirectory: path.resolve(appDirectory, "./node_modules/.".concat(metaName)),
19
+ htmlTemplates: {},
20
+ serverRoutes: [],
21
+ entrypoints: [],
22
+ checkedEntries: [],
23
+ apiOnly: false,
24
+ internalDirAlias: "@_".concat(metaName.replace(/-/g, "_"), "_internal"),
25
+ internalSrcAlias: "@_".concat(metaName.replace(/-/g, "_"), "_src")
26
+ };
27
+ };
28
+ export {
29
+ initAppContext
30
+ };
@@ -0,0 +1,11 @@
1
+ import path from "path";
2
+ import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
3
+ import { DEFAULT_CONFIG_FILE } from "./constants";
4
+ var getConfigFile = function(configFile) {
5
+ return findExists(CONFIG_FILE_EXTENSIONS.map(function(extension) {
6
+ return path.resolve(process.cwd(), "".concat(configFile || DEFAULT_CONFIG_FILE).concat(extension));
7
+ }));
8
+ };
9
+ export {
10
+ getConfigFile
11
+ };
@@ -0,0 +1,52 @@
1
+ import { createAsyncHook } from "@modern-js/plugin-v2";
2
+ import { appTools as oldAppTools } from "../old";
3
+ import { compatPlugin } from "./compat";
4
+ import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
5
+ import { initAppContext } from "./context";
6
+ export * from "../defineConfig";
7
+ var appTools = function() {
8
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
9
+ // default webpack to be compatible with original projects
10
+ bundler: "webpack"
11
+ };
12
+ return {
13
+ name: "@modern-js/app-tools",
14
+ usePlugins: [
15
+ compatPlugin(),
16
+ oldAppTools(options)
17
+ ],
18
+ post: [
19
+ "@modern-js/app-tools-old"
20
+ ],
21
+ registryHooks: {
22
+ onBeforeConfig: createAsyncHook(),
23
+ onAfterPrepare: createAsyncHook(),
24
+ deploy: createAsyncHook(),
25
+ _internalRuntimePlugins: createAsyncHook(),
26
+ _internalServerPlugins: createAsyncHook(),
27
+ checkEntryPoint: createAsyncHook(),
28
+ modifyEntrypoints: createAsyncHook(),
29
+ modifyFileSystemRoutes: createAsyncHook(),
30
+ modifyServerRoutes: createAsyncHook(),
31
+ generateEntryCode: createAsyncHook(),
32
+ onBeforeGenerateRoutes: createAsyncHook(),
33
+ onBeforePrintInstructions: createAsyncHook(),
34
+ registerDev: createAsyncHook(),
35
+ registerBuildPlatform: createAsyncHook(),
36
+ addRuntimeExports: createAsyncHook()
37
+ },
38
+ setup: function(api) {
39
+ var context = api.getAppContext();
40
+ api.updateAppContext(initAppContext({
41
+ appDirectory: context.appDirectory,
42
+ options: {},
43
+ serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
44
+ runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE
45
+ }));
46
+ }
47
+ };
48
+ };
49
+ export {
50
+ appTools,
51
+ initAppContext
52
+ };
@@ -0,0 +1,94 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
+ import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
5
+ var debug = createDebugger("load-plugins");
6
+ var resolveCliPlugin = function() {
7
+ var _ref = _async_to_generator(function(p, appDirectory) {
8
+ var pkg, pluginOptions, path, module, e, ref, result;
9
+ return _ts_generator(this, function(_state) {
10
+ switch (_state.label) {
11
+ case 0:
12
+ pkg = typeof p === "string" ? p : p[0];
13
+ pluginOptions = typeof p === "string" ? void 0 : p[1];
14
+ path = tryResolve(pkg, appDirectory);
15
+ _state.label = 1;
16
+ case 1:
17
+ _state.trys.push([
18
+ 1,
19
+ 3,
20
+ ,
21
+ 5
22
+ ]);
23
+ return [
24
+ 4,
25
+ compatibleRequire(path)
26
+ ];
27
+ case 2:
28
+ module = _state.sent();
29
+ return [
30
+ 3,
31
+ 5
32
+ ];
33
+ case 3:
34
+ e = _state.sent();
35
+ return [
36
+ 4,
37
+ dynamicImport(path)
38
+ ];
39
+ case 4:
40
+ ref = _state.sent(), module = ref.default, ref;
41
+ return [
42
+ 3,
43
+ 5
44
+ ];
45
+ case 5:
46
+ if (typeof module === "function") {
47
+ result = module(pluginOptions);
48
+ return [
49
+ 2,
50
+ result
51
+ ];
52
+ }
53
+ return [
54
+ 2,
55
+ module
56
+ ];
57
+ }
58
+ });
59
+ });
60
+ return function resolveCliPlugin2(p, appDirectory) {
61
+ return _ref.apply(this, arguments);
62
+ };
63
+ }();
64
+ var loadInternalPlugins = function() {
65
+ var _ref = _async_to_generator(function(appDirectory, internalPlugins, autoLoad, autoLoadPlugins, forceAutoLoadPlugins) {
66
+ var plugins, loadedPlugins;
67
+ return _ts_generator(this, function(_state) {
68
+ switch (_state.label) {
69
+ case 0:
70
+ plugins = _to_consumable_array(forceAutoLoadPlugins || autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : []).concat(_to_consumable_array(autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []));
71
+ return [
72
+ 4,
73
+ Promise.all(plugins.map(function(plugin) {
74
+ var loadedPlugin = resolveCliPlugin(plugin, appDirectory);
75
+ debug("resolve plugin %s: %s", plugin, loadedPlugin);
76
+ return loadedPlugin;
77
+ }))
78
+ ];
79
+ case 1:
80
+ loadedPlugins = _state.sent();
81
+ return [
82
+ 2,
83
+ loadedPlugins
84
+ ];
85
+ }
86
+ });
87
+ });
88
+ return function loadInternalPlugins2(appDirectory, internalPlugins, autoLoad, autoLoadPlugins, forceAutoLoadPlugins) {
89
+ return _ref.apply(this, arguments);
90
+ };
91
+ }();
92
+ export {
93
+ loadInternalPlugins
94
+ };
@@ -0,0 +1,79 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { initAppDir } from "@modern-js/plugin-v2/cli";
4
+ import { run as CLIPluginRun } from "@modern-js/plugin-v2/run";
5
+ import { minimist } from "@modern-js/utils";
6
+ import { handleSetupResult } from "./compat/hooks";
7
+ import { PACKAGE_JSON_CONFIG_NAME } from "./constants";
8
+ import { getConfigFile } from "./getConfigFile";
9
+ import { loadInternalPlugins } from "./loadPlugins";
10
+ import { getIsAutoLoadPlugins } from "./utils";
11
+ function run(_) {
12
+ return _run.apply(this, arguments);
13
+ }
14
+ function _run() {
15
+ _run = _async_to_generator(function(param) {
16
+ var cwd, initialLog, version, internalPlugins, forceAutoLoadPlugins, packageJsonConfig, configFile, command, cliParams, SUPPORT_CONFIG_PARAM_COMMANDS, customConfigFile, appDirectory, autoLoadPlugins, plugins;
17
+ return _ts_generator(this, function(_state) {
18
+ switch (_state.label) {
19
+ case 0:
20
+ cwd = param.cwd, initialLog = param.initialLog, version = param.version, internalPlugins = param.internalPlugins, forceAutoLoadPlugins = param.forceAutoLoadPlugins, packageJsonConfig = param.packageJsonConfig, configFile = param.configFile;
21
+ command = process.argv[2];
22
+ cliParams = minimist(process.argv.slice(2));
23
+ SUPPORT_CONFIG_PARAM_COMMANDS = [
24
+ "dev",
25
+ "build",
26
+ "deploy",
27
+ "start",
28
+ "serve",
29
+ "inspect",
30
+ "upgrade"
31
+ ];
32
+ if (SUPPORT_CONFIG_PARAM_COMMANDS.includes(command)) {
33
+ customConfigFile = cliParams.config || cliParams.c;
34
+ }
35
+ if (command === "new") {
36
+ customConfigFile = cliParams["config-file"];
37
+ }
38
+ return [
39
+ 4,
40
+ initAppDir(cwd)
41
+ ];
42
+ case 1:
43
+ appDirectory = _state.sent();
44
+ return [
45
+ 4,
46
+ getIsAutoLoadPlugins(appDirectory, customConfigFile || getConfigFile(configFile))
47
+ ];
48
+ case 2:
49
+ autoLoadPlugins = _state.sent();
50
+ return [
51
+ 4,
52
+ loadInternalPlugins(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins, forceAutoLoadPlugins)
53
+ ];
54
+ case 3:
55
+ plugins = _state.sent();
56
+ return [
57
+ 4,
58
+ CLIPluginRun({
59
+ cwd,
60
+ initialLog: initialLog || "Modern.js Framework v".concat(version),
61
+ configFile: customConfigFile || getConfigFile(configFile),
62
+ packageJsonConfig: packageJsonConfig || PACKAGE_JSON_CONFIG_NAME,
63
+ internalPlugins: plugins,
64
+ handleSetupResult
65
+ })
66
+ ];
67
+ case 4:
68
+ _state.sent();
69
+ return [
70
+ 2
71
+ ];
72
+ }
73
+ });
74
+ });
75
+ return _run.apply(this, arguments);
76
+ }
77
+ export {
78
+ run
79
+ };
File without changes
@@ -0,0 +1,33 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
4
+ function getIsAutoLoadPlugins(appDirectory) {
5
+ return _getIsAutoLoadPlugins.apply(this, arguments);
6
+ }
7
+ function _getIsAutoLoadPlugins() {
8
+ _getIsAutoLoadPlugins = _async_to_generator(function(appDirectory) {
9
+ var configFile, packageJsonConfig, _loaded_config, loaded, autoLoadPlugins;
10
+ var _arguments = arguments;
11
+ return _ts_generator(this, function(_state) {
12
+ switch (_state.label) {
13
+ case 0:
14
+ configFile = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : "modern.config.ts", packageJsonConfig = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : "ModernConfig";
15
+ return [
16
+ 4,
17
+ createLoadedConfig(appDirectory, configFile, packageJsonConfig)
18
+ ];
19
+ case 1:
20
+ loaded = _state.sent();
21
+ autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
22
+ return [
23
+ 2,
24
+ autoLoadPlugins || false
25
+ ];
26
+ }
27
+ });
28
+ });
29
+ return _getIsAutoLoadPlugins.apply(this, arguments);
30
+ }
31
+ export {
32
+ getIsAutoLoadPlugins
33
+ };
@@ -0,0 +1,258 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
6
+ import path from "path";
7
+ import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
8
+ import { castArray } from "@modern-js/uni-builder";
9
+ import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
10
+ import { hooks } from "./hooks";
11
+ import { i18n } from "./locale";
12
+ import analyzePlugin from "./plugins/analyze";
13
+ import deployPlugin from "./plugins/deploy";
14
+ import initializePlugin from "./plugins/initialize";
15
+ import serverBuildPlugin from "./plugins/serverBuild";
16
+ import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
17
+ import { generateWatchFiles } from "./utils/generateWatchFiles";
18
+ import { restart } from "./utils/restart";
19
+ import { dev } from "./commands/dev";
20
+ import { mergeConfig } from "@modern-js/core";
21
+ export * from "./defineConfig";
22
+ export * from "./types";
23
+ var appTools = function() {
24
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
25
+ // default webpack to be compatible with original projects
26
+ bundler: "webpack"
27
+ };
28
+ return {
29
+ name: "@modern-js/app-tools-old",
30
+ post: [
31
+ "@modern-js/plugin-initialize",
32
+ "@modern-js/plugin-analyze",
33
+ "@modern-js/plugin-ssr",
34
+ "@modern-js/plugin-document",
35
+ "@modern-js/plugin-state",
36
+ "@modern-js/plugin-router",
37
+ "@modern-js/plugin-router-v5",
38
+ "@modern-js/plugin-polyfill"
39
+ ],
40
+ registerHook: hooks,
41
+ usePlugins: [
42
+ initializePlugin({
43
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
44
+ "rspack",
45
+ "experimental-rspack"
46
+ ].includes(options.bundler) ? "rspack" : "webpack"
47
+ }),
48
+ analyzePlugin({
49
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
50
+ "rspack",
51
+ "experimental-rspack"
52
+ ].includes(options.bundler) ? "rspack" : "webpack"
53
+ }),
54
+ serverBuildPlugin(),
55
+ deployPlugin()
56
+ ],
57
+ setup: function(api) {
58
+ var appContext = api.useAppContext();
59
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
60
+ toolsType: "app-tools"
61
+ }));
62
+ var locale = getLocaleLanguage();
63
+ i18n.changeLanguage({
64
+ locale
65
+ });
66
+ return {
67
+ beforeConfig: function beforeConfig() {
68
+ return _async_to_generator(function() {
69
+ var _userConfig_output, userConfig, appContext2;
70
+ return _ts_generator(this, function(_state) {
71
+ userConfig = api.useConfigContext();
72
+ appContext2 = api.useAppContext();
73
+ if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
74
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext2), {
75
+ internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
76
+ }));
77
+ }
78
+ return [
79
+ 2
80
+ ];
81
+ });
82
+ })();
83
+ },
84
+ commands: function commands(param) {
85
+ var program = param.program;
86
+ return _async_to_generator(function() {
87
+ return _ts_generator(this, function(_state) {
88
+ switch (_state.label) {
89
+ case 0:
90
+ return [
91
+ 4,
92
+ devCommand(program, api)
93
+ ];
94
+ case 1:
95
+ _state.sent();
96
+ return [
97
+ 4,
98
+ buildCommand(program, api)
99
+ ];
100
+ case 2:
101
+ _state.sent();
102
+ serverCommand(program, api);
103
+ deployCommand(program, api);
104
+ newCommand(program, locale);
105
+ inspectCommand(program, api);
106
+ upgradeCommand(program);
107
+ deprecatedCommands(program);
108
+ return [
109
+ 2
110
+ ];
111
+ }
112
+ });
113
+ })();
114
+ },
115
+ prepare: function prepare() {
116
+ return _async_to_generator(function() {
117
+ var command, isSkipBuild, resolvedConfig, appContext2;
118
+ return _ts_generator(this, function(_state) {
119
+ switch (_state.label) {
120
+ case 0:
121
+ command = getCommand();
122
+ if (command === "deploy") {
123
+ isSkipBuild = [
124
+ "-s",
125
+ "--skip-build"
126
+ ].some(function(tag) {
127
+ return getArgv().includes(tag);
128
+ });
129
+ if (isSkipBuild) {
130
+ return [
131
+ 2
132
+ ];
133
+ }
134
+ }
135
+ if (!(command === "dev" || command === "start" || command === "build" || command === "deploy"))
136
+ return [
137
+ 3,
138
+ 2
139
+ ];
140
+ resolvedConfig = api.useResolvedConfigContext();
141
+ if (!resolvedConfig.output.cleanDistPath)
142
+ return [
143
+ 3,
144
+ 2
145
+ ];
146
+ appContext2 = api.useAppContext();
147
+ return [
148
+ 4,
149
+ emptyDir(appContext2.distDirectory)
150
+ ];
151
+ case 1:
152
+ _state.sent();
153
+ _state.label = 2;
154
+ case 2:
155
+ return [
156
+ 2
157
+ ];
158
+ }
159
+ });
160
+ })();
161
+ },
162
+ watchFiles: function watchFiles() {
163
+ return _async_to_generator(function() {
164
+ var appContext2, config, files, watchFiles2;
165
+ return _ts_generator(this, function(_state) {
166
+ switch (_state.label) {
167
+ case 0:
168
+ appContext2 = api.useAppContext();
169
+ config = api.useResolvedConfigContext();
170
+ return [
171
+ 4,
172
+ generateWatchFiles(appContext2, config.source.configDir)
173
+ ];
174
+ case 1:
175
+ files = _state.sent();
176
+ watchFiles2 = castArray(config.dev.watchFiles);
177
+ watchFiles2.forEach(function(param) {
178
+ var type = param.type, paths = param.paths;
179
+ if (type === "reload-server") {
180
+ var _files;
181
+ (_files = files).push.apply(_files, _to_consumable_array(Array.isArray(paths) ? paths : [
182
+ paths
183
+ ]));
184
+ }
185
+ });
186
+ return [
187
+ 2,
188
+ files
189
+ ];
190
+ }
191
+ });
192
+ })();
193
+ },
194
+ fileChange: (
195
+ // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
196
+ function fileChange(e) {
197
+ return _async_to_generator(function() {
198
+ var filename, eventType, isPrivate, closeServer;
199
+ return _ts_generator(this, function(_state) {
200
+ switch (_state.label) {
201
+ case 0:
202
+ filename = e.filename, eventType = e.eventType, isPrivate = e.isPrivate;
203
+ if (!(!isPrivate && (eventType === "change" || eventType === "unlink")))
204
+ return [
205
+ 3,
206
+ 4
207
+ ];
208
+ return [
209
+ 4,
210
+ import("./utils/createServer.js")
211
+ ];
212
+ case 1:
213
+ closeServer = _state.sent().closeServer;
214
+ return [
215
+ 4,
216
+ closeServer()
217
+ ];
218
+ case 2:
219
+ _state.sent();
220
+ return [
221
+ 4,
222
+ restart(api.useHookRunners(), filename)
223
+ ];
224
+ case 3:
225
+ _state.sent();
226
+ _state.label = 4;
227
+ case 4:
228
+ return [
229
+ 2
230
+ ];
231
+ }
232
+ });
233
+ })();
234
+ }
235
+ ),
236
+ beforeRestart: function beforeRestart() {
237
+ return _async_to_generator(function() {
238
+ return _ts_generator(this, function(_state) {
239
+ cleanRequireCache([
240
+ require.resolve("./plugins/analyze")
241
+ ]);
242
+ return [
243
+ 2
244
+ ];
245
+ });
246
+ })();
247
+ }
248
+ };
249
+ }
250
+ };
251
+ };
252
+ var old_default = appTools;
253
+ export {
254
+ appTools,
255
+ old_default as default,
256
+ dev,
257
+ mergeConfig
258
+ };