@umijs/core 4.0.0-rc.14 → 4.0.0-rc.15
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.
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -30,7 +19,7 @@ function transformRoutes(opts) {
|
|
|
30
19
|
function transformRoute(opts) {
|
|
31
20
|
(0, assert_1.default)(!opts.route.children, 'children is not allowed in route props, use routes instead.');
|
|
32
21
|
const id = String(opts.memo.id++);
|
|
33
|
-
const
|
|
22
|
+
const { routes, component, wrappers, ...routeProps } = opts.route;
|
|
34
23
|
let absPath = opts.route.path;
|
|
35
24
|
if ((absPath === null || absPath === void 0 ? void 0 : absPath.charAt(0)) !== '/') {
|
|
36
25
|
const parentAbsPath = opts.parentId
|
|
@@ -38,7 +27,13 @@ function transformRoute(opts) {
|
|
|
38
27
|
: '/';
|
|
39
28
|
absPath = parentAbsPath + absPath;
|
|
40
29
|
}
|
|
41
|
-
opts.memo.ret[id] =
|
|
30
|
+
opts.memo.ret[id] = {
|
|
31
|
+
...routeProps,
|
|
32
|
+
path: opts.route.path,
|
|
33
|
+
...(component ? { file: component } : {}),
|
|
34
|
+
parentId: opts.parentId,
|
|
35
|
+
id,
|
|
36
|
+
};
|
|
42
37
|
if (absPath) {
|
|
43
38
|
opts.memo.ret[id].absPath = absPath;
|
|
44
39
|
}
|
|
@@ -44,7 +44,7 @@ function visitFiles(opts) {
|
|
|
44
44
|
let file = (0, path_1.resolve)(opts.dir, filename);
|
|
45
45
|
let stat = (0, fs_1.lstatSync)(file);
|
|
46
46
|
if (stat.isDirectory()) {
|
|
47
|
-
visitFiles(
|
|
47
|
+
visitFiles({ ...opts, dir: file });
|
|
48
48
|
}
|
|
49
49
|
else if (stat.isFile() &&
|
|
50
50
|
['.tsx', '.ts', '.js', '.jsx', '.md', '.mdx', '.vue'].includes((0, path_1.extname)(file))) {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const utils_1 = require("@umijs/utils");
|
|
13
4
|
const generator_1 = require("./generator");
|
|
@@ -19,70 +10,68 @@ exports.default = (api) => {
|
|
|
19
10
|
umi generate
|
|
20
11
|
`,
|
|
21
12
|
description: 'generate code snippets quickly',
|
|
22
|
-
fn({ args }) {
|
|
13
|
+
async fn({ args }) {
|
|
23
14
|
var _a;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
const [type] = args._;
|
|
16
|
+
const runGenerator = async (generator) => {
|
|
17
|
+
await (generator === null || generator === void 0 ? void 0 : generator.fn({
|
|
18
|
+
args,
|
|
19
|
+
generateFile: utils_1.generateFile,
|
|
20
|
+
installDeps: utils_1.installDeps,
|
|
21
|
+
updatePackageJSON: utils_1.updatePackageJSON,
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
if (type) {
|
|
25
|
+
const generator = api.service.generators[type];
|
|
26
|
+
if (!generator) {
|
|
27
|
+
throw new Error(`Generator ${type} not found.`);
|
|
28
|
+
}
|
|
29
|
+
if (generator.type === generator_1.GeneratorType.enable) {
|
|
30
|
+
const enable = await ((_a = generator.checkEnable) === null || _a === void 0 ? void 0 : _a.call(generator, {
|
|
28
31
|
args,
|
|
29
|
-
generateFile: utils_1.generateFile,
|
|
30
|
-
installDeps: utils_1.installDeps,
|
|
31
|
-
updatePackageJSON: utils_1.updatePackageJSON,
|
|
32
32
|
}));
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const generator = api.service.generators[type];
|
|
36
|
-
if (!generator) {
|
|
37
|
-
throw new Error(`Generator ${type} not found.`);
|
|
38
|
-
}
|
|
39
|
-
if (generator.type === generator_1.GeneratorType.enable) {
|
|
40
|
-
const enable = yield ((_a = generator.checkEnable) === null || _a === void 0 ? void 0 : _a.call(generator, {
|
|
41
|
-
args,
|
|
42
|
-
}));
|
|
43
|
-
if (!enable) {
|
|
44
|
-
throw new Error(`Generator ${type} is unable.The corresponding function has been turned on or is not available.`);
|
|
45
|
-
}
|
|
33
|
+
if (!enable) {
|
|
34
|
+
throw new Error(`Generator ${type} is unable.The corresponding function has been turned on or is not available.`);
|
|
46
35
|
}
|
|
47
|
-
yield runGenerator(generator);
|
|
48
36
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
37
|
+
await runGenerator(generator);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const getEnableGenerators = async (generators) => {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const questions = [];
|
|
43
|
+
for (const key of Object.keys(generators)) {
|
|
44
|
+
if (generators[key].type === generator_1.GeneratorType.generate) {
|
|
45
|
+
questions.push({
|
|
46
|
+
title: `${generators[key].name} -- ${generators[key].description}` ||
|
|
47
|
+
'',
|
|
48
|
+
value: generators[key].key,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const enable = await ((_b = (_a = generators[key]) === null || _a === void 0 ? void 0 : _a.checkEnable) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
53
|
+
args,
|
|
54
|
+
}));
|
|
55
|
+
if (enable) {
|
|
55
56
|
questions.push({
|
|
56
57
|
title: `${generators[key].name} -- ${generators[key].description}` ||
|
|
57
58
|
'',
|
|
58
59
|
value: generators[key].key,
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
|
-
else {
|
|
62
|
-
const enable = yield ((_c = (_b = generators[key]) === null || _b === void 0 ? void 0 : _b.checkEnable) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
63
|
-
args,
|
|
64
|
-
}));
|
|
65
|
-
if (enable) {
|
|
66
|
-
questions.push({
|
|
67
|
-
title: `${generators[key].name} -- ${generators[key].description}` ||
|
|
68
|
-
'',
|
|
69
|
-
value: generators[key].key,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
62
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
63
|
+
}
|
|
64
|
+
return questions;
|
|
65
|
+
};
|
|
66
|
+
const questions = await getEnableGenerators(api.service.generators);
|
|
67
|
+
const { gType } = await (0, utils_1.prompts)({
|
|
68
|
+
type: 'select',
|
|
69
|
+
name: 'gType',
|
|
70
|
+
message: 'Pick generator type',
|
|
71
|
+
choices: questions,
|
|
72
|
+
});
|
|
73
|
+
await runGenerator(api.service.generators[gType]);
|
|
74
|
+
}
|
|
86
75
|
},
|
|
87
76
|
});
|
|
88
77
|
};
|
|
@@ -50,13 +50,16 @@ class PluginAPI {
|
|
|
50
50
|
var _a;
|
|
51
51
|
const { name } = commandOpts;
|
|
52
52
|
(0, assert_1.default)(!this.service.commands[name], `api.registerCommand() failed, the command ${name} is exists from ${(_a = this.service.commands[name]) === null || _a === void 0 ? void 0 : _a.plugin.id}.`);
|
|
53
|
-
this.service.commands[name] = new command_1.Command(
|
|
53
|
+
this.service.commands[name] = new command_1.Command({
|
|
54
|
+
...commandOpts,
|
|
55
|
+
plugin: this.plugin,
|
|
56
|
+
});
|
|
54
57
|
};
|
|
55
58
|
registerCommand(opts);
|
|
56
59
|
if (alias) {
|
|
57
60
|
const aliases = (0, utils_2.makeArray)(alias);
|
|
58
61
|
aliases.forEach((alias) => {
|
|
59
|
-
registerCommand(
|
|
62
|
+
registerCommand({ ...opts, name: alias });
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
65
|
}
|
|
@@ -64,13 +67,16 @@ class PluginAPI {
|
|
|
64
67
|
var _a;
|
|
65
68
|
const { key } = opts;
|
|
66
69
|
(0, assert_1.default)(!this.service.generators[key], `api.registerGenerator() failed, the generator ${key} is exists from ${(_a = this.service.generators[key]) === null || _a === void 0 ? void 0 : _a.plugin.id}.`);
|
|
67
|
-
this.service.generators[key] = new generator_1.Generator(
|
|
70
|
+
this.service.generators[key] = new generator_1.Generator({
|
|
71
|
+
...opts,
|
|
72
|
+
plugin: this.plugin,
|
|
73
|
+
});
|
|
68
74
|
}
|
|
69
75
|
register(opts) {
|
|
70
76
|
var _a, _b;
|
|
71
77
|
(0, assert_1.default)(this.service.stage <= types_1.ServiceStage.initPlugins, 'api.register() should not be called after plugin register stage.');
|
|
72
78
|
(_a = this.service.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
73
|
-
this.service.hooks[opts.key].push(new hook_1.Hook(
|
|
79
|
+
this.service.hooks[opts.key].push(new hook_1.Hook({ ...opts, plugin: this.plugin }));
|
|
74
80
|
}
|
|
75
81
|
registerMethod(opts) {
|
|
76
82
|
(0, assert_1.default)(!this.service.pluginMethods[opts.name], `api.registerMethod() failed, method ${opts.name} is already exist.`);
|
|
@@ -81,7 +87,10 @@ class PluginAPI {
|
|
|
81
87
|
// 否则 pluginId 会不会,导致不能正确 skip plugin
|
|
82
88
|
function (fn) {
|
|
83
89
|
// @ts-ignore
|
|
84
|
-
this.register(
|
|
90
|
+
this.register({
|
|
91
|
+
key: opts.name,
|
|
92
|
+
...(utils_1.lodash.isPlainObject(fn) ? fn : { fn }),
|
|
93
|
+
});
|
|
85
94
|
},
|
|
86
95
|
};
|
|
87
96
|
}
|
|
@@ -80,6 +80,11 @@ export declare class Service {
|
|
|
80
80
|
name: string;
|
|
81
81
|
args?: any;
|
|
82
82
|
}): Promise<void>;
|
|
83
|
+
generateFinalConfig(): Promise<{
|
|
84
|
+
config: any;
|
|
85
|
+
defaultConfig: any;
|
|
86
|
+
finalConfig: Record<string, any>;
|
|
87
|
+
}>;
|
|
83
88
|
_baconPlugins(): void;
|
|
84
89
|
initPreset(opts: {
|
|
85
90
|
preset: Plugin;
|
package/dist/service/service.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -82,14 +73,14 @@ class Service {
|
|
|
82
73
|
name: hook.plugin.key,
|
|
83
74
|
stage: hook.stage,
|
|
84
75
|
before: hook.before,
|
|
85
|
-
}, (memo) =>
|
|
76
|
+
}, async (memo) => {
|
|
86
77
|
var _a, _b;
|
|
87
78
|
const dateStart = new Date();
|
|
88
|
-
const items =
|
|
79
|
+
const items = await hook.fn(opts.args);
|
|
89
80
|
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
90
81
|
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
91
82
|
return memo.concat(items);
|
|
92
|
-
})
|
|
83
|
+
});
|
|
93
84
|
}
|
|
94
85
|
return tAdd.promise(opts.initialValue || []);
|
|
95
86
|
case types_1.ApplyPluginsType.modify:
|
|
@@ -101,14 +92,14 @@ class Service {
|
|
|
101
92
|
name: hook.plugin.key,
|
|
102
93
|
stage: hook.stage,
|
|
103
94
|
before: hook.before,
|
|
104
|
-
}, (memo) =>
|
|
105
|
-
var
|
|
95
|
+
}, async (memo) => {
|
|
96
|
+
var _a, _b;
|
|
106
97
|
const dateStart = new Date();
|
|
107
|
-
const ret =
|
|
108
|
-
(
|
|
98
|
+
const ret = await hook.fn(memo, opts.args);
|
|
99
|
+
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
109
100
|
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
110
101
|
return ret;
|
|
111
|
-
})
|
|
102
|
+
});
|
|
112
103
|
}
|
|
113
104
|
return tModify.promise(opts.initialValue);
|
|
114
105
|
case types_1.ApplyPluginsType.event:
|
|
@@ -139,176 +130,186 @@ class Service {
|
|
|
139
130
|
name: hook.plugin.key,
|
|
140
131
|
stage: hook.stage || 0,
|
|
141
132
|
before: hook.before,
|
|
142
|
-
}, () =>
|
|
143
|
-
var
|
|
133
|
+
}, async () => {
|
|
134
|
+
var _a, _b;
|
|
144
135
|
const dateStart = new Date();
|
|
145
|
-
|
|
146
|
-
(
|
|
136
|
+
await hook.fn(opts.args);
|
|
137
|
+
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
147
138
|
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
148
|
-
})
|
|
139
|
+
});
|
|
149
140
|
}
|
|
150
141
|
return tEvent.promise(1);
|
|
151
142
|
default:
|
|
152
143
|
throw new Error(`applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`);
|
|
153
144
|
}
|
|
154
145
|
}
|
|
155
|
-
run(opts) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
pkgPath = (0, path_1.join)(process.cwd(), 'package.json');
|
|
180
|
-
}
|
|
181
|
-
catch (_e) { }
|
|
146
|
+
async run(opts) {
|
|
147
|
+
const { name, args = {} } = opts;
|
|
148
|
+
args._ = args._ || [];
|
|
149
|
+
// shift the command itself
|
|
150
|
+
if (args._[0] === name)
|
|
151
|
+
args._.shift();
|
|
152
|
+
this.args = args;
|
|
153
|
+
this.name = name;
|
|
154
|
+
// loadEnv
|
|
155
|
+
this.stage = types_1.ServiceStage.init;
|
|
156
|
+
(0, env_1.loadEnv)({ cwd: this.cwd, envFile: '.env' });
|
|
157
|
+
// get pkg from package.json
|
|
158
|
+
let pkg = {};
|
|
159
|
+
let pkgPath = '';
|
|
160
|
+
try {
|
|
161
|
+
pkg = require((0, path_1.join)(this.cwd, 'package.json'));
|
|
162
|
+
pkgPath = (0, path_1.join)(this.cwd, 'package.json');
|
|
163
|
+
}
|
|
164
|
+
catch (_e) {
|
|
165
|
+
// APP_ROOT
|
|
166
|
+
if (this.cwd !== process.cwd()) {
|
|
167
|
+
try {
|
|
168
|
+
pkg = require((0, path_1.join)(process.cwd(), 'package.json'));
|
|
169
|
+
pkgPath = (0, path_1.join)(process.cwd(), 'package.json');
|
|
182
170
|
}
|
|
171
|
+
catch (_e) { }
|
|
183
172
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
173
|
+
}
|
|
174
|
+
this.pkg = pkg;
|
|
175
|
+
this.pkgPath = pkgPath || (0, path_1.join)(this.cwd, 'package.json');
|
|
176
|
+
const prefix = this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME;
|
|
177
|
+
// get user config
|
|
178
|
+
const configManager = new config_1.Config({
|
|
179
|
+
cwd: this.cwd,
|
|
180
|
+
env: this.env,
|
|
181
|
+
defaultConfigFiles: this.opts.defaultConfigFiles,
|
|
182
|
+
specifiedEnv: process.env[`${prefix}_ENV`.toUpperCase()],
|
|
183
|
+
});
|
|
184
|
+
this.configManager = configManager;
|
|
185
|
+
this.userConfig = configManager.getUserConfig().config;
|
|
186
|
+
// get paths
|
|
187
|
+
const paths = (0, path_2.getPaths)({
|
|
188
|
+
cwd: this.cwd,
|
|
189
|
+
env: this.env,
|
|
190
|
+
prefix: this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME,
|
|
191
|
+
});
|
|
192
|
+
// temporary paths for use by function generateFinalConfig.
|
|
193
|
+
// the value of paths may be updated by plugins later
|
|
194
|
+
this.paths = paths;
|
|
195
|
+
// resolve initial presets and plugins
|
|
196
|
+
const { plugins, presets } = plugin_1.Plugin.getPluginsAndPresets({
|
|
197
|
+
cwd: this.cwd,
|
|
198
|
+
pkg,
|
|
199
|
+
plugins: [require.resolve('./generatePlugin')].concat(this.opts.plugins || []),
|
|
200
|
+
presets: [require.resolve('./servicePlugin')].concat(this.opts.presets || []),
|
|
201
|
+
userConfig: this.userConfig,
|
|
202
|
+
prefix,
|
|
203
|
+
});
|
|
204
|
+
// register presets and plugins
|
|
205
|
+
this.stage = types_1.ServiceStage.initPresets;
|
|
206
|
+
const presetPlugins = [];
|
|
207
|
+
while (presets.length) {
|
|
208
|
+
await this.initPreset({
|
|
209
|
+
preset: presets.shift(),
|
|
210
|
+
presets,
|
|
211
|
+
plugins: presetPlugins,
|
|
193
212
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
213
|
+
}
|
|
214
|
+
plugins.unshift(...presetPlugins);
|
|
215
|
+
this.stage = types_1.ServiceStage.initPlugins;
|
|
216
|
+
while (plugins.length) {
|
|
217
|
+
await this.initPlugin({ plugin: plugins.shift(), plugins });
|
|
218
|
+
}
|
|
219
|
+
// collect configSchemas and configDefaults
|
|
220
|
+
for (const id of Object.keys(this.plugins)) {
|
|
221
|
+
const { config, key } = this.plugins[id];
|
|
222
|
+
if (config.schema)
|
|
223
|
+
this.configSchemas[key] = config.schema;
|
|
224
|
+
if (config.default !== undefined) {
|
|
225
|
+
this.configDefaults[key] = config.default;
|
|
226
|
+
}
|
|
227
|
+
this.configOnChanges[key] = config.onChange || types_1.ConfigChangeType.reload;
|
|
228
|
+
}
|
|
229
|
+
// setup api.config from modifyConfig and modifyDefaultConfig
|
|
230
|
+
this.stage = types_1.ServiceStage.resolveConfig;
|
|
231
|
+
const { config, defaultConfig } = await this.generateFinalConfig();
|
|
232
|
+
if (this.config.outputPath) {
|
|
233
|
+
paths.absOutputPath = (0, path_1.isAbsolute)(this.config.outputPath)
|
|
234
|
+
? this.config.outputPath
|
|
235
|
+
: (0, path_1.join)(this.cwd, this.config.outputPath);
|
|
236
|
+
}
|
|
237
|
+
this.paths = await this.applyPlugins({
|
|
238
|
+
key: 'modifyPaths',
|
|
239
|
+
initialValue: paths,
|
|
240
|
+
});
|
|
241
|
+
// applyPlugin collect app data
|
|
242
|
+
// TODO: some data is mutable
|
|
243
|
+
this.stage = types_1.ServiceStage.collectAppData;
|
|
244
|
+
this.appData = await this.applyPlugins({
|
|
245
|
+
key: 'modifyAppData',
|
|
246
|
+
initialValue: {
|
|
247
|
+
// base
|
|
199
248
|
cwd: this.cwd,
|
|
200
249
|
pkg,
|
|
201
|
-
|
|
202
|
-
|
|
250
|
+
pkgPath,
|
|
251
|
+
plugins,
|
|
252
|
+
presets,
|
|
253
|
+
name,
|
|
254
|
+
args,
|
|
255
|
+
// config
|
|
203
256
|
userConfig: this.userConfig,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
this.config = utils_1.lodash.merge(defaultConfig, config);
|
|
253
|
-
if (this.config.outputPath) {
|
|
254
|
-
paths.absOutputPath = (0, path_1.isAbsolute)(this.config.outputPath)
|
|
255
|
-
? this.config.outputPath
|
|
256
|
-
: (0, path_1.join)(this.cwd, this.config.outputPath);
|
|
257
|
-
}
|
|
258
|
-
this.paths = yield this.applyPlugins({
|
|
259
|
-
key: 'modifyPaths',
|
|
260
|
-
initialValue: paths,
|
|
261
|
-
});
|
|
262
|
-
// applyPlugin collect app data
|
|
263
|
-
// TODO: some data is mutable
|
|
264
|
-
this.stage = types_1.ServiceStage.collectAppData;
|
|
265
|
-
this.appData = yield this.applyPlugins({
|
|
266
|
-
key: 'modifyAppData',
|
|
267
|
-
initialValue: {
|
|
268
|
-
// base
|
|
269
|
-
cwd: this.cwd,
|
|
270
|
-
pkg,
|
|
271
|
-
pkgPath,
|
|
272
|
-
plugins,
|
|
273
|
-
presets,
|
|
274
|
-
name,
|
|
275
|
-
args,
|
|
276
|
-
// config
|
|
277
|
-
userConfig: this.userConfig,
|
|
278
|
-
mainConfigFile: configManager.mainConfigFile,
|
|
279
|
-
config,
|
|
280
|
-
defaultConfig: defaultConfig,
|
|
281
|
-
// TODO
|
|
282
|
-
// moduleGraph,
|
|
283
|
-
// routes,
|
|
284
|
-
// npmClient,
|
|
285
|
-
// nodeVersion,
|
|
286
|
-
// gitInfo,
|
|
287
|
-
// gitBranch,
|
|
288
|
-
// debugger info,
|
|
289
|
-
// devPort,
|
|
290
|
-
// devHost,
|
|
291
|
-
// env
|
|
292
|
-
},
|
|
293
|
-
});
|
|
294
|
-
// applyPlugin onCheck
|
|
295
|
-
this.stage = types_1.ServiceStage.onCheck;
|
|
296
|
-
yield this.applyPlugins({
|
|
297
|
-
key: 'onCheck',
|
|
298
|
-
});
|
|
299
|
-
// applyPlugin onStart
|
|
300
|
-
this.stage = types_1.ServiceStage.onStart;
|
|
301
|
-
yield this.applyPlugins({
|
|
302
|
-
key: 'onStart',
|
|
303
|
-
});
|
|
304
|
-
// run command
|
|
305
|
-
this.stage = types_1.ServiceStage.runCommand;
|
|
306
|
-
const command = this.commands[name];
|
|
307
|
-
(0, assert_1.default)(command, `Invalid command ${name}, it's not registered.`);
|
|
308
|
-
let ret = yield command.fn({ args });
|
|
309
|
-
this._baconPlugins();
|
|
310
|
-
return ret;
|
|
257
|
+
mainConfigFile: configManager.mainConfigFile,
|
|
258
|
+
config,
|
|
259
|
+
defaultConfig: defaultConfig,
|
|
260
|
+
// TODO
|
|
261
|
+
// moduleGraph,
|
|
262
|
+
// routes,
|
|
263
|
+
// npmClient,
|
|
264
|
+
// nodeVersion,
|
|
265
|
+
// gitInfo,
|
|
266
|
+
// gitBranch,
|
|
267
|
+
// debugger info,
|
|
268
|
+
// devPort,
|
|
269
|
+
// devHost,
|
|
270
|
+
// env
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
// applyPlugin onCheck
|
|
274
|
+
this.stage = types_1.ServiceStage.onCheck;
|
|
275
|
+
await this.applyPlugins({
|
|
276
|
+
key: 'onCheck',
|
|
277
|
+
});
|
|
278
|
+
// applyPlugin onStart
|
|
279
|
+
this.stage = types_1.ServiceStage.onStart;
|
|
280
|
+
await this.applyPlugins({
|
|
281
|
+
key: 'onStart',
|
|
282
|
+
});
|
|
283
|
+
// run command
|
|
284
|
+
this.stage = types_1.ServiceStage.runCommand;
|
|
285
|
+
const command = this.commands[name];
|
|
286
|
+
(0, assert_1.default)(command, `Invalid command ${name}, it's not registered.`);
|
|
287
|
+
let ret = await command.fn({ args });
|
|
288
|
+
this._baconPlugins();
|
|
289
|
+
return ret;
|
|
290
|
+
}
|
|
291
|
+
// generate config and defaultConfig, and assign values to this.config
|
|
292
|
+
async generateFinalConfig() {
|
|
293
|
+
var _a;
|
|
294
|
+
// configManager and paths are not available until the init stage
|
|
295
|
+
(0, assert_1.default)(this.stage > types_1.ServiceStage.init, `Can't generate final config before init stage`);
|
|
296
|
+
const config = await this.applyPlugins({
|
|
297
|
+
key: 'modifyConfig',
|
|
298
|
+
// why clone deep?
|
|
299
|
+
// user may change the config in modifyConfig
|
|
300
|
+
// e.g. memo.alias = xxx
|
|
301
|
+
initialValue: utils_1.lodash.cloneDeep((_a = this.configManager) === null || _a === void 0 ? void 0 : _a.getConfig({
|
|
302
|
+
schemas: this.configSchemas,
|
|
303
|
+
}).config),
|
|
304
|
+
args: { paths: this.paths },
|
|
311
305
|
});
|
|
306
|
+
const defaultConfig = await this.applyPlugins({
|
|
307
|
+
key: 'modifyDefaultConfig',
|
|
308
|
+
initialValue: this.configDefaults,
|
|
309
|
+
});
|
|
310
|
+
const finalConfig = utils_1.lodash.merge(defaultConfig, config);
|
|
311
|
+
this.config = finalConfig;
|
|
312
|
+
return { config, defaultConfig, finalConfig };
|
|
312
313
|
}
|
|
313
314
|
_baconPlugins() {
|
|
314
315
|
// TODO: prettier
|
|
@@ -320,80 +321,76 @@ class Service {
|
|
|
320
321
|
}
|
|
321
322
|
}
|
|
322
323
|
}
|
|
323
|
-
initPreset(opts) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
plugins: opts.plugins,
|
|
329
|
-
});
|
|
330
|
-
opts.presets.unshift(...(presets || []));
|
|
331
|
-
opts.plugins.push(...(plugins || []));
|
|
324
|
+
async initPreset(opts) {
|
|
325
|
+
const { presets, plugins } = await this.initPlugin({
|
|
326
|
+
plugin: opts.preset,
|
|
327
|
+
presets: opts.presets,
|
|
328
|
+
plugins: opts.plugins,
|
|
332
329
|
});
|
|
330
|
+
opts.presets.unshift(...(presets || []));
|
|
331
|
+
opts.plugins.push(...(plugins || []));
|
|
333
332
|
}
|
|
334
|
-
initPlugin(opts) {
|
|
333
|
+
async initPlugin(opts) {
|
|
335
334
|
var _a, _b;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
335
|
+
// register to this.plugins
|
|
336
|
+
(0, assert_1.default)(!this.plugins[opts.plugin.id], `${opts.plugin.type} ${opts.plugin.id} is already registered by ${(_a = this.plugins[opts.plugin.id]) === null || _a === void 0 ? void 0 : _a.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
|
|
337
|
+
this.plugins[opts.plugin.id] = opts.plugin;
|
|
338
|
+
// apply with PluginAPI
|
|
339
|
+
const pluginAPI = new pluginAPI_1.PluginAPI({
|
|
340
|
+
plugin: opts.plugin,
|
|
341
|
+
service: this,
|
|
342
|
+
});
|
|
343
|
+
pluginAPI.registerPresets = pluginAPI.registerPresets.bind(pluginAPI, opts.presets || []);
|
|
344
|
+
pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(pluginAPI, opts.plugins);
|
|
345
|
+
const proxyPluginAPI = pluginAPI_1.PluginAPI.proxyPluginAPI({
|
|
346
|
+
service: this,
|
|
347
|
+
pluginAPI,
|
|
348
|
+
serviceProps: [
|
|
349
|
+
'appData',
|
|
350
|
+
'applyPlugins',
|
|
351
|
+
'args',
|
|
352
|
+
'config',
|
|
353
|
+
'cwd',
|
|
354
|
+
'pkg',
|
|
355
|
+
'pkgPath',
|
|
356
|
+
'name',
|
|
357
|
+
'paths',
|
|
358
|
+
'userConfig',
|
|
359
|
+
'env',
|
|
360
|
+
'isPluginEnable',
|
|
361
|
+
],
|
|
362
|
+
staticProps: {
|
|
363
|
+
ApplyPluginsType: types_1.ApplyPluginsType,
|
|
364
|
+
ConfigChangeType: types_1.ConfigChangeType,
|
|
365
|
+
EnableBy: types_1.EnableBy,
|
|
366
|
+
ServiceStage: types_1.ServiceStage,
|
|
348
367
|
service: this,
|
|
349
|
-
|
|
350
|
-
serviceProps: [
|
|
351
|
-
'appData',
|
|
352
|
-
'applyPlugins',
|
|
353
|
-
'args',
|
|
354
|
-
'config',
|
|
355
|
-
'cwd',
|
|
356
|
-
'pkg',
|
|
357
|
-
'pkgPath',
|
|
358
|
-
'name',
|
|
359
|
-
'paths',
|
|
360
|
-
'userConfig',
|
|
361
|
-
'env',
|
|
362
|
-
'isPluginEnable',
|
|
363
|
-
],
|
|
364
|
-
staticProps: {
|
|
365
|
-
ApplyPluginsType: types_1.ApplyPluginsType,
|
|
366
|
-
ConfigChangeType: types_1.ConfigChangeType,
|
|
367
|
-
EnableBy: types_1.EnableBy,
|
|
368
|
-
ServiceStage: types_1.ServiceStage,
|
|
369
|
-
service: this,
|
|
370
|
-
},
|
|
371
|
-
});
|
|
372
|
-
let dateStart = new Date();
|
|
373
|
-
let ret = yield opts.plugin.apply()(proxyPluginAPI);
|
|
374
|
-
opts.plugin.time.register = new Date().getTime() - dateStart.getTime();
|
|
375
|
-
if (opts.plugin.type === 'plugin') {
|
|
376
|
-
(0, assert_1.default)(!ret, `plugin should return nothing`);
|
|
377
|
-
}
|
|
378
|
-
// key should be unique
|
|
379
|
-
(0, assert_1.default)(!this.keyToPluginMap[opts.plugin.key], `key ${opts.plugin.key} is already registered by ${(_b = this.keyToPluginMap[opts.plugin.key]) === null || _b === void 0 ? void 0 : _b.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
|
|
380
|
-
this.keyToPluginMap[opts.plugin.key] = opts.plugin;
|
|
381
|
-
if (ret === null || ret === void 0 ? void 0 : ret.presets) {
|
|
382
|
-
ret.presets = ret.presets.map((preset) => new plugin_1.Plugin({
|
|
383
|
-
path: preset,
|
|
384
|
-
type: types_1.PluginType.preset,
|
|
385
|
-
cwd: this.cwd,
|
|
386
|
-
}));
|
|
387
|
-
}
|
|
388
|
-
if (ret === null || ret === void 0 ? void 0 : ret.plugins) {
|
|
389
|
-
ret.plugins = ret.plugins.map((plugin) => new plugin_1.Plugin({
|
|
390
|
-
path: plugin,
|
|
391
|
-
type: types_1.PluginType.plugin,
|
|
392
|
-
cwd: this.cwd,
|
|
393
|
-
}));
|
|
394
|
-
}
|
|
395
|
-
return ret || {};
|
|
368
|
+
},
|
|
396
369
|
});
|
|
370
|
+
let dateStart = new Date();
|
|
371
|
+
let ret = await opts.plugin.apply()(proxyPluginAPI);
|
|
372
|
+
opts.plugin.time.register = new Date().getTime() - dateStart.getTime();
|
|
373
|
+
if (opts.plugin.type === 'plugin') {
|
|
374
|
+
(0, assert_1.default)(!ret, `plugin should return nothing`);
|
|
375
|
+
}
|
|
376
|
+
// key should be unique
|
|
377
|
+
(0, assert_1.default)(!this.keyToPluginMap[opts.plugin.key], `key ${opts.plugin.key} is already registered by ${(_b = this.keyToPluginMap[opts.plugin.key]) === null || _b === void 0 ? void 0 : _b.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
|
|
378
|
+
this.keyToPluginMap[opts.plugin.key] = opts.plugin;
|
|
379
|
+
if (ret === null || ret === void 0 ? void 0 : ret.presets) {
|
|
380
|
+
ret.presets = ret.presets.map((preset) => new plugin_1.Plugin({
|
|
381
|
+
path: preset,
|
|
382
|
+
type: types_1.PluginType.preset,
|
|
383
|
+
cwd: this.cwd,
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
if (ret === null || ret === void 0 ? void 0 : ret.plugins) {
|
|
387
|
+
ret.plugins = ret.plugins.map((plugin) => new plugin_1.Plugin({
|
|
388
|
+
path: plugin,
|
|
389
|
+
type: types_1.PluginType.plugin,
|
|
390
|
+
cwd: this.cwd,
|
|
391
|
+
}));
|
|
392
|
+
}
|
|
393
|
+
return ret || {};
|
|
397
394
|
}
|
|
398
395
|
isPluginEnable(hook) {
|
|
399
396
|
let plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/core",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.15",
|
|
4
4
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/core#readme",
|
|
5
5
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
6
6
|
"repository": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"test": "umi-scripts jest-turbo"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@umijs/bundler-utils": "4.0.0-rc.
|
|
25
|
-
"@umijs/utils": "4.0.0-rc.
|
|
24
|
+
"@umijs/bundler-utils": "4.0.0-rc.15",
|
|
25
|
+
"@umijs/utils": "4.0.0-rc.15"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@hapi/joi": "17.1.1",
|