mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-25 11:06:36 +08:00
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
import { readFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
import { name } from '../package.json';
|
|
|
|
const namespace = 'plugin-enums';
|
|
|
|
export default (api) => {
|
|
const {
|
|
utils: { Mustache },
|
|
} = api;
|
|
|
|
api.describe({
|
|
key: 'enums',
|
|
config: {
|
|
schema(joi) {
|
|
return joi.object();
|
|
},
|
|
onChange: api.ConfigChangeType.regenerateTmpFiles,
|
|
},
|
|
});
|
|
|
|
const absoluteFilePath = join(namespace, 'core.js');
|
|
api.onGenerateFiles(() => {
|
|
// 文件写出
|
|
const enums = api.config.enums || {};
|
|
api.writeTmpFile({
|
|
path: absoluteFilePath,
|
|
content: Mustache.render(readFileSync(join(__dirname, 'runtime/core.tpl'), 'utf-8'), {
|
|
REPLACE_ENUMS: JSON.stringify(enums),
|
|
}),
|
|
});
|
|
|
|
api.copyTmpFiles({
|
|
namespace,
|
|
path: join(__dirname, 'runtime'),
|
|
ignore: ['.tpl'],
|
|
});
|
|
});
|
|
|
|
api.addPluginExports(() => [
|
|
{
|
|
specifiers: ['enums'],
|
|
source: absoluteFilePath,
|
|
},
|
|
]);
|
|
|
|
api.addConfigType(() => ({
|
|
source: name,
|
|
build: ['EnumsBuildConfig'],
|
|
}));
|
|
};
|