UNPKG

@aniyajs/plugin-router

Version:

基于 react-routerV6 封装的路由插件服务于aniyajs自动化脚手架

53 lines (45 loc) 1.36 kB
import { flatArr } from "./index"; export default (api) => { api.describe({ key: "routes", config: { default: [], }, }); api.generate(async (args) => { const { pluginTempPath, ...paths } = args; const routers = flatArr({ initArr: api.configition.routes ? api.configition.routes : [], childrenField: "routes", }).filter((item) => item.component); const content = routers .map((route, i) => { const routeName = `Demo${i + 1}`; return `export { default as ${routeName} } from "${api.join( paths.appPagesPath, route.component, )}";`; }) .join("\n"); api.writeFile({ file: api.resolve(pluginTempPath, "imports.ts"), content, }); const templatePaths = await api.readFilterdir({ rootPath: api.join( paths.appNodeModules, "@aniyajs/plugin-router/templates", ), filterHandle: Boolean, withSuffix: true, }); templatePaths.forEach((templatePath) => { const basename = api.basename(templatePath); const filename = basename.slice(0, basename.length - 4); api.copyTpl(templatePath, api.resolve(pluginTempPath, filename), { haveRedux: api.configition.toolTik ? api.configition.toolTik : false, configFile: paths.appConfigJs, }); }); }); };