万纯 e43ea5e56c feat: plugin-locale 添加新功能
1. 支持 legacy 配置
2. 支持 share 配置
3. 支持 baseNavigator 配置
4. 添加setLocale方法
5. 添加addLocale方法
6. 添加getAllLocales方法
2021-01-14 19:09:59 +08:00

58 lines
1.3 KiB
JavaScript

import { readFileSync } from 'fs';
import { join } from 'path';
const namespace = 'plugin-access';
export default (api) => {
const {
utils: { Mustache }
} = api;
api.describe({
config: {
schema(joi) {
return joi.object({
roles: joi.object()
});
},
default: {}
}
});
const absoluteFilePath = join(namespace, 'core.js');
const absRuntimeFilePath = join(namespace, 'runtime.js');
api.onGenerateFiles(() => {
// 文件写出
const { roles = {} } = api.config.access || {};
api.writeTmpFile({
path: absoluteFilePath,
content: Mustache.render(
readFileSync(join(__dirname, 'runtime/core.tpl'), 'utf-8'),
{
REPLACE_ROLES: JSON.stringify(roles)
}
)
});
api.copyTmpFiles({
namespace,
path: join(__dirname, 'runtime'),
ignore: ['.tpl']
});
});
api.addPluginExports(() => [
{
specifiers: ['access', 'useAccess'],
source: absoluteFilePath
}
]);
api.addRuntimePluginKey(() => 'access');
api.addRuntimePlugin(() => `@@/${absRuntimeFilePath}`);
};