@umijs/core 4.0.0-rc.2 → 4.0.0-rc.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/dist/route/defineRoutes.js +6 -3
- package/dist/route/route.js +5 -1
- package/dist/route/routesConfig.d.ts +1 -0
- package/dist/route/routesConfig.js +54 -15
- package/dist/route/routesConvention.js +2 -2
- package/dist/route/utils.js +1 -1
- package/dist/service/command.d.ts +3 -0
- package/dist/service/command.js +1 -0
- package/dist/service/generatePlugin.js +59 -67
- package/dist/service/generator.d.ts +40 -29
- package/dist/service/generator.js +6 -12
- package/dist/service/path.d.ts +2 -0
- package/dist/service/path.js +2 -0
- package/dist/service/plugin.d.ts +4 -0
- package/dist/service/plugin.js +4 -3
- package/dist/service/pluginAPI.d.ts +6 -3
- package/dist/service/pluginAPI.js +31 -10
- package/dist/service/service.d.ts +16 -1
- package/dist/service/service.js +340 -290
- package/dist/types.d.ts +2 -0
- package/package.json +9 -10
- package/compiled/tapable/LICENSE +0 -21
- package/compiled/tapable/index.js +0 -1
- package/compiled/tapable/package.json +0 -1
- package/compiled/tapable/tapable.d.ts +0 -116
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './config/config';
|
|
2
2
|
export * from './route/route';
|
|
3
|
-
export {
|
|
3
|
+
export { Generator, GeneratorType } from './service/generator';
|
|
4
4
|
export * from './service/pluginAPI';
|
|
5
5
|
export * from './service/service';
|
|
6
6
|
export { Env, IAdd, IEvent, IModify, IRoute } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -7,13 +7,16 @@ function defineRoutes(callback) {
|
|
|
7
7
|
const parentRoutes = [];
|
|
8
8
|
const defineRoute = (opts) => {
|
|
9
9
|
opts.options = opts.options || {};
|
|
10
|
+
const parentRoute = parentRoutes.length > 0 ? parentRoutes[parentRoutes.length - 1] : null;
|
|
11
|
+
const parentId = parentRoute === null || parentRoute === void 0 ? void 0 : parentRoute.id;
|
|
12
|
+
const parentAbsPath = parentRoute === null || parentRoute === void 0 ? void 0 : parentRoute.absPath;
|
|
13
|
+
const absPath = [parentAbsPath, opts.path].join('/');
|
|
10
14
|
const route = {
|
|
11
15
|
path: opts.path || '/',
|
|
12
16
|
id: (0, utils_1.createRouteId)(opts.file),
|
|
13
|
-
parentId
|
|
14
|
-
? parentRoutes[parentRoutes.length - 1].id
|
|
15
|
-
: undefined,
|
|
17
|
+
parentId,
|
|
16
18
|
file: opts.file,
|
|
19
|
+
absPath,
|
|
17
20
|
};
|
|
18
21
|
routes[route.id] = route;
|
|
19
22
|
if (opts.children) {
|
package/dist/route/route.js
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
// programming route
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
9
13
|
}) : (function(o, m, k, k2) {
|
|
10
14
|
if (k2 === undefined) k2 = k;
|
|
11
15
|
o[k2] = m[k];
|
|
@@ -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
|
};
|
|
@@ -18,25 +7,75 @@ exports.getConfigRoutes = void 0;
|
|
|
18
7
|
const assert_1 = __importDefault(require("assert"));
|
|
19
8
|
function getConfigRoutes(opts) {
|
|
20
9
|
const memo = { ret: {}, id: 1 };
|
|
21
|
-
transformRoutes({
|
|
10
|
+
transformRoutes({
|
|
11
|
+
routes: opts.routes,
|
|
12
|
+
parentId: undefined,
|
|
13
|
+
memo,
|
|
14
|
+
onResolveComponent: opts.onResolveComponent,
|
|
15
|
+
});
|
|
22
16
|
return memo.ret;
|
|
23
17
|
}
|
|
24
18
|
exports.getConfigRoutes = getConfigRoutes;
|
|
25
19
|
function transformRoutes(opts) {
|
|
26
20
|
opts.routes.forEach((route) => {
|
|
27
|
-
transformRoute({
|
|
21
|
+
transformRoute({
|
|
22
|
+
route,
|
|
23
|
+
parentId: opts.parentId,
|
|
24
|
+
memo: opts.memo,
|
|
25
|
+
onResolveComponent: opts.onResolveComponent,
|
|
26
|
+
});
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
29
|
function transformRoute(opts) {
|
|
31
30
|
(0, assert_1.default)(!opts.route.children, 'children is not allowed in route props, use routes instead.');
|
|
32
31
|
const id = String(opts.memo.id++);
|
|
33
|
-
const
|
|
34
|
-
|
|
32
|
+
const { routes, component, wrappers, ...routeProps } = opts.route;
|
|
33
|
+
let absPath = opts.route.path;
|
|
34
|
+
if ((absPath === null || absPath === void 0 ? void 0 : absPath.charAt(0)) !== '/') {
|
|
35
|
+
const parentAbsPath = opts.parentId
|
|
36
|
+
? opts.memo.ret[opts.parentId].absPath.replace(/\/+$/, '/') // to remove '/'s on the tail
|
|
37
|
+
: '/';
|
|
38
|
+
absPath = parentAbsPath + absPath;
|
|
39
|
+
}
|
|
40
|
+
opts.memo.ret[id] = {
|
|
41
|
+
...routeProps,
|
|
42
|
+
path: opts.route.path,
|
|
43
|
+
...(component
|
|
44
|
+
? {
|
|
45
|
+
file: opts.onResolveComponent
|
|
46
|
+
? opts.onResolveComponent(component)
|
|
47
|
+
: component,
|
|
48
|
+
}
|
|
49
|
+
: {}),
|
|
50
|
+
parentId: opts.parentId,
|
|
51
|
+
id,
|
|
52
|
+
};
|
|
53
|
+
if (absPath) {
|
|
54
|
+
opts.memo.ret[id].absPath = absPath;
|
|
55
|
+
}
|
|
56
|
+
if (wrappers === null || wrappers === void 0 ? void 0 : wrappers.length) {
|
|
57
|
+
let parentId = opts.parentId;
|
|
58
|
+
let path = opts.route.path;
|
|
59
|
+
wrappers.forEach((wrapper) => {
|
|
60
|
+
const { id } = transformRoute({
|
|
61
|
+
route: { path, component: wrapper },
|
|
62
|
+
parentId,
|
|
63
|
+
memo: opts.memo,
|
|
64
|
+
onResolveComponent: opts.onResolveComponent,
|
|
65
|
+
});
|
|
66
|
+
parentId = id;
|
|
67
|
+
path = '';
|
|
68
|
+
});
|
|
69
|
+
opts.memo.ret[id].parentId = parentId;
|
|
70
|
+
opts.memo.ret[id].path = path;
|
|
71
|
+
}
|
|
35
72
|
if (opts.route.routes) {
|
|
36
73
|
transformRoutes({
|
|
37
74
|
routes: opts.route.routes,
|
|
38
75
|
parentId: id,
|
|
39
76
|
memo: opts.memo,
|
|
77
|
+
onResolveComponent: opts.onResolveComponent,
|
|
40
78
|
});
|
|
41
79
|
}
|
|
80
|
+
return { id };
|
|
42
81
|
}
|
|
@@ -44,10 +44,10 @@ 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
|
-
['.tsx', '.ts', '.js', '.jsx', '.md', '.mdx'].includes((0, path_1.extname)(file))) {
|
|
50
|
+
['.tsx', '.ts', '.js', '.jsx', '.md', '.mdx', '.vue'].includes((0, path_1.extname)(file))) {
|
|
51
51
|
opts.visitor((0, path_1.relative)(opts.baseDir, file));
|
|
52
52
|
}
|
|
53
53
|
}
|
package/dist/route/utils.js
CHANGED
|
@@ -19,7 +19,7 @@ function findParentRouteId(routeIds, childRouteId) {
|
|
|
19
19
|
return routeIds.find((id) => childRouteId.startsWith(`${id}/`));
|
|
20
20
|
}
|
|
21
21
|
exports.findParentRouteId = findParentRouteId;
|
|
22
|
-
const routeModuleExts = ['.js', '.jsx', '.ts', '.tsx', '.md', '.mdx'];
|
|
22
|
+
const routeModuleExts = ['.js', '.jsx', '.ts', '.tsx', '.md', '.mdx', '.vue'];
|
|
23
23
|
function isRouteModuleFile(opts) {
|
|
24
24
|
// TODO: add cache strategy
|
|
25
25
|
for (const excludeRegExp of opts.exclude || []) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { yParser } from '@umijs/utils';
|
|
2
2
|
import { Plugin } from './plugin';
|
|
3
|
+
import { ResolveConfigMode } from './pluginAPI';
|
|
3
4
|
export interface IOpts {
|
|
4
5
|
name: string;
|
|
5
6
|
description?: string;
|
|
@@ -11,12 +12,14 @@ export interface IOpts {
|
|
|
11
12
|
}): void;
|
|
12
13
|
};
|
|
13
14
|
plugin: Plugin;
|
|
15
|
+
configResolveMode?: ResolveConfigMode;
|
|
14
16
|
}
|
|
15
17
|
export declare class Command {
|
|
16
18
|
name: string;
|
|
17
19
|
description?: string;
|
|
18
20
|
options?: string;
|
|
19
21
|
details?: string;
|
|
22
|
+
configResolveMode: ResolveConfigMode;
|
|
20
23
|
fn: {
|
|
21
24
|
({ args }: {
|
|
22
25
|
args: yParser.Arguments;
|
package/dist/service/command.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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const utils_1 = require("@umijs/utils");
|
|
13
4
|
const generator_1 = require("./generator");
|
|
@@ -19,73 +10,74 @@ exports.default = (api) => {
|
|
|
19
10
|
umi generate
|
|
20
11
|
`,
|
|
21
12
|
description: 'generate code snippets quickly',
|
|
22
|
-
|
|
13
|
+
configResolveMode: 'loose',
|
|
14
|
+
async fn({ args }) {
|
|
23
15
|
var _a;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
const [type] = args._;
|
|
17
|
+
const runGenerator = async (generator) => {
|
|
18
|
+
await (generator === null || generator === void 0 ? void 0 : generator.fn({
|
|
19
|
+
args,
|
|
20
|
+
generateFile: utils_1.generateFile,
|
|
21
|
+
installDeps: utils_1.installDeps,
|
|
22
|
+
updatePackageJSON: utils_1.updatePackageJSON,
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
if (type) {
|
|
26
|
+
const generator = api.service.generators[type];
|
|
27
|
+
if (!generator) {
|
|
28
|
+
throw new Error(`Generator ${type} not found.`);
|
|
29
|
+
}
|
|
30
|
+
if (generator.type === generator_1.GeneratorType.enable) {
|
|
31
|
+
const enable = await ((_a = generator.checkEnable) === null || _a === void 0 ? void 0 : _a.call(generator, {
|
|
29
32
|
args,
|
|
30
|
-
generateFile: utils_1.generateFile,
|
|
31
|
-
installDeps: utils_1.installDeps,
|
|
32
|
-
updatePackageJSON: utils_1.updatePackageJSON,
|
|
33
33
|
}));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (generator.type === generator_1.GeneratorType.enable) {
|
|
41
|
-
const enable = yield ((_a = generator.checkEnable) === null || _a === void 0 ? void 0 : _a.call(generator, {
|
|
42
|
-
api,
|
|
43
|
-
args,
|
|
44
|
-
}));
|
|
45
|
-
if (!enable) {
|
|
46
|
-
throw new Error(`Generator ${type} is unable.The corresponding function has been turned on or is not available.`);
|
|
34
|
+
if (!enable) {
|
|
35
|
+
if (typeof generator.disabledDescription === 'function') {
|
|
36
|
+
utils_1.logger.warn(generator.disabledDescription());
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
utils_1.logger.warn(generator.disabledDescription);
|
|
47
40
|
}
|
|
41
|
+
return;
|
|
48
42
|
}
|
|
49
|
-
yield runGenerator(generator);
|
|
50
43
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
44
|
+
await runGenerator(generator);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const getEnableGenerators = async (generators) => {
|
|
48
|
+
var _a;
|
|
49
|
+
const questions = [];
|
|
50
|
+
for (const key of Object.keys(generators)) {
|
|
51
|
+
const g = generators[key];
|
|
52
|
+
if (g.type === generator_1.GeneratorType.generate) {
|
|
53
|
+
questions.push({
|
|
54
|
+
title: `${g.name} -- ${g.description}` || '',
|
|
55
|
+
value: g.key,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const enable = await ((_a = g === null || g === void 0 ? void 0 : g.checkEnable) === null || _a === void 0 ? void 0 : _a.call(g, {
|
|
60
|
+
args,
|
|
61
|
+
}));
|
|
62
|
+
if (enable) {
|
|
57
63
|
questions.push({
|
|
58
|
-
title: `${
|
|
59
|
-
|
|
60
|
-
value: generators[key].key,
|
|
64
|
+
title: `${g.name} -- ${g.description}` || '',
|
|
65
|
+
value: g.key,
|
|
61
66
|
});
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}));
|
|
77
|
-
return questions;
|
|
78
|
-
});
|
|
79
|
-
const questions = yield getEnableGenerators(api.service.generators);
|
|
80
|
-
const { gType } = yield (0, utils_1.prompts)({
|
|
81
|
-
type: 'select',
|
|
82
|
-
name: 'gType',
|
|
83
|
-
message: 'Pick generator type',
|
|
84
|
-
choices: questions,
|
|
85
|
-
});
|
|
86
|
-
yield runGenerator(api.service.generators[gType]);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return questions;
|
|
71
|
+
};
|
|
72
|
+
const questions = await getEnableGenerators(api.service.generators);
|
|
73
|
+
const { gType } = await (0, utils_1.prompts)({
|
|
74
|
+
type: 'select',
|
|
75
|
+
name: 'gType',
|
|
76
|
+
message: 'Pick generator type',
|
|
77
|
+
choices: questions,
|
|
78
|
+
});
|
|
79
|
+
await runGenerator(api.service.generators[gType]);
|
|
80
|
+
}
|
|
89
81
|
},
|
|
90
82
|
});
|
|
91
83
|
};
|
|
@@ -1,34 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateFile } from '@umijs/utils';
|
|
2
2
|
import { Plugin } from './plugin';
|
|
3
|
-
import { PluginAPI } from './pluginAPI';
|
|
4
|
-
import { IServicePluginAPI } from './service';
|
|
5
3
|
export declare enum GeneratorType {
|
|
6
4
|
generate = "generate",
|
|
7
5
|
enable = "enable"
|
|
8
6
|
}
|
|
9
|
-
|
|
7
|
+
declare type IGeneratorOptsWithoutEnableCheck = {
|
|
10
8
|
key: string;
|
|
11
|
-
name
|
|
12
|
-
description
|
|
13
|
-
type
|
|
14
|
-
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
type: GeneratorType.generate;
|
|
12
|
+
fn: {
|
|
13
|
+
(opts: {
|
|
14
|
+
args: any;
|
|
15
|
+
generateFile: typeof generateFile;
|
|
16
|
+
updatePackageJSON: {
|
|
17
|
+
(opts: {
|
|
18
|
+
opts: object;
|
|
19
|
+
cwd?: string;
|
|
20
|
+
}): void;
|
|
21
|
+
};
|
|
22
|
+
installDeps: {
|
|
23
|
+
(opts: {
|
|
24
|
+
opts: {
|
|
25
|
+
devDependencies?: string[];
|
|
26
|
+
dependencies?: string[];
|
|
27
|
+
};
|
|
28
|
+
cwd?: string;
|
|
29
|
+
}): void;
|
|
30
|
+
};
|
|
31
|
+
}): void;
|
|
32
|
+
};
|
|
33
|
+
plugin: Plugin;
|
|
34
|
+
};
|
|
35
|
+
declare type IGeneratorOptsWithEnableCheck = {
|
|
36
|
+
key: string;
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
type: GeneratorType.enable;
|
|
40
|
+
checkEnable: {
|
|
15
41
|
(opts: {
|
|
16
42
|
args: any;
|
|
17
|
-
api: PluginAPI & IServicePluginAPI;
|
|
18
43
|
}): boolean;
|
|
19
44
|
};
|
|
45
|
+
disabledDescription: string | (() => string);
|
|
20
46
|
fn: {
|
|
21
47
|
(opts: {
|
|
22
48
|
args: any;
|
|
23
|
-
|
|
24
|
-
generateFile: {
|
|
25
|
-
(opts: {
|
|
26
|
-
path: string;
|
|
27
|
-
target: string;
|
|
28
|
-
data?: any;
|
|
29
|
-
questions?: prompts.PromptObject[];
|
|
30
|
-
}): void;
|
|
31
|
-
};
|
|
49
|
+
generateFile: typeof generateFile;
|
|
32
50
|
updatePackageJSON: {
|
|
33
51
|
(opts: {
|
|
34
52
|
opts: object;
|
|
@@ -47,14 +65,7 @@ export interface IGeneratorOpts {
|
|
|
47
65
|
}): void;
|
|
48
66
|
};
|
|
49
67
|
plugin: Plugin;
|
|
50
|
-
}
|
|
51
|
-
export declare
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
description?: IGeneratorOpts['description'];
|
|
55
|
-
type?: IGeneratorOpts['type'];
|
|
56
|
-
checkEnable?: IGeneratorOpts['checkEnable'];
|
|
57
|
-
fn: IGeneratorOpts['fn'];
|
|
58
|
-
plugin: IGeneratorOpts['plugin'];
|
|
59
|
-
constructor(opts: IGeneratorOpts);
|
|
60
|
-
}
|
|
68
|
+
};
|
|
69
|
+
export declare type Generator = IGeneratorOptsWithEnableCheck | IGeneratorOptsWithoutEnableCheck;
|
|
70
|
+
export declare function makeGenerator<T>(opts: T): T;
|
|
71
|
+
export {};
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.makeGenerator = exports.GeneratorType = void 0;
|
|
4
4
|
var GeneratorType;
|
|
5
5
|
(function (GeneratorType) {
|
|
6
6
|
GeneratorType["generate"] = "generate";
|
|
7
7
|
GeneratorType["enable"] = "enable";
|
|
8
8
|
})(GeneratorType = exports.GeneratorType || (exports.GeneratorType = {}));
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.type = opts.type;
|
|
14
|
-
this.description = opts.description;
|
|
15
|
-
this.checkEnable = opts.checkEnable;
|
|
16
|
-
this.fn = opts.fn;
|
|
17
|
-
this.plugin = opts.plugin;
|
|
18
|
-
}
|
|
9
|
+
function makeGenerator(opts) {
|
|
10
|
+
return {
|
|
11
|
+
...opts,
|
|
12
|
+
};
|
|
19
13
|
}
|
|
20
|
-
exports.
|
|
14
|
+
exports.makeGenerator = makeGenerator;
|
package/dist/service/path.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export declare function getPaths(opts: {
|
|
|
7
7
|
cwd: string;
|
|
8
8
|
absSrcPath: string;
|
|
9
9
|
absPagesPath: string;
|
|
10
|
+
absApiRoutesPath: string;
|
|
10
11
|
absTmpPath: string;
|
|
11
12
|
absNodeModulesPath: string;
|
|
12
13
|
absOutputPath: string;
|
|
13
14
|
};
|
|
15
|
+
export declare type Paths = ReturnType<typeof getPaths>;
|
package/dist/service/path.js
CHANGED
|
@@ -13,6 +13,7 @@ function getPaths(opts) {
|
|
|
13
13
|
const src = winJoin(cwd, 'src');
|
|
14
14
|
const absSrcPath = (0, fs_1.existsSync)(src) && (0, fs_1.statSync)(src).isDirectory() ? src : cwd;
|
|
15
15
|
const absPagesPath = winJoin(absSrcPath, 'pages');
|
|
16
|
+
const absApiRoutesPath = winJoin(absSrcPath, 'api');
|
|
16
17
|
const tmp = opts.env === types_1.Env.development
|
|
17
18
|
? `.${opts.prefix}`
|
|
18
19
|
: `.${opts.prefix}-${opts.env}`;
|
|
@@ -23,6 +24,7 @@ function getPaths(opts) {
|
|
|
23
24
|
cwd,
|
|
24
25
|
absSrcPath,
|
|
25
26
|
absPagesPath,
|
|
27
|
+
absApiRoutesPath,
|
|
26
28
|
absTmpPath,
|
|
27
29
|
absNodeModulesPath,
|
|
28
30
|
absOutputPath,
|
package/dist/service/plugin.d.ts
CHANGED
package/dist/service/plugin.js
CHANGED
|
@@ -17,6 +17,7 @@ const RE = {
|
|
|
17
17
|
class Plugin {
|
|
18
18
|
constructor(opts) {
|
|
19
19
|
this.config = {};
|
|
20
|
+
this.time = { hooks: {} };
|
|
20
21
|
this.enableBy = types_1.EnableBy.register;
|
|
21
22
|
this.type = opts.type;
|
|
22
23
|
this.path = (0, utils_1.winPath)(opts.path);
|
|
@@ -37,6 +38,7 @@ class Plugin {
|
|
|
37
38
|
this.apply = () => {
|
|
38
39
|
utils_1.register.register({
|
|
39
40
|
implementor: esbuild_1.default,
|
|
41
|
+
exts: ['.ts', '.mjs'],
|
|
40
42
|
});
|
|
41
43
|
utils_1.register.clearFiles();
|
|
42
44
|
let ret;
|
|
@@ -46,10 +48,9 @@ class Plugin {
|
|
|
46
48
|
catch (e) {
|
|
47
49
|
throw new Error(`Register ${this.type} ${this.path} failed, since ${e.message}`);
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
finally {
|
|
52
|
+
utils_1.register.restore();
|
|
51
53
|
}
|
|
52
|
-
utils_1.register.restore();
|
|
53
54
|
// use the default member for es modules
|
|
54
55
|
return ret.__esModule ? ret.default : ret;
|
|
55
56
|
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { logger } from '@umijs/utils';
|
|
2
2
|
import { EnableBy, Env, IPluginConfig } from '../types';
|
|
3
3
|
import { IOpts as ICommandOpts } from './command';
|
|
4
|
-
import {
|
|
4
|
+
import { Generator } from './generator';
|
|
5
5
|
import { IOpts as IHookOpts } from './hook';
|
|
6
6
|
import { Plugin } from './plugin';
|
|
7
7
|
import { Service } from './service';
|
|
8
8
|
declare type Logger = typeof logger;
|
|
9
|
+
declare const resolveConfigModes: readonly ["strict", "loose"];
|
|
10
|
+
export declare type ResolveConfigMode = typeof resolveConfigModes[number];
|
|
11
|
+
declare type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
9
12
|
export declare class PluginAPI {
|
|
10
13
|
service: Service;
|
|
11
14
|
plugin: Plugin;
|
|
@@ -25,7 +28,7 @@ export declare class PluginAPI {
|
|
|
25
28
|
registerCommand(opts: Omit<ICommandOpts, 'plugin'> & {
|
|
26
29
|
alias?: string | string[];
|
|
27
30
|
}): void;
|
|
28
|
-
registerGenerator(opts:
|
|
31
|
+
registerGenerator(opts: DistributiveOmit<Generator, 'plugin'>): void;
|
|
29
32
|
register(opts: Omit<IHookOpts, 'plugin'>): void;
|
|
30
33
|
registerMethod(opts: {
|
|
31
34
|
name: string;
|
|
@@ -33,7 +36,7 @@ export declare class PluginAPI {
|
|
|
33
36
|
}): void;
|
|
34
37
|
registerPresets(source: Plugin[], presets: any[]): void;
|
|
35
38
|
registerPlugins(source: Plugin[], plugins: any[]): void;
|
|
36
|
-
skipPlugins(
|
|
39
|
+
skipPlugins(keys: string[]): void;
|
|
37
40
|
static proxyPluginAPI(opts: {
|
|
38
41
|
pluginAPI: PluginAPI;
|
|
39
42
|
service: Service;
|