@wavemaker/angular-codegen 12.0.0-next.45091 → 12.0.0-next.45094
Sign up to get free protection for your applications and to get access to all the features.
angular-codegen/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
const Handlebars=require("handlebars"),fs=require("fs"),{getComponentName:getComponentName,isPrefabProject:isPrefabProject,getComponentModuleName:getComponentModuleName,getCodegenPath:getCodegenPath}=require("./wm-utils"),getPageRouteInfo=(e,t,n)=>{let a,r;if(null!==e){a="[(route) => inject(AuthGuard).canActivate(route)]";for(const n of e)if(n.urlPattern.startsWith("/pages/")){n.urlPattern.split("/")[2]===t&&("Role"===n.permission?(a="[(route) => inject(RoleGuard).canActivate(route)]",n.roles&&(r=JSON.stringify(n.roles))):"PermitAll"===n.permission&&(a=void 0))}}return`{\n path: '${t}',\n pathMatch: 'full',\n loadChildren: () => import('${n?"../..":"."}/pages/${t}/${t}.module').then(m => m.${getComponentModuleName(t)}),\n ${a?`canActivate: ${a},`:""}\n data : {\n ${r?`allowedRoles: ${r},`:""}\n pageName: '${t}'\n }\n }`},getLayoutRouteInfo=e=>`{\n path: "",\n resolve: appDependenciesResolve,\n loadChildren: () => import("./layouts/${e}/${e}.module").then(m => m.${getComponentModuleName(e)}),\n data : { \n layoutName: '${e}' \n }\n }`;Handlebars.registerHelper("PageComponentsImportStmts",(e,t)=>{if(isPrefabProject(e))return"";const n=t.filter(e=>"PAGE"===e.type).map(e=>`import { ${getComponentName(e.name)} } from './pages/${e.name}/${e.name}.component';`).join("\n");return safeString(n)}),Handlebars.registerHelper("WMComponentsImportStmts",(e=[])=>{const t=e.map(e=>`import { ${e.name} as ${e.as||"WM_"+e.name} } from '${e.from}';`).join("\n");return safeString(t)}),Handlebars.registerHelper("WMCustomComponentsImportStmts",(e=[])=>{const t=e.map(e=>`import { ${getComponentName(e.name)} } from '../../customwidgets/${e.name}/${e.name}.component';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PartialModuleImportStmts",e=>{const t=e.filter(e=>"PARTIAL"===e.type).map(e=>`import { ${getComponentModuleName(e.name)} as Partial${getComponentModuleName(e.name)}} from '../../partials/${e.name}/${e.name}.module';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PrefabPartialModuleImportStmts",e=>{const t=e.filter(e=>"PARTIAL"===e.type).map(e=>`import { ${getComponentModuleName(e.name)} as Partial${getComponentModuleName(e.name)}} from './partials/${e.name}/${e.name}.module';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PartialModuleStmts",e=>{const t=e.filter(e=>"PARTIAL"===e.type).map(e=>"Partial"+getComponentModuleName(e.name)).join(",\n\t");return safeString(t)}),Handlebars.registerHelper("PrefabModuleImportStmts",e=>{const t=e.filter(e=>"PREFAB"===e.type).map(e=>`import { ${getComponentModuleName(e.name)} as Prefab${getComponentModuleName(e.name)} } from '../../prefabs/${e.name}/${e.name}.module';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PrefabModuleStmts",e=>{const t=e.filter(e=>"PREFAB"===e.type).map(e=>"Prefab"+getComponentModuleName(e.name)).join(",\n\t");return safeString(t)}),Handlebars.registerHelper("WMComponentModuleStmts",e=>{const t=e.map(e=>`${e.as||"WM_"+e.name}${e.forRoot?".forRoot()":""}`).join(",\n\t");return safeString(t)}),Handlebars.registerHelper("WMCustomComponentStmts",e=>{const t=e.map(e=>`${getComponentName(e.name)}`).join(",\n\t");return safeString(t)}),Handlebars.registerHelper("PartialComponentsImportStmts",e=>{const t=e.filter(e=>"PAGE"!==e.type).map(e=>`import { ${getComponentName(e.name)} } from './partials/${e.name}/${e.name}.component';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PrefabComponentsImportStmts",e=>{const t=[];for(const[n]of e.entries())t.push(`import { MainComponent as ${n}Component } from './prefabs/${n}/Main/Main.component';`);return safeString(t.join("\n"))}),Handlebars.registerHelper("RegisterComponents",(e,t,n)=>{let a=[];for(const[e]of n.entries())a.push(`ComponentRefProviderService.registerComponentRef('${e}', ComponentType.PREFAB, ${e}Component, null);`);return safeString(a.join("\n"))}),Handlebars.registerHelper("ComponentDeclarations",(e,t,n)=>{let a=[];for(const[e]of n.entries())a.push(`${e}Component`);return safeString(a.join(",\n\t"))}),Handlebars.registerHelper("RegisterPrefabConfig",e=>{const t=[];for(const[n,a]of e.entries())t.push(`registerPrefabConfig('${n}', ${a})`);return safeString(t.join("\n"))}),Handlebars.registerHelper("registerCustomWidgetConfig",e=>{const t=[];for(const[n,a]of e.entries())t.push(`registerCustomWidgetConfig('${n}', ${a})`);return safeString(t.join("\n"))}),Handlebars.registerHelper("DefineHomePage",e=>isPrefabProject(e)?"prefab-preview":e.homePage),Handlebars.registerHelper("ImportPrefabPreviewComponent",e=>isPrefabProject(e)?safeString('import { PrefabPreviewComponent } from "@wm/runtime/base";'):""),Handlebars.registerHelper("DefineLayoutRoutes",(e,t,n,a)=>{const r=n.filter(t=>t.layout===e&&"PAGE"===t.type).map(e=>getPageRouteInfo(a,e.name,!0));let o="";return r.length&&(o=`\n children: [\n ${r.join(",\n")}\n ]`),safeString(`[\n {\n path: '',\n component: ${t},\n ${o}\n\n }\n ]`)}),Handlebars.registerHelper("DefineAppRoutes",(e,t,n,a,r)=>{let o="";if(isPrefabProject(e))o="{\n path: 'prefab-preview',\n resolve: appDependenciesResolve,\n component: PrefabPreviewComponent\n }";else if(r){o=`${t.map(e=>getLayoutRouteInfo(e.name)).join(",\n")}`}else{o=`{\n path: '',\n resolve: appDependenciesResolve,\n children: [\n ${n.filter(e=>"PAGE"===e.type).map(e=>getPageRouteInfo(a,e.name,!1)).join(",\n")}\n ]\n }`}return safeString(`[\n {\n path: '',\n pathMatch: 'full',\n component: EmptyPageComponent,\n resolve: appDependenciesResolve\n },\n ${o},\n {\n path: "**",\n canActivate: [(route) => inject(PageNotFoundGuard).canActivate(route)],\n component: EmptyPageComponent\n }\n ]`)}),Handlebars.registerHelper("DefinePrefabModules",e=>`{ ${e} }`),Handlebars.registerHelper("DefinePartialModules",e=>`{ ${e} }`),Handlebars.registerHelper("DefinePrefabPartialModules",e=>`{ ${e} }`);const templates=new Map,initTemplates=()=>{const e=getCodegenPath()+"/templates/";templates.set("app-module-ts",Handlebars.compile(fs.readFileSync(e+"app.module.ts.hbs","utf-8"))),templates.set("app-codegen-module",Handlebars.compile(fs.readFileSync(e+"app-codegen.module.ts.hbs","utf-8"))),templates.set("app-prefabs-module",Handlebars.compile(fs.readFileSync(e+"app-prefabs.module.ts.hbs","utf-8"))),templates.set("prefab-config",Handlebars.compile(fs.readFileSync(e+"prefab/prefab-config.ts.hbs","utf-8"))),templates.set("customwidget-config",Handlebars.compile(fs.readFileSync(e+"customwidget/customwidget-config.ts.hbs","utf-8"))),templates.set("app-routes",Handlebars.compile(fs.readFileSync(e+"app-routes.ts.hbs","utf-8"))),templates.set("lazy-module-routes",Handlebars.compile(fs.readFileSync(e+"lazy-module-routes.ts.hbs","utf-8"))),templates.set("wm-project-properties",Handlebars.compile(fs.readFileSync(e+"wm-project-properties.ts.hbs","utf-8"))),templates.set("component-variables",Handlebars.compile(fs.readFileSync(e+"component.variables.ts.hbs","utf-8"))),templates.set("component-expressions",Handlebars.compile(fs.readFileSync(e+"component.expressions.ts.hbs","utf-8"))),templates.set("app-component-script",Handlebars.compile(fs.readFileSync(e+"app.component.script.js.hbs","utf-8"))),templates.set("layout-component-ts",Handlebars.compile(fs.readFileSync(e+"layout/layout.component.ts.hbs","utf-8"))),templates.set("layout-module-ts",Handlebars.compile(fs.readFileSync(e+"layout/layout.module.ts.hbs","utf-8"))),templates.set("page-component-ts",Handlebars.compile(fs.readFileSync(e+"page/page.component.ts.hbs","utf-8"))),templates.set("page-component-script",Handlebars.compile(fs.readFileSync(e+"page/page.component.script.js.hbs","utf-8"))),templates.set("page-module-ts",Handlebars.compile(fs.readFileSync(e+"page/page.module.ts.hbs","utf-8"))),templates.set("partial-component-ts",Handlebars.compile(fs.readFileSync(e+"partial/partial.component.ts.hbs","utf-8"))),templates.set("partial-component-script",Handlebars.compile(fs.readFileSync(e+"partial/partial.component.script.js.hbs","utf-8"))),templates.set("partial-module-ts",Handlebars.compile(fs.readFileSync(e+"partial/partial.module.ts.hbs","utf-8"))),templates.set("customwidget-component-ts",Handlebars.compile(fs.readFileSync(e+"customwidget/customwidget.component.ts.hbs","utf-8"))),templates.set("customwidget-component-script",Handlebars.compile(fs.readFileSync(e+"customwidget/customwidget.component.script.js.hbs","utf-8"))),templates.set("prefab-component-ts",Handlebars.compile(fs.readFileSync(e+"prefab/prefab.component.ts.hbs","utf-8"))),templates.set("prefab-module-ts",Handlebars.compile(fs.readFileSync(e+"prefab/prefab.module.ts.hbs","utf-8"))),templates.set("prefab-component-script",Handlebars.compile(fs.readFileSync(e+"prefab/prefab.component.script.js.hbs","utf-8"))),templates.set("expr-vs-fn",Handlebars.compile(fs.readFileSync(e+"expr-vs-fn.hbs","utf-8")))},getHandlebarTemplate=e=>templates.get(e),safeString=e=>new Handlebars.SafeString(e);module.exports={getHandlebarTemplate:getHandlebarTemplate,safeString:safeString,initTemplates:initTemplates};
|
1
|
+
const Handlebars=require("handlebars"),fs=require("fs"),{getComponentName:getComponentName,isPrefabProject:isPrefabProject,getComponentModuleName:getComponentModuleName,getCodegenPath:getCodegenPath}=require("./wm-utils"),getPageRouteInfo=(e,t,n)=>{let a,r;if(null!==e){a="[(route) => inject(AuthGuard).canActivate(route)]";for(const n of e)if(n.urlPattern.startsWith("/pages/")){n.urlPattern.split("/")[2]===t&&("Role"===n.permission?(a="[(route) => inject(RoleGuard).canActivate(route)]",n.roles&&(r=JSON.stringify(n.roles))):"PermitAll"===n.permission&&(a=void 0))}}return`{\n path: '${t}',\n pathMatch: 'full',\n loadChildren: () => import('${n?"../..":"."}/pages/${t}/${t}.module').then(m => m.${getComponentModuleName(t)}),\n ${a?`canActivate: ${a},`:""}\n data : {\n ${r?`allowedRoles: ${r},`:""}\n pageName: '${t}'\n }\n }`},getLayoutRouteInfo=e=>`{\n path: "",\n resolve: appDependenciesResolve,\n loadChildren: () => import("./layouts/${e}/${e}.module").then(m => m.${getComponentModuleName(e)}),\n data : { \n layoutName: '${e}' \n }\n }`;Handlebars.registerHelper("PageComponentsImportStmts",(e,t)=>{if(isPrefabProject(e))return"";const n=t.filter(e=>"PAGE"===e.type).map(e=>`import { ${getComponentName(e.name)} } from './pages/${e.name}/${e.name}.component';`).join("\n");return safeString(n)}),Handlebars.registerHelper("WMComponentsImportStmts",(e=[])=>{const t=e.map(e=>`import { ${e.name} as ${e.as||"WM_"+e.name} } from '${e.from}';`).join("\n");return safeString(t)}),Handlebars.registerHelper("WMCustomComponentsImportStmts",(e=[])=>{const t=e.map(e=>`import { ${getComponentName(e.name)} as ${"WM_"+getComponentName(e.name)} } from '../../customwidgets/${e.name}/${e.name}.component';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PartialModuleImportStmts",e=>{const t=e.filter(e=>"PARTIAL"===e.type).map(e=>`import { ${getComponentModuleName(e.name)} as Partial${getComponentModuleName(e.name)}} from '../../partials/${e.name}/${e.name}.module';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PrefabPartialModuleImportStmts",e=>{const t=e.filter(e=>"PARTIAL"===e.type).map(e=>`import { ${getComponentModuleName(e.name)} as Partial${getComponentModuleName(e.name)}} from './partials/${e.name}/${e.name}.module';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PartialModuleStmts",e=>{const t=e.filter(e=>"PARTIAL"===e.type).map(e=>"Partial"+getComponentModuleName(e.name)).join(",\n\t");return safeString(t)}),Handlebars.registerHelper("PrefabModuleImportStmts",e=>{const t=e.filter(e=>"PREFAB"===e.type).map(e=>`import { ${getComponentModuleName(e.name)} as Prefab${getComponentModuleName(e.name)} } from '../../prefabs/${e.name}/${e.name}.module';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PrefabModuleStmts",e=>{const t=e.filter(e=>"PREFAB"===e.type).map(e=>"Prefab"+getComponentModuleName(e.name)).join(",\n\t");return safeString(t)}),Handlebars.registerHelper("WMComponentModuleStmts",e=>{const t=e.map(e=>`${e.as||"WM_"+e.name}${e.forRoot?".forRoot()":""}`).join(",\n\t");return safeString(t)}),Handlebars.registerHelper("WMCustomComponentStmts",e=>{const t=e.map(e=>`${"WM_"+getComponentName(e.name)}`).join(",\n\t");return safeString(t)}),Handlebars.registerHelper("PartialComponentsImportStmts",e=>{const t=e.filter(e=>"PAGE"!==e.type).map(e=>`import { ${getComponentName(e.name)} } from './partials/${e.name}/${e.name}.component';`).join("\n");return safeString(t)}),Handlebars.registerHelper("PrefabComponentsImportStmts",e=>{const t=[];for(const[n]of e.entries())t.push(`import { MainComponent as ${n}Component } from './prefabs/${n}/Main/Main.component';`);return safeString(t.join("\n"))}),Handlebars.registerHelper("RegisterComponents",(e,t,n)=>{let a=[];for(const[e]of n.entries())a.push(`ComponentRefProviderService.registerComponentRef('${e}', ComponentType.PREFAB, ${e}Component, null);`);return safeString(a.join("\n"))}),Handlebars.registerHelper("ComponentDeclarations",(e,t,n)=>{let a=[];for(const[e]of n.entries())a.push(`${e}Component`);return safeString(a.join(",\n\t"))}),Handlebars.registerHelper("RegisterPrefabConfig",e=>{const t=[];for(const[n,a]of e.entries())t.push(`registerPrefabConfig('${n}', ${a})`);return safeString(t.join("\n"))}),Handlebars.registerHelper("registerCustomWidgetConfig",e=>{const t=[];for(const[n,a]of e.entries())t.push(`registerCustomWidgetConfig('${n}', ${a})`);return safeString(t.join("\n"))}),Handlebars.registerHelper("DefineHomePage",e=>isPrefabProject(e)?"prefab-preview":e.homePage),Handlebars.registerHelper("ImportPrefabPreviewComponent",e=>isPrefabProject(e)?safeString('import { PrefabPreviewComponent } from "@wm/runtime/base";'):""),Handlebars.registerHelper("DefineLayoutRoutes",(e,t,n,a)=>{const r=n.filter(t=>t.layout===e&&"PAGE"===t.type).map(e=>getPageRouteInfo(a,e.name,!0));let o="";return r.length&&(o=`\n children: [\n ${r.join(",\n")}\n ]`),safeString(`[\n {\n path: '',\n component: ${t},\n ${o}\n\n }\n ]`)}),Handlebars.registerHelper("DefineAppRoutes",(e,t,n,a,r)=>{let o="";if(isPrefabProject(e))o="{\n path: 'prefab-preview',\n resolve: appDependenciesResolve,\n component: PrefabPreviewComponent\n }";else if(r){o=`${t.map(e=>getLayoutRouteInfo(e.name)).join(",\n")}`}else{o=`{\n path: '',\n resolve: appDependenciesResolve,\n children: [\n ${n.filter(e=>"PAGE"===e.type).map(e=>getPageRouteInfo(a,e.name,!1)).join(",\n")}\n ]\n }`}return safeString(`[\n {\n path: '',\n pathMatch: 'full',\n component: EmptyPageComponent,\n resolve: appDependenciesResolve\n },\n ${o},\n {\n path: "**",\n canActivate: [(route) => inject(PageNotFoundGuard).canActivate(route)],\n component: EmptyPageComponent\n }\n ]`)}),Handlebars.registerHelper("DefinePrefabModules",e=>`{ ${e} }`),Handlebars.registerHelper("DefinePartialModules",e=>`{ ${e} }`),Handlebars.registerHelper("DefinePrefabPartialModules",e=>`{ ${e} }`);const templates=new Map,initTemplates=()=>{const e=getCodegenPath()+"/templates/";templates.set("app-module-ts",Handlebars.compile(fs.readFileSync(e+"app.module.ts.hbs","utf-8"))),templates.set("app-codegen-module",Handlebars.compile(fs.readFileSync(e+"app-codegen.module.ts.hbs","utf-8"))),templates.set("app-prefabs-module",Handlebars.compile(fs.readFileSync(e+"app-prefabs.module.ts.hbs","utf-8"))),templates.set("prefab-config",Handlebars.compile(fs.readFileSync(e+"prefab/prefab-config.ts.hbs","utf-8"))),templates.set("customwidget-config",Handlebars.compile(fs.readFileSync(e+"customwidget/customwidget-config.ts.hbs","utf-8"))),templates.set("app-routes",Handlebars.compile(fs.readFileSync(e+"app-routes.ts.hbs","utf-8"))),templates.set("lazy-module-routes",Handlebars.compile(fs.readFileSync(e+"lazy-module-routes.ts.hbs","utf-8"))),templates.set("wm-project-properties",Handlebars.compile(fs.readFileSync(e+"wm-project-properties.ts.hbs","utf-8"))),templates.set("component-variables",Handlebars.compile(fs.readFileSync(e+"component.variables.ts.hbs","utf-8"))),templates.set("component-expressions",Handlebars.compile(fs.readFileSync(e+"component.expressions.ts.hbs","utf-8"))),templates.set("app-component-script",Handlebars.compile(fs.readFileSync(e+"app.component.script.js.hbs","utf-8"))),templates.set("layout-component-ts",Handlebars.compile(fs.readFileSync(e+"layout/layout.component.ts.hbs","utf-8"))),templates.set("layout-module-ts",Handlebars.compile(fs.readFileSync(e+"layout/layout.module.ts.hbs","utf-8"))),templates.set("page-component-ts",Handlebars.compile(fs.readFileSync(e+"page/page.component.ts.hbs","utf-8"))),templates.set("page-component-script",Handlebars.compile(fs.readFileSync(e+"page/page.component.script.js.hbs","utf-8"))),templates.set("page-module-ts",Handlebars.compile(fs.readFileSync(e+"page/page.module.ts.hbs","utf-8"))),templates.set("partial-component-ts",Handlebars.compile(fs.readFileSync(e+"partial/partial.component.ts.hbs","utf-8"))),templates.set("partial-component-script",Handlebars.compile(fs.readFileSync(e+"partial/partial.component.script.js.hbs","utf-8"))),templates.set("partial-module-ts",Handlebars.compile(fs.readFileSync(e+"partial/partial.module.ts.hbs","utf-8"))),templates.set("customwidget-component-ts",Handlebars.compile(fs.readFileSync(e+"customwidget/customwidget.component.ts.hbs","utf-8"))),templates.set("customwidget-component-script",Handlebars.compile(fs.readFileSync(e+"customwidget/customwidget.component.script.js.hbs","utf-8"))),templates.set("prefab-component-ts",Handlebars.compile(fs.readFileSync(e+"prefab/prefab.component.ts.hbs","utf-8"))),templates.set("prefab-module-ts",Handlebars.compile(fs.readFileSync(e+"prefab/prefab.module.ts.hbs","utf-8"))),templates.set("prefab-component-script",Handlebars.compile(fs.readFileSync(e+"prefab/prefab.component.script.js.hbs","utf-8"))),templates.set("expr-vs-fn",Handlebars.compile(fs.readFileSync(e+"expr-vs-fn.hbs","utf-8")))},getHandlebarTemplate=e=>templates.get(e),safeString=e=>new Handlebars.SafeString(e);module.exports={getHandlebarTemplate:getHandlebarTemplate,safeString:safeString,initTemplates:initTemplates};
|