@umijs/core 3.5.20 → 4.0.0-beta.12
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/README.md +2 -0
- package/compiled/@hapi/joi/index.d.ts +2219 -0
- package/compiled/@hapi/joi/index.js +1 -0
- package/compiled/@hapi/joi/package.json +1 -0
- package/compiled/dotenv/LICENSE +23 -0
- package/compiled/dotenv/index.js +1 -0
- package/compiled/dotenv/package.json +1 -0
- package/compiled/dotenv/types/index.d.ts +59 -0
- package/compiled/just-diff/LICENSE +21 -0
- package/compiled/just-diff/index.d.ts +20 -0
- package/compiled/just-diff/index.js +1 -0
- package/compiled/just-diff/package.json +1 -0
- package/compiled/tapable/LICENSE +21 -0
- package/compiled/tapable/index.js +1 -0
- package/compiled/tapable/package.json +1 -0
- package/compiled/tapable/tapable.d.ts +116 -0
- package/dist/config/config.d.ts +63 -0
- package/dist/config/config.js +183 -0
- package/dist/config/utils.d.ts +8 -0
- package/dist/config/utils.js +15 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +21 -0
- package/dist/route/defineRoutes.d.ts +1 -0
- package/dist/route/defineRoutes.js +28 -0
- package/dist/route/route.d.ts +3 -0
- package/dist/route/route.js +19 -0
- package/dist/route/routeUtils.d.ts +7 -0
- package/dist/route/routeUtils.js +21 -0
- package/dist/route/routesConfig.d.ts +5 -0
- package/dist/route/routesConfig.js +37 -0
- package/dist/route/routesConvention.d.ts +4 -0
- package/dist/route/routesConvention.js +73 -0
- package/dist/route/utils.d.ts +7 -0
- package/dist/route/utils.js +26 -0
- package/dist/service/command.d.ts +27 -0
- package/dist/service/command.js +14 -0
- package/dist/service/env.d.ts +4 -0
- package/dist/service/env.js +21 -0
- package/dist/service/generatePlugin.d.ts +4 -0
- package/dist/service/generatePlugin.js +91 -0
- package/dist/service/generator.d.ts +60 -0
- package/dist/service/generator.js +20 -0
- package/dist/service/hook.d.ts +16 -0
- package/dist/service/hook.js +18 -0
- package/dist/service/path.d.ts +13 -0
- package/dist/service/path.js +31 -0
- package/dist/service/plugin.d.ts +56 -0
- package/dist/service/plugin.js +147 -0
- package/dist/service/pluginAPI.d.ts +44 -0
- package/dist/service/pluginAPI.js +146 -0
- package/dist/service/service.d.ts +99 -0
- package/dist/service/service.js +355 -0
- package/dist/service/servicePlugin.d.ts +3 -0
- package/dist/service/servicePlugin.js +14 -0
- package/dist/service/utils.d.ts +2 -0
- package/dist/service/utils.js +12 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.js +42 -0
- package/package.json +42 -21
- package/lib/Config/Config.d.ts +0 -39
- package/lib/Config/Config.js +0 -348
- package/lib/Config/types.d.ts +0 -21
- package/lib/Config/utils/configUtils.d.ts +0 -9
- package/lib/Config/utils/configUtils.js +0 -54
- package/lib/Config/utils/isEqual.d.ts +0 -1
- package/lib/Config/utils/isEqual.js +0 -45
- package/lib/Config/utils/mergeDefault.d.ts +0 -6
- package/lib/Config/utils/mergeDefault.js +0 -41
- package/lib/Html/Html.d.ts +0 -16
- package/lib/Html/Html.js +0 -292
- package/lib/Html/document.ejs +0 -12
- package/lib/Html/types.d.ts +0 -55
- package/lib/Logger/Common.d.ts +0 -13
- package/lib/Logger/Common.js +0 -53
- package/lib/Logger/Logger.d.ts +0 -17
- package/lib/Logger/Logger.js +0 -87
- package/lib/Route/Route.d.ts +0 -32
- package/lib/Route/Route.js +0 -228
- package/lib/Route/getConventionalRoutes.d.ts +0 -10
- package/lib/Route/getConventionalRoutes.js +0 -259
- package/lib/Route/routesToJSON.d.ts +0 -9
- package/lib/Route/routesToJSON.js +0 -140
- package/lib/Route/types.d.ts +0 -11
- package/lib/Service/PluginAPI.d.ts +0 -38
- package/lib/Service/PluginAPI.js +0 -193
- package/lib/Service/Service.d.ts +0 -96
- package/lib/Service/Service.js +0 -694
- package/lib/Service/enums.d.ts +0 -29
- package/lib/Service/enums.js +0 -67
- package/lib/Service/getPaths.d.ts +0 -6
- package/lib/Service/getPaths.js +0 -79
- package/lib/Service/types.d.ts +0 -52
- package/lib/Service/types.js +0 -17
- package/lib/Service/utils/isPromise.d.ts +0 -1
- package/lib/Service/utils/isPromise.js +0 -22
- package/lib/Service/utils/loadDotEnv.d.ts +0 -5
- package/lib/Service/utils/loadDotEnv.js +0 -54
- package/lib/Service/utils/pluginUtils.d.ts +0 -42
- package/lib/Service/utils/pluginUtils.js +0 -201
- package/lib/index.d.ts +0 -14
- package/lib/index.js +0 -81
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getConfigRoutes = void 0;
|
|
15
|
+
function getConfigRoutes(opts) {
|
|
16
|
+
const memo = { ret: {}, id: 1 };
|
|
17
|
+
transformRoutes({ routes: opts.routes, parentId: undefined, memo });
|
|
18
|
+
return memo.ret;
|
|
19
|
+
}
|
|
20
|
+
exports.getConfigRoutes = getConfigRoutes;
|
|
21
|
+
function transformRoutes(opts) {
|
|
22
|
+
opts.routes.forEach((route) => {
|
|
23
|
+
transformRoute({ route, parentId: opts.parentId, memo: opts.memo });
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function transformRoute(opts) {
|
|
27
|
+
const id = String(opts.memo.id++);
|
|
28
|
+
const _a = opts.route, { routes, component } = _a, routeProps = __rest(_a, ["routes", "component"]);
|
|
29
|
+
opts.memo.ret[id] = Object.assign(Object.assign(Object.assign(Object.assign({}, routeProps), { path: opts.route.path }), (component ? { file: component } : {})), { parentId: opts.parentId, id });
|
|
30
|
+
if (opts.route.routes) {
|
|
31
|
+
transformRoutes({
|
|
32
|
+
routes: opts.route.routes,
|
|
33
|
+
parentId: id,
|
|
34
|
+
memo: opts.memo,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getConventionRoutes = void 0;
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const defineRoutes_1 = require("./defineRoutes");
|
|
12
|
+
const utils_2 = require("./utils");
|
|
13
|
+
// opts.base: path of pages
|
|
14
|
+
function getConventionRoutes(opts) {
|
|
15
|
+
const files = {};
|
|
16
|
+
(0, assert_1.default)((0, fs_1.existsSync)(opts.base) && (0, fs_1.statSync)(opts.base).isDirectory(), `Convention routes base not found.`);
|
|
17
|
+
visitFiles({
|
|
18
|
+
dir: opts.base,
|
|
19
|
+
visitor: (file) => {
|
|
20
|
+
const routeId = (0, utils_2.createRouteId)(file);
|
|
21
|
+
if ((0, utils_2.isRouteModuleFile)({ file })) {
|
|
22
|
+
files[routeId] = (0, utils_1.winPath)(file);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error(`Invalid route module file: ${(0, path_1.join)(opts.base, file)}`);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const routeIds = Object.keys(files).sort(utils_2.byLongestFirst);
|
|
30
|
+
function defineNestedRoutes(defineRoute, parentId) {
|
|
31
|
+
const childRouteIds = routeIds.filter((id) => (0, utils_2.findParentRouteId)(routeIds, id) === parentId);
|
|
32
|
+
for (let routeId of childRouteIds) {
|
|
33
|
+
let routePath = createRoutePath(parentId ? routeId.slice(parentId.length + 1) : routeId);
|
|
34
|
+
defineRoute({
|
|
35
|
+
path: routePath,
|
|
36
|
+
file: `${opts.prefix || ''}${files[routeId]}`,
|
|
37
|
+
children() {
|
|
38
|
+
defineNestedRoutes(defineRoute, routeId);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return (0, defineRoutes_1.defineRoutes)(defineNestedRoutes);
|
|
44
|
+
}
|
|
45
|
+
exports.getConventionRoutes = getConventionRoutes;
|
|
46
|
+
function visitFiles(opts) {
|
|
47
|
+
opts.baseDir = opts.baseDir || opts.dir;
|
|
48
|
+
for (let filename of (0, fs_1.readdirSync)(opts.dir)) {
|
|
49
|
+
let file = (0, path_1.resolve)(opts.dir, filename);
|
|
50
|
+
let stat = (0, fs_1.lstatSync)(file);
|
|
51
|
+
if (stat.isDirectory()) {
|
|
52
|
+
visitFiles(Object.assign(Object.assign({}, opts), { dir: file }));
|
|
53
|
+
}
|
|
54
|
+
else if (stat.isFile() &&
|
|
55
|
+
['.tsx', '.ts', '.js', '.jsx'].includes((0, path_1.extname)(file))) {
|
|
56
|
+
opts.visitor((0, path_1.relative)(opts.baseDir, file));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function createRoutePath(routeId) {
|
|
61
|
+
const path = routeId
|
|
62
|
+
// routes/$ -> routes/*
|
|
63
|
+
// routes/nested/$.tsx (with a "routes/nested.tsx" layout)
|
|
64
|
+
.replace(/^\$$/, '*')
|
|
65
|
+
// routes/docs.$ -> routes/docs/*
|
|
66
|
+
// routes/docs/$ -> routes/docs/*
|
|
67
|
+
.replace(/(\/|\.)\$$/, '/*')
|
|
68
|
+
// routes/$user -> routes/:user
|
|
69
|
+
.replace(/\$/g, ':')
|
|
70
|
+
// routes/not.nested -> routes/not/nested
|
|
71
|
+
.replace(/\./g, '/');
|
|
72
|
+
return /\b\/?index$/.test(path) ? path.replace(/\/?index$/, '') : path;
|
|
73
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function createRouteId(file: string): string;
|
|
2
|
+
export declare function stripFileExtension(file: string): string;
|
|
3
|
+
export declare function byLongestFirst(a: string, b: string): number;
|
|
4
|
+
export declare function findParentRouteId(routeIds: string[], childRouteId: string): string | undefined;
|
|
5
|
+
export declare function isRouteModuleFile(opts: {
|
|
6
|
+
file: string;
|
|
7
|
+
}): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRouteModuleFile = exports.findParentRouteId = exports.byLongestFirst = exports.stripFileExtension = exports.createRouteId = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
function createRouteId(file) {
|
|
7
|
+
return (0, utils_1.winPath)(stripFileExtension(file));
|
|
8
|
+
}
|
|
9
|
+
exports.createRouteId = createRouteId;
|
|
10
|
+
function stripFileExtension(file) {
|
|
11
|
+
return file.replace(/\.[a-z0-9]+$/i, '');
|
|
12
|
+
}
|
|
13
|
+
exports.stripFileExtension = stripFileExtension;
|
|
14
|
+
function byLongestFirst(a, b) {
|
|
15
|
+
return b.length - a.length;
|
|
16
|
+
}
|
|
17
|
+
exports.byLongestFirst = byLongestFirst;
|
|
18
|
+
function findParentRouteId(routeIds, childRouteId) {
|
|
19
|
+
return routeIds.find((id) => childRouteId.startsWith(`${id}/`));
|
|
20
|
+
}
|
|
21
|
+
exports.findParentRouteId = findParentRouteId;
|
|
22
|
+
const routeModuleExts = ['.js', '.jsx', '.ts', '.tsx', '.md', '.mdx'];
|
|
23
|
+
function isRouteModuleFile(opts) {
|
|
24
|
+
return routeModuleExts.includes((0, path_1.extname)(opts.file));
|
|
25
|
+
}
|
|
26
|
+
exports.isRouteModuleFile = isRouteModuleFile;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { yParser } from '@umijs/utils';
|
|
2
|
+
import { Plugin } from './plugin';
|
|
3
|
+
export interface IOpts {
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
options?: string;
|
|
7
|
+
details?: string;
|
|
8
|
+
fn: {
|
|
9
|
+
({ args }: {
|
|
10
|
+
args: yParser.Arguments;
|
|
11
|
+
}): void;
|
|
12
|
+
};
|
|
13
|
+
plugin: Plugin;
|
|
14
|
+
}
|
|
15
|
+
export declare class Command {
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
options?: string;
|
|
19
|
+
details?: string;
|
|
20
|
+
fn: {
|
|
21
|
+
({ args }: {
|
|
22
|
+
args: yParser.Arguments;
|
|
23
|
+
}): void;
|
|
24
|
+
};
|
|
25
|
+
plugin: Plugin;
|
|
26
|
+
constructor(opts: IOpts);
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Command = void 0;
|
|
4
|
+
class Command {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
this.name = opts.name;
|
|
7
|
+
this.description = opts.description;
|
|
8
|
+
this.options = opts.options;
|
|
9
|
+
this.details = opts.details;
|
|
10
|
+
this.fn = opts.fn;
|
|
11
|
+
this.plugin = opts.plugin;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Command = Command;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadEnv = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const dotenv_1 = require("../../compiled/dotenv");
|
|
7
|
+
function loadEnv(opts) {
|
|
8
|
+
const files = [
|
|
9
|
+
(0, path_1.join)(opts.cwd, opts.envFile),
|
|
10
|
+
(0, path_1.join)(opts.cwd, `${opts.envFile}.local`),
|
|
11
|
+
];
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
if (!(0, fs_1.existsSync)(file))
|
|
14
|
+
continue;
|
|
15
|
+
const parsed = (0, dotenv_1.parse)((0, fs_1.readFileSync)(file)) || {};
|
|
16
|
+
for (const key of Object.keys(parsed)) {
|
|
17
|
+
process.env[key] = parsed[key];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.loadEnv = loadEnv;
|
|
@@ -0,0 +1,91 @@
|
|
|
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 utils_1 = require("@umijs/utils");
|
|
13
|
+
const generator_1 = require("./generator");
|
|
14
|
+
exports.default = (api) => {
|
|
15
|
+
api.registerCommand({
|
|
16
|
+
name: 'generate',
|
|
17
|
+
alias: 'g',
|
|
18
|
+
details: `
|
|
19
|
+
umi generate
|
|
20
|
+
`,
|
|
21
|
+
description: 'generate code snippets quickly',
|
|
22
|
+
fn({ args }) {
|
|
23
|
+
var _a;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const [type] = args._;
|
|
26
|
+
const runGenerator = (generator) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
yield (generator === null || generator === void 0 ? void 0 : generator.fn({
|
|
28
|
+
api,
|
|
29
|
+
args,
|
|
30
|
+
generateFile: utils_1.generateFile,
|
|
31
|
+
installDeps: utils_1.installDeps,
|
|
32
|
+
updatePackageJSON: utils_1.updatePackageJSON,
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
|
+
if (type) {
|
|
36
|
+
const generator = api.service.generators[type];
|
|
37
|
+
if (!generator) {
|
|
38
|
+
throw new Error(`Generator ${type} not found.`);
|
|
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.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
yield runGenerator(generator);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const getEnableGenerators = (generators) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const questions = [];
|
|
54
|
+
Object.keys(generators).forEach((key) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _b, _c;
|
|
56
|
+
if (generators[key].type === generator_1.GeneratorType.generate) {
|
|
57
|
+
questions.push({
|
|
58
|
+
title: `${generators[key].name} -- ${generators[key].description}` ||
|
|
59
|
+
'',
|
|
60
|
+
value: generators[key].key,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const enable = yield ((_c = (_b = generators[key]) === null || _b === void 0 ? void 0 : _b.checkEnable) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
65
|
+
api,
|
|
66
|
+
args,
|
|
67
|
+
}));
|
|
68
|
+
if (enable) {
|
|
69
|
+
questions.push({
|
|
70
|
+
title: `${generators[key].name} -- ${generators[key].description}` ||
|
|
71
|
+
'',
|
|
72
|
+
value: generators[key].key,
|
|
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
|
+
});
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { prompts } from '@umijs/utils';
|
|
2
|
+
import { Plugin } from './plugin';
|
|
3
|
+
import { PluginAPI } from './pluginAPI';
|
|
4
|
+
import { IServicePluginAPI } from './service';
|
|
5
|
+
export declare enum GeneratorType {
|
|
6
|
+
generate = "generate",
|
|
7
|
+
enable = "enable"
|
|
8
|
+
}
|
|
9
|
+
export interface IGeneratorOpts {
|
|
10
|
+
key: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
type?: GeneratorType;
|
|
14
|
+
checkEnable?: {
|
|
15
|
+
(opts: {
|
|
16
|
+
args: any;
|
|
17
|
+
api: PluginAPI & IServicePluginAPI;
|
|
18
|
+
}): boolean;
|
|
19
|
+
};
|
|
20
|
+
fn: {
|
|
21
|
+
(opts: {
|
|
22
|
+
args: any;
|
|
23
|
+
api: PluginAPI & IServicePluginAPI;
|
|
24
|
+
generateFile: {
|
|
25
|
+
(opts: {
|
|
26
|
+
path: string;
|
|
27
|
+
target: string;
|
|
28
|
+
data?: any;
|
|
29
|
+
questions?: prompts.PromptObject[];
|
|
30
|
+
}): void;
|
|
31
|
+
};
|
|
32
|
+
updatePackageJSON: {
|
|
33
|
+
(opts: {
|
|
34
|
+
opts: object;
|
|
35
|
+
cwd?: string;
|
|
36
|
+
}): void;
|
|
37
|
+
};
|
|
38
|
+
installDeps: {
|
|
39
|
+
(opts: {
|
|
40
|
+
opts: {
|
|
41
|
+
devDependencies?: string[];
|
|
42
|
+
dependencies?: string[];
|
|
43
|
+
};
|
|
44
|
+
cwd?: string;
|
|
45
|
+
}): void;
|
|
46
|
+
};
|
|
47
|
+
}): void;
|
|
48
|
+
};
|
|
49
|
+
plugin: Plugin;
|
|
50
|
+
}
|
|
51
|
+
export declare class Generator {
|
|
52
|
+
key: IGeneratorOpts['key'];
|
|
53
|
+
name?: IGeneratorOpts['name'];
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Generator = exports.GeneratorType = void 0;
|
|
4
|
+
var GeneratorType;
|
|
5
|
+
(function (GeneratorType) {
|
|
6
|
+
GeneratorType["generate"] = "generate";
|
|
7
|
+
GeneratorType["enable"] = "enable";
|
|
8
|
+
})(GeneratorType = exports.GeneratorType || (exports.GeneratorType = {}));
|
|
9
|
+
class Generator {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this.key = opts.key;
|
|
12
|
+
this.name = opts.name;
|
|
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
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Generator = Generator;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Plugin } from './plugin';
|
|
2
|
+
export interface IOpts {
|
|
3
|
+
plugin: Plugin;
|
|
4
|
+
key: string;
|
|
5
|
+
fn: Function;
|
|
6
|
+
before?: string;
|
|
7
|
+
stage?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class Hook {
|
|
10
|
+
plugin: Plugin;
|
|
11
|
+
key: string;
|
|
12
|
+
fn: Function;
|
|
13
|
+
before?: string;
|
|
14
|
+
stage?: number;
|
|
15
|
+
constructor(opts: IOpts);
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Hook = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
class Hook {
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
(0, assert_1.default)(opts.key && opts.fn, `Invalid hook ${opts}, key and fn must supplied.`);
|
|
11
|
+
this.plugin = opts.plugin;
|
|
12
|
+
this.key = opts.key;
|
|
13
|
+
this.fn = opts.fn;
|
|
14
|
+
this.before = opts.before;
|
|
15
|
+
this.stage = opts.stage || 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Hook = Hook;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Env } from '../types';
|
|
2
|
+
export declare function getPaths(opts: {
|
|
3
|
+
cwd: string;
|
|
4
|
+
prefix: string;
|
|
5
|
+
env: Env;
|
|
6
|
+
}): {
|
|
7
|
+
cwd: string;
|
|
8
|
+
absSrcPath: string;
|
|
9
|
+
absPagesPath: string;
|
|
10
|
+
absTmpPath: string;
|
|
11
|
+
absNodeModulesPath: string;
|
|
12
|
+
absOutputPath: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPaths = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
function winJoin(...args) {
|
|
9
|
+
return (0, utils_1.winPath)((0, path_1.join)(...args));
|
|
10
|
+
}
|
|
11
|
+
function getPaths(opts) {
|
|
12
|
+
const cwd = opts.cwd;
|
|
13
|
+
const src = winJoin(cwd, 'src');
|
|
14
|
+
const absSrcPath = (0, fs_1.existsSync)(src) && (0, fs_1.statSync)(src).isDirectory() ? src : cwd;
|
|
15
|
+
const absPagesPath = winJoin(absSrcPath, 'pages');
|
|
16
|
+
const tmp = opts.env === types_1.Env.development
|
|
17
|
+
? `.${opts.prefix}`
|
|
18
|
+
: `.${opts.prefix}-${opts.env}`;
|
|
19
|
+
const absTmpPath = winJoin(absSrcPath, tmp);
|
|
20
|
+
const absNodeModulesPath = winJoin(cwd, 'node_modules');
|
|
21
|
+
const absOutputPath = winJoin(cwd, 'dist');
|
|
22
|
+
return {
|
|
23
|
+
cwd,
|
|
24
|
+
absSrcPath,
|
|
25
|
+
absPagesPath,
|
|
26
|
+
absTmpPath,
|
|
27
|
+
absNodeModulesPath,
|
|
28
|
+
absOutputPath,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.getPaths = getPaths;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EnableBy, Env, IPluginConfig } from '../types';
|
|
2
|
+
declare type PluginType = 'plugin' | 'preset';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
path: string;
|
|
5
|
+
cwd: string;
|
|
6
|
+
type: PluginType;
|
|
7
|
+
}
|
|
8
|
+
export interface IPluginObject {
|
|
9
|
+
id: string;
|
|
10
|
+
key: string;
|
|
11
|
+
apply?: Function;
|
|
12
|
+
config?: IPluginConfig;
|
|
13
|
+
enableBy?: EnableBy | (() => boolean);
|
|
14
|
+
}
|
|
15
|
+
export declare class Plugin {
|
|
16
|
+
private cwd;
|
|
17
|
+
type: PluginType;
|
|
18
|
+
path: string;
|
|
19
|
+
id: string;
|
|
20
|
+
key: string;
|
|
21
|
+
apply: Function;
|
|
22
|
+
config: IPluginConfig;
|
|
23
|
+
enableBy: EnableBy | ((opts: {
|
|
24
|
+
config: any;
|
|
25
|
+
env: Env;
|
|
26
|
+
}) => boolean);
|
|
27
|
+
constructor(opts: IOpts);
|
|
28
|
+
merge(opts: {
|
|
29
|
+
key?: string;
|
|
30
|
+
config?: IPluginConfig;
|
|
31
|
+
enableBy?: any;
|
|
32
|
+
}): void;
|
|
33
|
+
getId(opts: {
|
|
34
|
+
pkg: any;
|
|
35
|
+
isPkgEntry: boolean;
|
|
36
|
+
pkgJSONPath: string | null;
|
|
37
|
+
}): any;
|
|
38
|
+
getKey(opts: {
|
|
39
|
+
pkg: any;
|
|
40
|
+
isPkgEntry: boolean;
|
|
41
|
+
}): string;
|
|
42
|
+
static isPluginOrPreset(type: 'plugin' | 'preset', name: string): boolean;
|
|
43
|
+
static stripNoneUmiScope(name: string): string;
|
|
44
|
+
static getPluginsAndPresets(opts: {
|
|
45
|
+
cwd: string;
|
|
46
|
+
pkg: any;
|
|
47
|
+
userConfig: any;
|
|
48
|
+
plugins?: string[];
|
|
49
|
+
presets?: string[];
|
|
50
|
+
prefix: string;
|
|
51
|
+
}): {
|
|
52
|
+
presets: Plugin[];
|
|
53
|
+
plugins: Plugin[];
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export {};
|