@fesjs/plugin-access
Version:
@fesjs/plugin-access
57 lines (56 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fs = require("fs");
var _path = require("path");
var _package = require("../package.json");
const namespace = 'plugin-access';
var _default = api => {
const {
utils: {
Mustache
}
} = api;
api.describe({
config: {
schema(joi) {
return joi.object({
roles: joi.object()
});
},
default: {}
}
});
const absoluteFilePath = (0, _path.join)(namespace, 'core.js');
const absRuntimeFilePath = (0, _path.join)(namespace, 'runtime.js');
api.onGenerateFiles(() => {
// 文件写出
const {
roles = {}
} = api.config.access || {};
api.writeTmpFile({
path: absoluteFilePath,
content: Mustache.render((0, _fs.readFileSync)((0, _path.join)(__dirname, 'runtime/core.tpl'), 'utf-8'), {
REPLACE_ROLES: JSON.stringify(roles),
lodashPath: 'lodash-es'
})
});
api.copyTmpFiles({
namespace,
path: (0, _path.join)(__dirname, 'runtime'),
ignore: ['.tpl']
});
});
api.addPluginExports(() => [{
specifiers: ['access', 'useAccess'],
source: absoluteFilePath
}]);
api.addRuntimePluginKey(() => 'access');
api.addRuntimePlugin(() => `@@/${absRuntimeFilePath}`);
api.addConfigType(() => ({
source: _package.name
}));
};
exports.default = _default;