@umijs/core 3.5.18 → 4.0.0-beta.2
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/dist/config/config.d.ts +63 -0
- package/dist/config/config.js +182 -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 +2 -0
- package/dist/route/route.js +18 -0
- package/dist/route/routeUtils.d.ts +7 -0
- package/dist/route/routeUtils.js +21 -0
- package/dist/route/routesConfig.d.ts +0 -0
- package/dist/route/routesConfig.js +1 -0
- package/dist/route/routesConvention.d.ts +3 -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 +53 -0
- package/dist/service/plugin.js +137 -0
- package/dist/service/pluginAPI.d.ts +37 -0
- package/dist/service/pluginAPI.js +127 -0
- package/dist/service/service.d.ts +94 -0
- package/dist/service/service.js +342 -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 +35 -15
- 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
package/README.md
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Env } from '../types';
|
|
2
|
+
interface IOpts {
|
|
3
|
+
cwd: string;
|
|
4
|
+
env: Env;
|
|
5
|
+
specifiedEnv?: string;
|
|
6
|
+
defaultConfigFiles?: string[];
|
|
7
|
+
}
|
|
8
|
+
declare type ISchema = Record<string, any>;
|
|
9
|
+
declare type IOnChangeTypes = Record<string, string | Function>;
|
|
10
|
+
export declare class Config {
|
|
11
|
+
opts: IOpts;
|
|
12
|
+
mainConfigFile: string | null;
|
|
13
|
+
prevConfig: any;
|
|
14
|
+
files: string[];
|
|
15
|
+
constructor(opts: IOpts);
|
|
16
|
+
getUserConfig(): {
|
|
17
|
+
config: {};
|
|
18
|
+
files: string[];
|
|
19
|
+
};
|
|
20
|
+
getConfig(opts: {
|
|
21
|
+
schemas: ISchema;
|
|
22
|
+
}): {
|
|
23
|
+
config: {};
|
|
24
|
+
files: string[];
|
|
25
|
+
};
|
|
26
|
+
watch(opts: {
|
|
27
|
+
schemas: ISchema;
|
|
28
|
+
onChangeTypes: IOnChangeTypes;
|
|
29
|
+
onChange: (opts: {
|
|
30
|
+
data: ReturnType<typeof Config.diffConfigs>;
|
|
31
|
+
event: string;
|
|
32
|
+
path: string;
|
|
33
|
+
}) => Promise<void>;
|
|
34
|
+
}): () => Promise<void>;
|
|
35
|
+
static getMainConfigFile(opts: {
|
|
36
|
+
cwd: string;
|
|
37
|
+
defaultConfigFiles?: string[];
|
|
38
|
+
}): string | null;
|
|
39
|
+
static getConfigFiles(opts: {
|
|
40
|
+
mainConfigFile: string | null;
|
|
41
|
+
env: Env;
|
|
42
|
+
specifiedEnv?: string;
|
|
43
|
+
}): string[];
|
|
44
|
+
static getUserConfig(opts: {
|
|
45
|
+
configFiles: string[];
|
|
46
|
+
}): {
|
|
47
|
+
config: {};
|
|
48
|
+
files: string[];
|
|
49
|
+
};
|
|
50
|
+
static validateConfig(opts: {
|
|
51
|
+
config: any;
|
|
52
|
+
schemas: ISchema;
|
|
53
|
+
}): void;
|
|
54
|
+
static diffConfigs(opts: {
|
|
55
|
+
origin: any;
|
|
56
|
+
updated: any;
|
|
57
|
+
onChangeTypes: IOnChangeTypes;
|
|
58
|
+
}): {
|
|
59
|
+
changes: Record<string, string[]>;
|
|
60
|
+
fns: Function[];
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
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.Config = void 0;
|
|
7
|
+
const esbuild_1 = __importDefault(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
8
|
+
const utils_1 = require("@umijs/utils");
|
|
9
|
+
const assert_1 = __importDefault(require("assert"));
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const joi_1 = __importDefault(require("../../compiled/@hapi/joi"));
|
|
13
|
+
const just_diff_1 = require("../../compiled/just-diff");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
15
|
+
const utils_2 = require("./utils");
|
|
16
|
+
class Config {
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
this.files = [];
|
|
19
|
+
this.opts = opts;
|
|
20
|
+
this.mainConfigFile = Config.getMainConfigFile(this.opts);
|
|
21
|
+
this.prevConfig = null;
|
|
22
|
+
}
|
|
23
|
+
getUserConfig() {
|
|
24
|
+
const configFiles = Config.getConfigFiles({
|
|
25
|
+
mainConfigFile: this.mainConfigFile,
|
|
26
|
+
env: this.opts.env,
|
|
27
|
+
specifiedEnv: this.opts.specifiedEnv,
|
|
28
|
+
});
|
|
29
|
+
return Config.getUserConfig({
|
|
30
|
+
configFiles: (0, utils_2.getAbsFiles)({
|
|
31
|
+
files: configFiles,
|
|
32
|
+
cwd: this.opts.cwd,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getConfig(opts) {
|
|
37
|
+
const { config, files } = this.getUserConfig();
|
|
38
|
+
Config.validateConfig({ config, schemas: opts.schemas });
|
|
39
|
+
this.files = files;
|
|
40
|
+
return (this.prevConfig = {
|
|
41
|
+
config: config,
|
|
42
|
+
files,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
watch(opts) {
|
|
46
|
+
const watcher = utils_1.chokidar.watch([
|
|
47
|
+
...this.files,
|
|
48
|
+
...(this.mainConfigFile
|
|
49
|
+
? []
|
|
50
|
+
: (0, utils_2.getAbsFiles)({
|
|
51
|
+
files: this.opts.defaultConfigFiles || constants_1.DEFAULT_CONFIG_FILES,
|
|
52
|
+
cwd: this.opts.cwd,
|
|
53
|
+
})),
|
|
54
|
+
], {
|
|
55
|
+
ignoreInitial: true,
|
|
56
|
+
cwd: this.opts.cwd,
|
|
57
|
+
});
|
|
58
|
+
watcher.on('all', utils_1.lodash.debounce((event, path) => {
|
|
59
|
+
const { config: origin } = this.prevConfig;
|
|
60
|
+
const { config: updated, files } = this.getConfig({
|
|
61
|
+
schemas: opts.schemas,
|
|
62
|
+
});
|
|
63
|
+
watcher.add(files);
|
|
64
|
+
const data = Config.diffConfigs({
|
|
65
|
+
origin,
|
|
66
|
+
updated,
|
|
67
|
+
onChangeTypes: opts.onChangeTypes,
|
|
68
|
+
});
|
|
69
|
+
opts
|
|
70
|
+
.onChange({
|
|
71
|
+
data,
|
|
72
|
+
event,
|
|
73
|
+
path,
|
|
74
|
+
})
|
|
75
|
+
.catch((e) => {
|
|
76
|
+
throw new Error(e);
|
|
77
|
+
});
|
|
78
|
+
}, constants_1.WATCH_DEBOUNCE_STEP));
|
|
79
|
+
return () => watcher.close();
|
|
80
|
+
}
|
|
81
|
+
static getMainConfigFile(opts) {
|
|
82
|
+
let mainConfigFile = null;
|
|
83
|
+
for (const configFile of opts.defaultConfigFiles || constants_1.DEFAULT_CONFIG_FILES) {
|
|
84
|
+
const absConfigFile = (0, path_1.join)(opts.cwd, configFile);
|
|
85
|
+
if ((0, fs_1.existsSync)(absConfigFile)) {
|
|
86
|
+
mainConfigFile = absConfigFile;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return mainConfigFile;
|
|
91
|
+
}
|
|
92
|
+
static getConfigFiles(opts) {
|
|
93
|
+
const ret = [];
|
|
94
|
+
const { mainConfigFile } = opts;
|
|
95
|
+
const specifiedEnv = opts.specifiedEnv || '';
|
|
96
|
+
if (mainConfigFile) {
|
|
97
|
+
const env = constants_1.SHORT_ENV[opts.env] || opts.env;
|
|
98
|
+
ret.push(...[
|
|
99
|
+
mainConfigFile,
|
|
100
|
+
specifiedEnv &&
|
|
101
|
+
(0, utils_2.addExt)({ file: mainConfigFile, ext: `.${specifiedEnv}` }),
|
|
102
|
+
(0, utils_2.addExt)({ file: mainConfigFile, ext: `.${env}` }),
|
|
103
|
+
specifiedEnv &&
|
|
104
|
+
(0, utils_2.addExt)({
|
|
105
|
+
file: mainConfigFile,
|
|
106
|
+
ext: `.${env}.${specifiedEnv}`,
|
|
107
|
+
}),
|
|
108
|
+
(0, utils_2.addExt)({ file: mainConfigFile, ext: constants_1.LOCAL_EXT }),
|
|
109
|
+
].filter(Boolean));
|
|
110
|
+
}
|
|
111
|
+
return ret;
|
|
112
|
+
}
|
|
113
|
+
static getUserConfig(opts) {
|
|
114
|
+
let config = {};
|
|
115
|
+
let files = [];
|
|
116
|
+
for (const configFile of opts.configFiles) {
|
|
117
|
+
files.push(configFile);
|
|
118
|
+
if ((0, fs_1.existsSync)(configFile)) {
|
|
119
|
+
utils_1.register.register({
|
|
120
|
+
implementor: esbuild_1.default,
|
|
121
|
+
});
|
|
122
|
+
utils_1.register.clearFiles();
|
|
123
|
+
config = utils_1.lodash.merge(config, require(configFile).default);
|
|
124
|
+
for (const file of utils_1.register.getFiles()) {
|
|
125
|
+
delete require.cache[file];
|
|
126
|
+
}
|
|
127
|
+
files.push(...utils_1.register.getFiles());
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
config,
|
|
132
|
+
files,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
static validateConfig(opts) {
|
|
136
|
+
const errors = new Map();
|
|
137
|
+
const configKeys = new Set(Object.keys(opts.config));
|
|
138
|
+
for (const key of Object.keys(opts.schemas)) {
|
|
139
|
+
configKeys.delete(key);
|
|
140
|
+
if (!opts.config[key])
|
|
141
|
+
continue;
|
|
142
|
+
const schema = opts.schemas[key](joi_1.default);
|
|
143
|
+
// invalid schema
|
|
144
|
+
(0, assert_1.default)(joi_1.default.isSchema(schema), `schema for config ${key} is not valid.`);
|
|
145
|
+
const { error } = schema.validate(opts.config[key]);
|
|
146
|
+
if (error)
|
|
147
|
+
errors.set(key, error);
|
|
148
|
+
}
|
|
149
|
+
// invalid config values
|
|
150
|
+
(0, assert_1.default)(errors.size === 0, `Invalid config values: ${Array.from(errors.keys()).join(', ')}
|
|
151
|
+
${Array.from(errors.keys()).map((key) => {
|
|
152
|
+
return `Invalid value for ${key}:\n${errors.get(key).message}`;
|
|
153
|
+
})}`);
|
|
154
|
+
// invalid config keys
|
|
155
|
+
(0, assert_1.default)(configKeys.size === 0, `Invalid config keys: ${Array.from(configKeys).join(', ')}`);
|
|
156
|
+
}
|
|
157
|
+
static diffConfigs(opts) {
|
|
158
|
+
const patch = (0, just_diff_1.diff)(opts.origin, opts.updated);
|
|
159
|
+
const changes = {};
|
|
160
|
+
const fns = [];
|
|
161
|
+
for (const item of patch) {
|
|
162
|
+
const key = item.path[0];
|
|
163
|
+
const onChange = opts.onChangeTypes[key];
|
|
164
|
+
(0, assert_1.default)(onChange, `Invalid onChange config for key ${key}`);
|
|
165
|
+
if (typeof onChange === 'string') {
|
|
166
|
+
changes[onChange] || (changes[onChange] = []);
|
|
167
|
+
changes[onChange].push(String(key));
|
|
168
|
+
}
|
|
169
|
+
else if (typeof onChange === 'function') {
|
|
170
|
+
fns.push(onChange);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
throw new Error(`Invalid onChange value for key ${key}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
changes,
|
|
178
|
+
fns,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.Config = Config;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAbsFiles = exports.addExt = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
function addExt(opts) {
|
|
6
|
+
const index = opts.file.lastIndexOf('.');
|
|
7
|
+
return `${opts.file.slice(0, index)}${opts.ext}${opts.file.slice(index)}`;
|
|
8
|
+
}
|
|
9
|
+
exports.addExt = addExt;
|
|
10
|
+
function getAbsFiles(opts) {
|
|
11
|
+
return opts.files.map((file) => {
|
|
12
|
+
return (0, path_1.isAbsolute)(file) ? file : (0, path_1.join)(opts.cwd, file);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.getAbsFiles = getAbsFiles;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const DEFAULT_CONFIG_FILES: string[];
|
|
2
|
+
export declare const SHORT_ENV: {
|
|
3
|
+
development: string;
|
|
4
|
+
production: string;
|
|
5
|
+
test: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const LOCAL_EXT = ".local";
|
|
8
|
+
export declare const WATCH_DEBOUNCE_STEP = 300;
|
|
9
|
+
export declare const DEFAULT_FRAMEWORK_NAME = "umi";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_FRAMEWORK_NAME = exports.WATCH_DEBOUNCE_STEP = exports.LOCAL_EXT = exports.SHORT_ENV = exports.DEFAULT_CONFIG_FILES = void 0;
|
|
4
|
+
exports.DEFAULT_CONFIG_FILES = ['config.ts', 'config.js'];
|
|
5
|
+
exports.SHORT_ENV = {
|
|
6
|
+
development: 'dev',
|
|
7
|
+
production: 'prod',
|
|
8
|
+
test: 'test',
|
|
9
|
+
};
|
|
10
|
+
exports.LOCAL_EXT = '.local';
|
|
11
|
+
exports.WATCH_DEBOUNCE_STEP = 300;
|
|
12
|
+
exports.DEFAULT_FRAMEWORK_NAME = 'umi';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './config/config';
|
|
2
|
+
export * from './route/route';
|
|
3
|
+
export { GeneratorType, IGeneratorOpts } from './service/generator';
|
|
4
|
+
export * from './service/pluginAPI';
|
|
5
|
+
export * from './service/service';
|
|
6
|
+
export { Env, IAdd, IEvent, IModify, IRoute } from './types';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.Env = exports.GeneratorType = void 0;
|
|
14
|
+
__exportStar(require("./config/config"), exports);
|
|
15
|
+
__exportStar(require("./route/route"), exports);
|
|
16
|
+
var generator_1 = require("./service/generator");
|
|
17
|
+
Object.defineProperty(exports, "GeneratorType", { enumerable: true, get: function () { return generator_1.GeneratorType; } });
|
|
18
|
+
__exportStar(require("./service/pluginAPI"), exports);
|
|
19
|
+
__exportStar(require("./service/service"), exports);
|
|
20
|
+
var types_1 = require("./types");
|
|
21
|
+
Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return types_1.Env; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function defineRoutes(callback: (defineRoute: Function) => void): any;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineRoutes = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
function defineRoutes(callback) {
|
|
6
|
+
const routes = Object.create(null);
|
|
7
|
+
const parentRoutes = [];
|
|
8
|
+
const defineRoute = (opts) => {
|
|
9
|
+
opts.options = opts.options || {};
|
|
10
|
+
const route = {
|
|
11
|
+
path: opts.path || '/',
|
|
12
|
+
id: (0, utils_1.createRouteId)(opts.file),
|
|
13
|
+
parentId: parentRoutes.length > 0
|
|
14
|
+
? parentRoutes[parentRoutes.length - 1].id
|
|
15
|
+
: undefined,
|
|
16
|
+
file: opts.file,
|
|
17
|
+
};
|
|
18
|
+
routes[route.id] = route;
|
|
19
|
+
if (opts.children) {
|
|
20
|
+
parentRoutes.push(route);
|
|
21
|
+
opts.children();
|
|
22
|
+
parentRoutes.pop();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
callback(defineRoute);
|
|
26
|
+
return routes;
|
|
27
|
+
}
|
|
28
|
+
exports.defineRoutes = defineRoutes;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO
|
|
3
|
+
// [x] convention route
|
|
4
|
+
// config route
|
|
5
|
+
// programming route
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./routesConvention"), exports);
|
|
18
|
+
__exportStar(require("./routeUtils"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addParentRoute = void 0;
|
|
4
|
+
function addParentRoute(opts) {
|
|
5
|
+
if (opts.addToAll) {
|
|
6
|
+
for (const id of Object.keys(opts.routes)) {
|
|
7
|
+
if (opts.routes[id].parentId === undefined) {
|
|
8
|
+
opts.routes[id].parentId = opts.target.id;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else if (opts.id) {
|
|
13
|
+
opts.routes[opts.id].parentId = opts.target.id;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
throw new Error(`addParentRoute failed, opts.addToAll or opts.id must be supplied.`);
|
|
17
|
+
}
|
|
18
|
+
// add new route
|
|
19
|
+
opts.routes[opts.target.id] = opts.target;
|
|
20
|
+
}
|
|
21
|
+
exports.addParentRoute = addParentRoute;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -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: 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;
|