Skip to content

Commit 28498a3

Browse files
committed
feat(重写构建): 重写构建
1 parent a49f328 commit 28498a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3623
-2620
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# http://editorconfig.org
22

33
root = true
4+
lib
45

56
[*]
67
charset = utf-8

.fatherrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { join } from 'path';
33

44
// utils must build before core
55
// runtime must build before renderer-react
6-
const headPkgs = ['fes-runtime', 'fes-core'];
6+
const headPkgs = ['fes-runtime', 'fes-core', 'fes', 'fes-plugin-built-in'];
77
const tailPkgs = [];
88
// const otherPkgs = readdirSync(join(__dirname, 'packages')).filter(
99
// (pkg) =>
File renamed without changes.

packages/fes-core/src/Config/Config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ export default class Config {
196196
return {};
197197
}
198198

199-
// @ts-ignore
200-
// @ts-ignore
201199
addAffix(file, affix) {
202200
const ext = extname(file);
203201
return file.replace(new RegExp(`${ext}$`), `.${affix}${ext}`);

packages/fes-core/src/Service/PluginAPI.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from 'assert';
22
import * as utils from '@umijs/utils';
33
import { isValidPlugin, pathToObj } from './utils/pluginUtils';
44
import { EnableBy, PluginType, ServiceStage } from './enums';
5-
5+
import Logger from '../logger/logger';
66
// TODO
77
// 标准化 logger
88
export default class PluginAPI {
@@ -11,6 +11,7 @@ export default class PluginAPI {
1111
this.key = opts.key;
1212
this.service = opts.service;
1313
this.utils = utils;
14+
this.logger = new Logger(`fes:plugin:${this.id || this.key}`);
1415
}
1516

1617
// TODO: reversed keys

packages/fes-core/src/Service/Service.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,7 @@ export default class Service extends EventEmitter {
180180
// 1. merge default config
181181
// 2. validate
182182
this.setStage(ServiceStage.getConfig);
183-
const defaultConfig = await this.applyPlugins({
184-
key: 'modifyDefaultConfig',
185-
type: this.ApplyPluginsType.modify,
186-
initialValue: await this.configInstance.getDefaultConfig()
187-
});
188-
this.config = await this.applyPlugins({
189-
key: 'modifyConfig',
190-
type: this.ApplyPluginsType.modify,
191-
initialValue: this.configInstance.getConfig({
192-
defaultConfig
193-
})
194-
});
183+
await this.setConfig();
195184

196185
// merge paths to keep the this.paths ref
197186
this.setStage(ServiceStage.getPaths);
@@ -209,6 +198,21 @@ export default class Service extends EventEmitter {
209198
});
210199
}
211200

201+
async setConfig() {
202+
const defaultConfig = await this.applyPlugins({
203+
key: 'modifyDefaultConfig',
204+
type: this.ApplyPluginsType.modify,
205+
initialValue: await this.configInstance.getDefaultConfig()
206+
});
207+
this.config = await this.applyPlugins({
208+
key: 'modifyConfig',
209+
type: this.ApplyPluginsType.modify,
210+
initialValue: this.configInstance.getConfig({
211+
defaultConfig
212+
})
213+
});
214+
}
215+
212216
async initPlugins() {
213217
this._extraPlugins = [];
214218
this.setStage(ServiceStage.initPlugins);
@@ -257,7 +261,8 @@ export default class Service extends EventEmitter {
257261
'config',
258262
'env',
259263
'args',
260-
'hasPlugins'
264+
'hasPlugins',
265+
'setConfig'
261266
].includes(prop)
262267
) {
263268
return typeof this[prop] === 'function'
@@ -422,13 +427,6 @@ export default class Service extends EventEmitter {
422427
this.args = args;
423428
await this.init();
424429

425-
// TODO 临时实现
426-
await this.applyPlugins({
427-
key: 'onGenerateFiles',
428-
type: ApplyPluginsType.event
429-
});
430-
431-
432430
this.setStage(ServiceStage.run);
433431
await this.applyPlugins({
434432
key: 'onStart',
@@ -437,11 +435,11 @@ export default class Service extends EventEmitter {
437435
args
438436
}
439437
});
440-
// TODO 执行命令
441-
// return this.runCommand({
442-
// name,
443-
// args
444-
// });
438+
439+
return this.runCommand({
440+
name,
441+
args
442+
});
445443
}
446444

447445
async runCommand({

packages/fes-core/src/Service/utils/pluginUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function pathToObj({ path, cwd }) {
7373
} else {
7474
id = winPath(path);
7575
}
76-
id = id.replace('@webank/fes-core/lib/plugins', '@@');
76+
id = id.replace('@webank/fes-plugin-built-in/lib/plugins', '@@');
7777
id = id.replace(/\.js$/, '');
7878

7979
const key = isPkgPlugin

packages/fes-core/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import Config from './Config/Config';
44
import Service from './Service/Service';
55
import PluginAPI from './Service/PluginAPI';
6+
import Logger from './logger/logger';
67
import { PluginType } from './Service/enums';
78
import { isPlugin } from './Service/utils/pluginUtils';
8-
import ServiceWithBuiltIn from './ServiceWithBuiltIn';
99

1010
export * from './route';
1111

@@ -15,5 +15,5 @@ export {
1515
PluginAPI,
1616
isPlugin,
1717
PluginType,
18-
ServiceWithBuiltIn
18+
Logger
1919
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import {
2+
createDebug,
3+
chalk
4+
} from '@umijs/utils';
5+
6+
export default class Logger {
7+
LOG = chalk.black.bgBlue('LOG');
8+
9+
INFO = chalk.black.bgBlue('INFO');
10+
11+
WARN = chalk.black.bgHex('#faad14')('WARN');
12+
13+
ERROR = chalk.black.bgRed('ERROR');
14+
15+
PROFILE = chalk.black.bgCyan('PROFILE');
16+
17+
constructor(namespace) {
18+
// TODO: get namespace filename accounding caller function
19+
if (!namespace) {
20+
throw new Error('logger needs namespace');
21+
}
22+
this.namespace = namespace;
23+
this.profilers = {};
24+
this.debug = createDebug(this.namespace);
25+
}
26+
27+
log(...args) {
28+
// TODO: node env production
29+
console.log(this.LOG, ...args);
30+
}
31+
32+
/**
33+
* The {@link logger.info} function is an alias for {@link logger.log()}.
34+
* @param args
35+
*/
36+
info(...args) {
37+
console.log(this.INFO, ...args);
38+
}
39+
40+
error(...args) {
41+
console.error(this.ERROR, ...args);
42+
}
43+
44+
warn(...args) {
45+
console.warn(this.WARN, ...args);
46+
}
47+
48+
formatTiming(timing) {
49+
return timing < 60 * 1000
50+
? `${Math.round(timing / 10) / 100}s`
51+
: `${Math.round(timing / 600) / 100}m`;
52+
}
53+
54+
profile(id, message) {
55+
const time = Date.now();
56+
const namespace = `${this.namespace}:${id}`;
57+
// for test
58+
let msg;
59+
if (this.profilers[id]) {
60+
const timeEnd = this.profilers[id];
61+
delete this.profilers[id];
62+
process.stderr.write(`${this.PROFILE} `);
63+
msg = `${this.PROFILE} ${chalk.cyan(
64+
`└ ${namespace}`,
65+
)} Completed in ${this.formatTiming(time - timeEnd)}`;
66+
console.log(msg);
67+
} else {
68+
msg = `${this.PROFILE} ${chalk.cyan(`┌ ${namespace}`)} ${message || ''}`;
69+
console.log(msg);
70+
}
71+
72+
this.profilers[id] = time;
73+
return msg;
74+
}
75+
}

packages/fes-core/src/plugins/index.js

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
disableTypeCheck: false,
3+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@webank/fes-plugin-built-in",
3+
"version": "2.0.0",
4+
"description": "@webank/fes-plugin-built-in",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
7+
"files": [
8+
"lib"
9+
],
10+
"repository": {
11+
"type": "git",
12+
"url": ""
13+
},
14+
"keywords": [
15+
"fes"
16+
],
17+
"authors": [
18+
""
19+
],
20+
"license": "MIT",
21+
"bugs": "",
22+
"homepage": "",
23+
"publishConfig": {
24+
"access": "public"
25+
},
26+
"dependencies": {
27+
"@umijs/utils": "^3.2.24",
28+
"@umijs/bundler-webpack": "^3.2.23",
29+
"@umijs/server": "^3.2.23",
30+
"@vue/babel-plugin-jsx": "^1.0.0-rc.3",
31+
"@webank/fes-core": "^2.0.0",
32+
"cliui": "6.0.0",
33+
"vue-loader": "^16.0.0-rc.1",
34+
"html-webpack-plugin": "^3.2.0"
35+
}
36+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// TODO 拆成独立的包作为内置插件包
2+
3+
export default [
4+
// register methods
5+
require.resolve('./plugins/registerMethods'),
6+
7+
// misc
8+
require.resolve('./plugins/routes'),
9+
10+
// generate files
11+
require.resolve('./plugins/generateFiles/core/plugin'),
12+
require.resolve('./plugins/generateFiles/core/routes'),
13+
require.resolve('./plugins/generateFiles/core/fesExports'),
14+
require.resolve('./plugins/generateFiles/fes'),
15+
16+
// bundle configs
17+
require.resolve('./plugins/features/alias'),
18+
require.resolve('./plugins/features/analyze'),
19+
require.resolve('./plugins/features/autoprefixer'),
20+
require.resolve('./plugins/features/base'),
21+
require.resolve('./plugins/features/chainWebpack'),
22+
require.resolve('./plugins/features/chunks'),
23+
require.resolve('./plugins/features/cssLoader'),
24+
require.resolve('./plugins/features/cssnano'),
25+
require.resolve('./plugins/features/copy'),
26+
require.resolve('./plugins/features/define'),
27+
require.resolve('./plugins/features/devServer'),
28+
require.resolve('./plugins/features/devtool'),
29+
require.resolve('./plugins/features/externals'),
30+
require.resolve('./plugins/features/extraBabelPlugins'),
31+
require.resolve('./plugins/features/extraBabelPresets'),
32+
require.resolve('./plugins/features/extraPostCSSPlugins'),
33+
require.resolve('./plugins/features/hash'),
34+
require.resolve('./plugins/features/html'),
35+
require.resolve('./plugins/features/inlineLimit'),
36+
require.resolve('./plugins/features/lessLoader'),
37+
require.resolve('./plugins/features/mountElementId'),
38+
require.resolve('./plugins/features/nodeModulesTransform'),
39+
require.resolve('./plugins/features/outputPath'),
40+
require.resolve('./plugins/features/plugins'),
41+
require.resolve('./plugins/features/postcssLoader'),
42+
require.resolve('./plugins/features/proxy'),
43+
require.resolve('./plugins/features/publicPath'),
44+
require.resolve('./plugins/features/styleLoader'),
45+
require.resolve('./plugins/features/targets'),
46+
require.resolve('./plugins/features/terserOptions'),
47+
require.resolve('./plugins/features/theme'),
48+
require.resolve('./plugins/features/vueLoader'),
49+
50+
// commands
51+
require.resolve('./plugins/commands/build/build'),
52+
require.resolve('./plugins/commands/dev/dev')
53+
];

0 commit comments

Comments
 (0)