mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
* fix: 优化类型提示 * fix: 添加 enums 接口类型声明 * feat: 配置插件api提示 Co-authored-by: wanchun <445436867@qq.com>
66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
import { readFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
import { winPath } from '@fesjs/utils';
|
|
import { parseStore } from './helper';
|
|
import { name } from '../package.json';
|
|
|
|
const namespace = 'plugin-vuex';
|
|
|
|
export default (api) => {
|
|
const {
|
|
paths,
|
|
utils: { Mustache },
|
|
} = api;
|
|
|
|
api.describe({
|
|
key: 'vuex',
|
|
config: {
|
|
schema(joi) {
|
|
return joi.object();
|
|
},
|
|
onChange: api.ConfigChangeType.regenerateTmpFiles,
|
|
},
|
|
});
|
|
|
|
const absCoreFilePath = join(namespace, 'core.js');
|
|
const absRuntimeFilePath = join(namespace, 'runtime.js');
|
|
api.onGenerateFiles(() => {
|
|
const root = winPath(join(paths.absSrcPath, api.config.singular ? 'store' : 'stores'));
|
|
const store = parseStore(root);
|
|
const vuexConfig = api.config.vuex || {};
|
|
// 文件写出
|
|
api.writeTmpFile({
|
|
path: absCoreFilePath,
|
|
content: Mustache.render(readFileSync(join(__dirname, 'runtime/core.tpl'), 'utf-8'), {
|
|
IMPORT_MODULES: store.importModules.join('\n'),
|
|
IMPORT_PLUGINS: store.importPlugins.join('\n'),
|
|
MODULES: `{ ${store.modules.join(', ')} }`,
|
|
PLUGINS: `[${store.plugins.join(', ')}]`,
|
|
MUTATION_TYPES: JSON.stringify(store.MUTATION_TYPES),
|
|
ACTION_TYPES: JSON.stringify(store.ACTION_TYPES),
|
|
GETTER_TYPES: JSON.stringify(store.GETTER_TYPES),
|
|
VUEX_CONFIG: JSON.stringify(vuexConfig),
|
|
}),
|
|
});
|
|
|
|
api.copyTmpFiles({
|
|
namespace,
|
|
path: join(__dirname, 'runtime'),
|
|
ignore: ['.tpl'],
|
|
});
|
|
});
|
|
|
|
api.addPluginExports(() => [
|
|
{
|
|
specifiers: ['MUTATION_TYPES', 'ACTION_TYPES', 'GETTER_TYPES', 'store'],
|
|
source: absCoreFilePath,
|
|
},
|
|
]);
|
|
|
|
api.addRuntimePlugin(() => `@@/${absRuntimeFilePath}`);
|
|
|
|
api.addConfigType(() => ({
|
|
source: name,
|
|
}));
|
|
};
|