qlin b0797260fc feat: 添加 login 插件 (#168)
* feat: 添加 login 插件

* docs: 优化 access docs 文档

* refactor: beforeRender迁移到router创建后

* fix: 修复清除webpack-cache问题

* refactor: 优化 plugin 插件

Co-authored-by: wanchun <445436867@qq.com>
2023-01-11 15:51:43 +08:00

61 lines
1.5 KiB
JavaScript

import { readFileSync } from 'fs';
import { join } from 'path';
import { winPath } from '@fesjs/utils';
import { name } from '../package.json';
import { parseStore } from './helper';
const namespace = 'plugin-pinia';
export default (api) => {
const {
paths,
utils: { Mustache },
} = api;
api.describe({
key: 'pinia',
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);
// 文件写出
api.writeTmpFile({
path: absCoreFilePath,
content: Mustache.render(readFileSync(join(__dirname, 'runtime/core.tpl'), 'utf-8'), {
IMPORT_PLUGINS: store.importPlugins.join('\n'),
PLUGINS: store.plugins,
}),
});
api.copyTmpFiles({
namespace,
path: join(__dirname, 'runtime'),
ignore: ['.tpl'],
});
});
api.addPluginExports(() => [
{
specifiers: ['pinia'],
source: absCoreFilePath,
},
]);
api.addRuntimePlugin(() => `@@/${absRuntimeFilePath}`);
api.addConfigType(() => ({
source: name,
}));
};