@umijs/preset-umi 4.0.0-beta.10

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 (113) hide show
  1. package/README.md +3 -0
  2. package/assets/umi.png +0 -0
  3. package/compiled/body-parser/LICENSE +23 -0
  4. package/compiled/body-parser/connect/index.d.ts +93 -0
  5. package/compiled/body-parser/index.d.ts +107 -0
  6. package/compiled/body-parser/index.js +129 -0
  7. package/compiled/body-parser/package.json +1 -0
  8. package/compiled/multer/LICENSE +17 -0
  9. package/compiled/multer/body-parser/index.d.ts +104 -0
  10. package/compiled/multer/connect/index.d.ts +93 -0
  11. package/compiled/multer/express/index.d.ts +133 -0
  12. package/compiled/multer/express-serve-static-core/index.d.ts +1252 -0
  13. package/compiled/multer/index.d.ts +321 -0
  14. package/compiled/multer/index.js +41 -0
  15. package/compiled/multer/mime/index.d.ts +35 -0
  16. package/compiled/multer/package.json +1 -0
  17. package/compiled/multer/qs/index.d.ts +62 -0
  18. package/compiled/multer/range-parser/index.d.ts +35 -0
  19. package/compiled/multer/serve-static/index.d.ts +108 -0
  20. package/dist/commands/build.d.ts +3 -0
  21. package/dist/commands/build.js +120 -0
  22. package/dist/commands/config/config.d.ts +3 -0
  23. package/dist/commands/config/config.js +61 -0
  24. package/dist/commands/config/list.d.ts +2 -0
  25. package/dist/commands/config/list.js +34 -0
  26. package/dist/commands/config/remove.d.ts +1 -0
  27. package/dist/commands/config/remove.js +21 -0
  28. package/dist/commands/config/set.d.ts +1 -0
  29. package/dist/commands/config/set.js +21 -0
  30. package/dist/commands/dev/createRouteMiddleware.d.ts +5 -0
  31. package/dist/commands/dev/createRouteMiddleware.js +35 -0
  32. package/dist/commands/dev/dev.d.ts +3 -0
  33. package/dist/commands/dev/dev.js +269 -0
  34. package/dist/commands/dev/faviconMiddleware.d.ts +2 -0
  35. package/dist/commands/dev/faviconMiddleware.js +13 -0
  36. package/dist/commands/dev/getBabelOpts.d.ts +20 -0
  37. package/dist/commands/dev/getBabelOpts.js +57 -0
  38. package/dist/commands/dev/getMarkupArgs.d.ts +13 -0
  39. package/dist/commands/dev/getMarkupArgs.js +73 -0
  40. package/dist/commands/dev/watch.d.ts +19 -0
  41. package/dist/commands/dev/watch.js +55 -0
  42. package/dist/commands/generate/page.d.ts +3 -0
  43. package/dist/commands/generate/page.js +44 -0
  44. package/dist/commands/generate/prettier.d.ts +3 -0
  45. package/dist/commands/generate/prettier.js +31 -0
  46. package/dist/commands/help.d.ts +3 -0
  47. package/dist/commands/help.js +61 -0
  48. package/dist/commands/plugin.d.ts +3 -0
  49. package/dist/commands/plugin.js +38 -0
  50. package/dist/commands/setup.d.ts +3 -0
  51. package/dist/commands/setup.js +20 -0
  52. package/dist/commands/version.d.ts +3 -0
  53. package/dist/commands/version.js +16 -0
  54. package/dist/constants.d.ts +4 -0
  55. package/dist/constants.js +8 -0
  56. package/dist/features/__sample.d.ts +3 -0
  57. package/dist/features/__sample.js +5 -0
  58. package/dist/features/appData/appData.d.ts +3 -0
  59. package/dist/features/appData/appData.js +30 -0
  60. package/dist/features/check/check.d.ts +3 -0
  61. package/dist/features/check/check.js +34 -0
  62. package/dist/features/configPlugins/configPlugins.d.ts +3 -0
  63. package/dist/features/configPlugins/configPlugins.js +61 -0
  64. package/dist/features/configPlugins/schema.d.ts +2 -0
  65. package/dist/features/configPlugins/schema.js +16 -0
  66. package/dist/features/esmi/esmi.d.ts +3 -0
  67. package/dist/features/esmi/esmi.js +44 -0
  68. package/dist/features/favicon/favicon.d.ts +3 -0
  69. package/dist/features/favicon/favicon.js +58 -0
  70. package/dist/features/lowImport/babelPlugin.d.ts +17 -0
  71. package/dist/features/lowImport/babelPlugin.js +68 -0
  72. package/dist/features/lowImport/lowImport.d.ts +9 -0
  73. package/dist/features/lowImport/lowImport.js +108 -0
  74. package/dist/features/mock/constants.d.ts +3 -0
  75. package/dist/features/mock/constants.js +14 -0
  76. package/dist/features/mock/createMockMiddleware.d.ts +7 -0
  77. package/dist/features/mock/createMockMiddleware.js +82 -0
  78. package/dist/features/mock/getMockData.d.ts +9 -0
  79. package/dist/features/mock/getMockData.js +61 -0
  80. package/dist/features/mock/mock.d.ts +2 -0
  81. package/dist/features/mock/mock.js +50 -0
  82. package/dist/features/polyfill/polyfill.d.ts +3 -0
  83. package/dist/features/polyfill/polyfill.js +14 -0
  84. package/dist/features/tmpFiles/importsToStr.d.ts +4 -0
  85. package/dist/features/tmpFiles/importsToStr.js +16 -0
  86. package/dist/features/tmpFiles/routes.d.ts +8 -0
  87. package/dist/features/tmpFiles/routes.js +74 -0
  88. package/dist/features/tmpFiles/tmpFiles.d.ts +3 -0
  89. package/dist/features/tmpFiles/tmpFiles.js +124 -0
  90. package/dist/features/transform/babelPlugin.d.ts +11 -0
  91. package/dist/features/transform/babelPlugin.js +118 -0
  92. package/dist/features/transform/transform.d.ts +3 -0
  93. package/dist/features/transform/transform.js +29 -0
  94. package/dist/index.d.ts +5 -0
  95. package/dist/index.js +30 -0
  96. package/dist/libs/moduleGraph.d.ts +2 -0
  97. package/dist/libs/moduleGraph.js +6 -0
  98. package/dist/libs/scan.d.ts +28 -0
  99. package/dist/libs/scan.js +110 -0
  100. package/dist/registerMethods.d.ts +3 -0
  101. package/dist/registerMethods.js +89 -0
  102. package/dist/types.d.ts +147 -0
  103. package/dist/types.js +2 -0
  104. package/dist/utils/clearTmp.d.ts +1 -0
  105. package/dist/utils/clearTmp.js +17 -0
  106. package/dist/utils/isTypeScriptFile.d.ts +1 -0
  107. package/dist/utils/isTypeScriptFile.js +7 -0
  108. package/package.json +62 -0
  109. package/templates/generate/page/index.less.tpl +4 -0
  110. package/templates/generate/page/index.tsx.tpl +10 -0
  111. package/templates/plugin.tpl +18 -0
  112. package/templates/route.tpl +7 -0
  113. package/templates/umi.tpl +22 -0
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ const utils_1 = require("@umijs/utils");
32
+ const fs_1 = require("fs");
33
+ const path_1 = require("path");
34
+ const process = __importStar(require("process"));
35
+ const constants_1 = require("../../constants");
36
+ const clearTmp_1 = require("../../utils/clearTmp");
37
+ const createRouteMiddleware_1 = require("./createRouteMiddleware");
38
+ const faviconMiddleware_1 = require("./faviconMiddleware");
39
+ const getBabelOpts_1 = require("./getBabelOpts");
40
+ const watch_1 = require("./watch");
41
+ const bundlerWebpack = (0, utils_1.importLazy)('@umijs/bundler-webpack');
42
+ const bundlerVite = (0, utils_1.importLazy)('@umijs/bundler-vite');
43
+ exports.default = (api) => {
44
+ api.describe({
45
+ enableBy() {
46
+ return api.name === 'dev';
47
+ },
48
+ });
49
+ api.registerCommand({
50
+ name: 'dev',
51
+ description: 'dev server for development',
52
+ details: `
53
+ umi dev
54
+
55
+ # dev with specified port
56
+ PORT=8888 umi dev
57
+ `,
58
+ fn() {
59
+ var _a;
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const enableVite = api.args.vite;
62
+ // clear tmp except cache
63
+ (0, clearTmp_1.clearTmp)(api.paths.absTmpPath);
64
+ // check package.json
65
+ yield api.applyPlugins({
66
+ key: 'onCheckPkgJSON',
67
+ args: {
68
+ origin: null,
69
+ current: api.appData.pkg,
70
+ },
71
+ });
72
+ // clean cache if umi version not matched
73
+ // const umiJSONPath = join(api.paths.absTmpPath, 'umi.json');
74
+ // if (existsSync(umiJSONPath)) {
75
+ // const originVersion = require(umiJSONPath).version;
76
+ // if (originVersion !== api.appData.umi.version) {
77
+ // logger.info(`Delete cache folder since umi version updated.`);
78
+ // rimraf.sync(api.paths.absTmpPath);
79
+ // }
80
+ // }
81
+ // fsExtra.outputFileSync(
82
+ // umiJSONPath,
83
+ // JSON.stringify({ version: api.appData.umi.version }),
84
+ // );
85
+ // generate files
86
+ function generate(opts) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ yield api.applyPlugins({
89
+ key: 'onGenerateFiles',
90
+ args: {
91
+ files: opts.files || null,
92
+ isFirstTime: opts.isFirstTime,
93
+ },
94
+ });
95
+ });
96
+ }
97
+ yield generate({
98
+ isFirstTime: true,
99
+ });
100
+ const { absPagesPath, absSrcPath } = api.paths;
101
+ const watcherPaths = yield api.applyPlugins({
102
+ key: 'addTmpGenerateWatcherPaths',
103
+ initialValue: [
104
+ absPagesPath,
105
+ (0, path_1.join)(absSrcPath, 'layouts'),
106
+ ...(0, watch_1.expandJSPaths)((0, path_1.join)(absSrcPath, 'app')),
107
+ ],
108
+ });
109
+ utils_1.lodash.uniq(watcherPaths.map(utils_1.winPath)).forEach((p) => {
110
+ (0, watch_1.watch)({
111
+ path: p,
112
+ addToUnWatches: true,
113
+ onChange: (0, watch_1.createDebouncedHandler)({
114
+ timeout: 2000,
115
+ onChange(opts) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ yield generate({ files: opts.files, isFirstTime: false });
118
+ });
119
+ },
120
+ }),
121
+ });
122
+ });
123
+ // watch package.json change
124
+ const pkgPath = (0, path_1.join)(api.cwd, 'package.json');
125
+ (0, watch_1.watch)({
126
+ path: pkgPath,
127
+ addToUnWatches: true,
128
+ onChange() {
129
+ const origin = api.appData.pkg;
130
+ api.appData.pkg = JSON.parse((0, fs_1.readFileSync)(pkgPath, 'utf-8'));
131
+ api.applyPlugins({
132
+ key: 'onCheckPkgJSON',
133
+ args: {
134
+ origin,
135
+ current: api.appData.pkg,
136
+ },
137
+ });
138
+ api.applyPlugins({
139
+ key: 'onPkgJSONChanged',
140
+ args: {
141
+ origin,
142
+ current: api.appData.pkg,
143
+ },
144
+ });
145
+ },
146
+ });
147
+ // watch config change
148
+ (0, watch_1.addUnWatch)(api.service.configManager.watch({
149
+ schemas: api.service.configSchemas,
150
+ onChangeTypes: api.service.configOnChanges,
151
+ onChange(opts) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ yield api.applyPlugins({
154
+ key: 'onCheckConfig',
155
+ args: {
156
+ config: api.config,
157
+ userConfig: api.userConfig,
158
+ },
159
+ });
160
+ const { data } = opts;
161
+ if (data.changes[api.ConfigChangeType.reload]) {
162
+ utils_1.logger.event(`config ${data.changes[api.ConfigChangeType.reload].join(', ')} changed, restart server...`);
163
+ api.restartServer();
164
+ return;
165
+ }
166
+ if (data.changes[api.ConfigChangeType.regenerateTmpFiles]) {
167
+ utils_1.logger.event(`config ${data.changes[api.ConfigChangeType.reload].join(', ')} changed, regenerate tmp files...`);
168
+ yield generate({ isFirstTime: false });
169
+ }
170
+ for (const fn of data.fns) {
171
+ fn();
172
+ }
173
+ });
174
+ },
175
+ }));
176
+ // watch plugin change
177
+ const pluginFiles = [
178
+ (0, path_1.join)(api.cwd, 'plugin.ts'),
179
+ (0, path_1.join)(api.cwd, 'plugin.js'),
180
+ ];
181
+ pluginFiles.forEach((filePath) => {
182
+ (0, watch_1.watch)({
183
+ path: filePath,
184
+ addToUnWatches: true,
185
+ onChange() {
186
+ utils_1.logger.event(`${(0, path_1.basename)(filePath)} changed, restart server...`);
187
+ api.restartServer();
188
+ },
189
+ });
190
+ });
191
+ yield api.applyPlugins({
192
+ key: 'onBeforeCompiler',
193
+ });
194
+ // start dev server
195
+ const beforeMiddlewares = yield api.applyPlugins({
196
+ key: 'addBeforeMiddlewares',
197
+ initialValue: [],
198
+ });
199
+ const middlewares = yield api.applyPlugins({
200
+ key: 'addMiddlewares',
201
+ initialValue: [],
202
+ });
203
+ const { babelPreset, beforeBabelPlugins, beforeBabelPresets, extraBabelPlugins, extraBabelPresets, } = yield (0, getBabelOpts_1.getBabelOpts)({ api });
204
+ const chainWebpack = (memo, args) => __awaiter(this, void 0, void 0, function* () {
205
+ yield api.applyPlugins({
206
+ key: 'chainWebpack',
207
+ type: api.ApplyPluginsType.modify,
208
+ initialValue: memo,
209
+ args,
210
+ });
211
+ });
212
+ const modifyWebpackConfig = (memo, args) => __awaiter(this, void 0, void 0, function* () {
213
+ return yield api.applyPlugins({
214
+ key: 'modifyWebpackConfig',
215
+ initialValue: memo,
216
+ args,
217
+ });
218
+ });
219
+ const modifyViteConfig = (memo, args) => __awaiter(this, void 0, void 0, function* () {
220
+ return yield api.applyPlugins({
221
+ key: 'modifyViteConfig',
222
+ initialValue: memo,
223
+ args,
224
+ });
225
+ });
226
+ const opts = Object.assign(Object.assign({ config: api.config, cwd: api.cwd, entry: {
227
+ umi: (0, path_1.join)(api.paths.absTmpPath, 'umi.ts'),
228
+ }, port: api.appData.port, host: api.appData.host }, (enableVite
229
+ ? { modifyViteConfig }
230
+ : { babelPreset, chainWebpack, modifyWebpackConfig })), { beforeBabelPlugins,
231
+ beforeBabelPresets,
232
+ extraBabelPlugins,
233
+ extraBabelPresets, beforeMiddlewares: [faviconMiddleware_1.faviconMiddleware].concat(beforeMiddlewares), afterMiddlewares: [(0, createRouteMiddleware_1.createRouteMiddleware)({ api })].concat(middlewares), onDevCompileDone(opts) {
234
+ api.applyPlugins({
235
+ key: 'onDevCompileDone',
236
+ args: opts,
237
+ });
238
+ }, mfsuWithESBuild: (_a = api.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild });
239
+ if (enableVite) {
240
+ yield bundlerVite.dev(opts);
241
+ }
242
+ else {
243
+ yield bundlerWebpack.dev(opts);
244
+ }
245
+ });
246
+ },
247
+ });
248
+ api.modifyAppData((memo) => __awaiter(void 0, void 0, void 0, function* () {
249
+ memo.port = yield utils_1.portfinder.getPortPromise({
250
+ port: parseInt(String(process.env.PORT || constants_1.DEFAULT_PORT), 10),
251
+ });
252
+ memo.host = process.env.HOST || constants_1.DEFAULT_HOST;
253
+ return memo;
254
+ }));
255
+ api.registerMethod({
256
+ name: 'restartServer',
257
+ fn() {
258
+ var _a;
259
+ utils_1.logger.info(`Restart dev server with port ${api.appData.port}...`);
260
+ (0, watch_1.unwatch)();
261
+ (_a = process.send) === null || _a === void 0 ? void 0 : _a.call(process, {
262
+ type: 'RESTART',
263
+ payload: {
264
+ port: api.appData.port,
265
+ },
266
+ });
267
+ },
268
+ });
269
+ };
@@ -0,0 +1,2 @@
1
+ import type { RequestHandler } from '@umijs/bundler-webpack';
2
+ export declare const faviconMiddleware: RequestHandler;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.faviconMiddleware = void 0;
4
+ const path_1 = require("path");
5
+ const faviconMiddleware = (req, res, next) => {
6
+ if (req.path === '/favicon.ico') {
7
+ res.sendFile((0, path_1.join)(__dirname, '../../../assets/umi.png'));
8
+ }
9
+ else {
10
+ next();
11
+ }
12
+ };
13
+ exports.faviconMiddleware = faviconMiddleware;
@@ -0,0 +1,20 @@
1
+ import { IApi } from '../../types';
2
+ export declare function getBabelOpts(opts: {
3
+ api: IApi;
4
+ }): Promise<{
5
+ babelPreset: (string | {
6
+ presetEnv: {};
7
+ presetReact: {
8
+ runtime: string;
9
+ };
10
+ presetTypeScript: {};
11
+ pluginTransformRuntime: {};
12
+ pluginLockCoreJS: {};
13
+ pluginDynamicImportNode: boolean;
14
+ pluginAutoCSSModules: any;
15
+ })[];
16
+ extraBabelPlugins: any;
17
+ extraBabelPresets: any;
18
+ beforeBabelPresets: any;
19
+ beforeBabelPlugins: any;
20
+ }>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getBabelOpts = void 0;
13
+ const utils_1 = require("@umijs/utils");
14
+ function getBabelOpts(opts) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ // TODO: 支持用户自定义
17
+ const isGTEReact17 = utils_1.semver.gte(opts.api.appData.react.version, '17.0.0');
18
+ const babelPreset = [
19
+ require.resolve('@umijs/babel-preset-umi'),
20
+ {
21
+ presetEnv: {},
22
+ presetReact: {
23
+ runtime: isGTEReact17 ? 'automatic' : 'classic',
24
+ },
25
+ presetTypeScript: {},
26
+ pluginTransformRuntime: {},
27
+ pluginLockCoreJS: {},
28
+ pluginDynamicImportNode: false,
29
+ pluginAutoCSSModules: opts.api.userConfig.autoCSSModules,
30
+ },
31
+ ];
32
+ const extraBabelPresets = yield opts.api.applyPlugins({
33
+ key: 'addExtraBabelPresets',
34
+ initialValue: [],
35
+ });
36
+ const extraBabelPlugins = yield opts.api.applyPlugins({
37
+ key: 'addExtraBabelPlugins',
38
+ initialValue: [],
39
+ });
40
+ const beforeBabelPresets = yield opts.api.applyPlugins({
41
+ key: 'addBeforeBabelPresets',
42
+ initialValue: [],
43
+ });
44
+ const beforeBabelPlugins = yield opts.api.applyPlugins({
45
+ key: 'addBeforeBabelPlugins',
46
+ initialValue: [],
47
+ });
48
+ return {
49
+ babelPreset,
50
+ extraBabelPlugins,
51
+ extraBabelPresets,
52
+ beforeBabelPresets,
53
+ beforeBabelPlugins,
54
+ };
55
+ });
56
+ }
57
+ exports.getBabelOpts = getBabelOpts;
@@ -0,0 +1,13 @@
1
+ import { IApi } from '../../types';
2
+ export declare function getMarkupArgs(opts: {
3
+ api: IApi;
4
+ }): Promise<{
5
+ routes: any;
6
+ favicon: any;
7
+ headScripts: any;
8
+ scripts: any;
9
+ metas: any;
10
+ links: any;
11
+ styles: any;
12
+ modifyHTML(memo: string, args: object): Promise<string>;
13
+ }>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getMarkupArgs = void 0;
16
+ const cheerio_1 = __importDefault(require("@umijs/utils/compiled/cheerio"));
17
+ function getMarkupArgs(opts) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const headScripts = yield opts.api.applyPlugins({
20
+ key: 'addHTMLHeadScripts',
21
+ initialValue: opts.api.config.headScripts || [],
22
+ });
23
+ const scripts = yield opts.api.applyPlugins({
24
+ key: 'addHTMLScripts',
25
+ initialValue: opts.api.config.scripts || [],
26
+ });
27
+ const metas = yield opts.api.applyPlugins({
28
+ key: 'addHTMLMetas',
29
+ initialValue: opts.api.config.metas || [],
30
+ });
31
+ const links = yield opts.api.applyPlugins({
32
+ key: 'addHTMLLinks',
33
+ initialValue: opts.api.config.links || [],
34
+ });
35
+ const styles = yield opts.api.applyPlugins({
36
+ key: 'addHTMLStyles',
37
+ initialValue: opts.api.config.styles || [],
38
+ });
39
+ const favicon = yield opts.api.applyPlugins({
40
+ key: 'modifyHTMLFavicon',
41
+ initialValue: opts.api.config.favicon,
42
+ });
43
+ return {
44
+ routes: opts.api.appData.routes,
45
+ favicon,
46
+ headScripts,
47
+ scripts,
48
+ metas,
49
+ links,
50
+ styles,
51
+ modifyHTML(memo, args) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ let $ = cheerio_1.default.load(memo, {
54
+ // @ts-ignore
55
+ decodeEntities: false,
56
+ });
57
+ $ = yield opts.api.applyPlugins({
58
+ key: 'modifyHTML',
59
+ initialValue: $,
60
+ args,
61
+ });
62
+ let html = $.html();
63
+ // TODO: prettier html
64
+ // html = prettier.format(html, {
65
+ // parser: 'html',
66
+ // });
67
+ return html;
68
+ });
69
+ },
70
+ };
71
+ });
72
+ }
73
+ exports.getMarkupArgs = getMarkupArgs;
@@ -0,0 +1,19 @@
1
+ import { chokidar } from '@umijs/utils';
2
+ export declare function addUnWatch(unWatcher: Function): void;
3
+ export declare function watch(opts: {
4
+ path: string | ReadonlyArray<string>;
5
+ watchOpts?: chokidar.WatchOptions;
6
+ addToUnWatches?: boolean;
7
+ onChange: (event: string, path: string) => void;
8
+ }): chokidar.FSWatcher;
9
+ export declare function createDebouncedHandler(opts: {
10
+ timeout?: number;
11
+ onChange: (opts: {
12
+ files: {
13
+ event: string;
14
+ path: string;
15
+ }[];
16
+ }) => Promise<any>;
17
+ }): (event: string, path: string) => void;
18
+ export declare function unwatch(): void;
19
+ export declare function expandJSPaths(path: string): string[];
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.expandJSPaths = exports.unwatch = exports.createDebouncedHandler = exports.watch = exports.addUnWatch = void 0;
13
+ const utils_1 = require("@umijs/utils");
14
+ const unWatches = [];
15
+ function addUnWatch(unWatcher) {
16
+ unWatches.push(unWatcher);
17
+ }
18
+ exports.addUnWatch = addUnWatch;
19
+ function watch(opts) {
20
+ const watcher = utils_1.chokidar.watch(opts.path, Object.assign(Object.assign({}, opts.watchOpts), { ignoreInitial: true }));
21
+ watcher.on('all', opts.onChange);
22
+ if (opts.addToUnWatches) {
23
+ addUnWatch(() => {
24
+ watcher.close();
25
+ });
26
+ }
27
+ return watcher;
28
+ }
29
+ exports.watch = watch;
30
+ function createDebouncedHandler(opts) {
31
+ let timer = null;
32
+ let files = [];
33
+ return (event, path) => {
34
+ if (timer) {
35
+ clearTimeout(timer);
36
+ }
37
+ files.push({ event, path: (0, utils_1.winPath)(path) });
38
+ timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
39
+ timer = null;
40
+ yield opts.onChange({ files });
41
+ files = [];
42
+ }), opts.timeout || 2000);
43
+ };
44
+ }
45
+ exports.createDebouncedHandler = createDebouncedHandler;
46
+ function unwatch() {
47
+ unWatches.forEach((unWatch) => unWatch());
48
+ }
49
+ exports.unwatch = unwatch;
50
+ function expandJSPaths(path) {
51
+ return ['.js', '.jsx', '.ts', '.tsx'].map((ext) => {
52
+ return `${path}${ext}`;
53
+ });
54
+ }
55
+ exports.expandJSPaths = expandJSPaths;
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const core_1 = require("@umijs/core");
13
+ const utils_1 = require("@umijs/utils");
14
+ const path_1 = require("path");
15
+ exports.default = (api) => {
16
+ api.registerGenerator({
17
+ key: 'page',
18
+ name: 'Create Pages',
19
+ description: 'Create a umi page by page name',
20
+ type: core_1.GeneratorType.generate,
21
+ fn: (options) => __awaiter(void 0, void 0, void 0, function* () {
22
+ const { args, api, generateFile } = options;
23
+ const [_, _name] = args._;
24
+ let name = _name;
25
+ if (!name) {
26
+ const response = yield (0, utils_1.prompts)({
27
+ type: 'text',
28
+ name: 'name',
29
+ message: 'What is the name of page?',
30
+ });
31
+ name = response.name;
32
+ }
33
+ generateFile({
34
+ path: (0, path_1.join)(__dirname, '../../../templates/generate/page'),
35
+ target: (0, path_1.join)(api.paths.absPagesPath, name),
36
+ data: {
37
+ color: (0, utils_1.randomColor)(),
38
+ name,
39
+ cssExt: '.less',
40
+ },
41
+ });
42
+ }),
43
+ });
44
+ };
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const core_1 = require("@umijs/core");
13
+ const fs_1 = require("fs");
14
+ const path_1 = require("path");
15
+ exports.default = (api) => {
16
+ api.registerGenerator({
17
+ key: 'prettier',
18
+ name: 'Enable Prettier',
19
+ description: 'Enable Prettier',
20
+ type: core_1.GeneratorType.enable,
21
+ checkEnable: (opts) => {
22
+ const { api } = opts;
23
+ // 存在 .prettierrc,不开启
24
+ return !(0, fs_1.existsSync)((0, path_1.join)(api.paths.cwd, '.prettierrc'));
25
+ },
26
+ fn: (options) => __awaiter(void 0, void 0, void 0, function* () {
27
+ // TODO
28
+ console.log(options);
29
+ }),
30
+ });
31
+ };
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;