@winner-fed/plugin-access
Version:
适配 access(权限)的 WinJS 插件,适用于 Vue3。
94 lines (93 loc) • 3.93 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
default: ()=>src
});
const external_node_fs_namespaceObject = require("node:fs");
const external_node_path_namespaceObject = require("node:path");
require("node:url");
const utils_namespaceObject = require("@winner-fed/utils");
const getCurrentDir = ()=>__dirname;
const ACCESS_TEMPLATES_DIR = (0, external_node_path_namespaceObject.join)(getCurrentDir(), '../templates');
const DIR_NAME = 'plugin-access';
const src = (api)=>{
api.describe({
key: 'access',
config: {
schema ({ zod }) {
return zod.object({
roles: zod.object({})
}).required();
}
},
enableBy: api.EnableBy.config
});
api.onGenerateFiles(()=>{
const { roles = {} } = api.config.access || {};
const accessTpl = (0, external_node_fs_namespaceObject.readFileSync)((0, external_node_path_namespaceObject.join)(ACCESS_TEMPLATES_DIR, 'core.tpl'), 'utf-8');
api.writeTmpFile({
path: (0, external_node_path_namespaceObject.join)(DIR_NAME, 'index.ts'),
noPluginDir: true,
content: utils_namespaceObject.Mustache.render(accessTpl, {
roles: JSON.stringify(roles)
}),
context: {}
});
api.writeTmpFile({
path: (0, external_node_path_namespaceObject.join)(DIR_NAME, 'runtime.ts'),
noPluginDir: true,
content: (0, external_node_fs_namespaceObject.readFileSync)((0, external_node_path_namespaceObject.join)(ACCESS_TEMPLATES_DIR, 'runtime.tpl'), 'utf-8')
});
api.writeTmpFile({
path: (0, external_node_path_namespaceObject.join)(DIR_NAME, 'createComponent.ts'),
noPluginDir: true,
content: (0, external_node_fs_namespaceObject.readFileSync)((0, external_node_path_namespaceObject.join)(ACCESS_TEMPLATES_DIR, 'createComponent.tpl'), 'utf-8')
});
api.writeTmpFile({
path: (0, external_node_path_namespaceObject.join)(DIR_NAME, 'createDirective.ts'),
noPluginDir: true,
content: (0, external_node_fs_namespaceObject.readFileSync)((0, external_node_path_namespaceObject.join)(ACCESS_TEMPLATES_DIR, 'createDirective.tpl'), 'utf-8')
});
api.writeTmpFile({
path: (0, external_node_path_namespaceObject.join)(DIR_NAME, 'types.d.ts'),
noPluginDir: true,
content: (0, external_node_fs_namespaceObject.readFileSync)((0, external_node_path_namespaceObject.join)(ACCESS_TEMPLATES_DIR, 'types.d.ts'), 'utf-8')
});
});
api.addRuntimePluginKey(()=>[
'access'
]);
api.addRuntimePlugin(()=>[
`${api.paths.absTmpPath}/${DIR_NAME}/runtime.ts`
]);
};
exports["default"] = __webpack_exports__["default"];
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
"default"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
value: true
});