@wavemaker/angular-codegen 12.0.0-next.45073 → 12.0.0-next.45076
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{createDir:createDir,writeFile:writeFile,isPrefabProject:isPrefabProject,getLayoutsDirPath:getLayoutsDirPath,getPagesDirPath:getPagesDirPath,formatContents:formatContents,getComponentName:getComponentName,getComponentModuleName:getComponentModuleName,getPrefabPagesDirPath:getPrefabPagesDirPath}=require("./wm-utils"),fs=require("fs"),cheerio=require("cheerio"),{getPageContents:getPageContents,getCustomWidgetPageContents:getCustomWidgetPageContents}=require("./pages-util"),{getHandlebarTemplate:getHandlebarTemplate,safeString:safeString}=require("./handlebar-helpers"),{generateCustomWidgetConfigFile:generateCustomWidgetConfigFile}=require("./gen-customwidget-config");let customWidgetConfigMap=new Map;const writeComponentHtmlFile=async(e,t,a)=>{const n=`${a}/${e}.component.html`;await writeFile(n,t.string)},writeComponentCssFile=async(e,t,a)=>{const n=`${a}/${e}.component.css`;await writeFile(n,t.string)},writeComponentVariablesFile=async(e,t,a,n)=>{let o=getHandlebarTemplate(e)({variables:a});await writeFile(`${n}/${t}.component.variables.ts`,formatContents(o))},writeComponentConfigFile=async(e,t,a,n)=>{let o=getHandlebarTemplate(e)({config:a});await writeFile(`${n}/${t}.component.config.ts`,formatContents(o))},writeComponentJsFile=async(e,t,a,n)=>{const o=getHandlebarTemplate(e)({jsContent:a});await writeFile(`${n}/${t}.component.script.js`,formatContents(o,"javascript"))},writeComponentExpressionsFile=async(e,t,a,n)=>{const o=getHandlebarTemplate(e)({expressions:a});await writeFile(`${n}/${t}.component.expressions.ts`,formatContents(o,"javascript"))},writeComponentTsFile=async(e,t,a,n,o,i,r=[])=>{let s=getHandlebarTemplate(e)({name:t,prefabName:a,componentName:getComponentName(t),enableSpa:o,layoutPages:safeString(JSON.stringify(i)),requiredWMComponents:r});await writeFile(`${n}/${t}.component.ts`,s)},writePagePartialModuleTsFile=async(e,t,a,n,o,i,r=!1,s,m,p,g)=>{let l=getHandlebarTemplate(e)({name:t,componentName:getComponentName(t),moduleName:getComponentModuleName(t),requiredPartials:n,requiredPrefabs:o,requiredWMComponents:i,hasCustomElement:r,insidePrefab:!!s,pagesConfig:m,securityConfig:p,requireCustomComponents:g});await writeFile(`${a}/${t}.module.ts`,l)},writePrefabModuleTsFile=async(e,t,a,n=!1,o)=>{let i=getHandlebarTemplate("prefab-module-ts")({name:e,componentName:getComponentName(e),moduleName:getComponentModuleName(e),requiredPartials:o,requiredWMComponents:a,hasCustomElement:n});await writeFile(`${t}/${e}.module.ts`,i)},generateComponent=async(e,t,a,n,o,i,r,s,m,p=!1)=>{await createDir(e,{recursive:!0});const{markup:g,styles:l,variables:c,script:
|
1
|
+
const{createDir:createDir,writeFile:writeFile,isPrefabProject:isPrefabProject,getLayoutsDirPath:getLayoutsDirPath,getPagesDirPath:getPagesDirPath,formatContents:formatContents,getComponentName:getComponentName,getComponentModuleName:getComponentModuleName,getPrefabPagesDirPath:getPrefabPagesDirPath}=require("./wm-utils"),fs=require("fs"),cheerio=require("cheerio"),{getPageContents:getPageContents,getCustomWidgetPageContents:getCustomWidgetPageContents}=require("./pages-util"),{getHandlebarTemplate:getHandlebarTemplate,safeString:safeString}=require("./handlebar-helpers"),{generateCustomWidgetConfigFile:generateCustomWidgetConfigFile}=require("./gen-customwidget-config");let customWidgetConfigMap=new Map;const writeComponentHtmlFile=async(e,t,a)=>{const n=`${a}/${e}.component.html`;await writeFile(n,t.string)},writeComponentCssFile=async(e,t,a)=>{const n=`${a}/${e}.component.css`;await writeFile(n,t.string)},writeComponentVariablesFile=async(e,t,a,n)=>{let o=getHandlebarTemplate(e)({variables:a});await writeFile(`${n}/${t}.component.variables.ts`,formatContents(o))},writeComponentConfigFile=async(e,t,a,n)=>{let o=getHandlebarTemplate(e)({config:a});await writeFile(`${n}/${t}.component.config.ts`,formatContents(o))},writeComponentJsFile=async(e,t,a,n)=>{const o=getHandlebarTemplate(e)({jsContent:a});await writeFile(`${n}/${t}.component.script.js`,formatContents(o,"javascript"))},writeComponentExpressionsFile=async(e,t,a,n)=>{const o=getHandlebarTemplate(e)({expressions:a});await writeFile(`${n}/${t}.component.expressions.ts`,formatContents(o,"javascript"))},writeComponentTsFile=async(e,t,a,n,o,i,r=[])=>{let s=getHandlebarTemplate(e)({name:t,prefabName:a,componentName:getComponentName(t),enableSpa:o,layoutPages:safeString(JSON.stringify(i)),requiredWMComponents:r});await writeFile(`${n}/${t}.component.ts`,s)},writePagePartialModuleTsFile=async(e,t,a,n,o,i,r=!1,s,m,p,g)=>{let l=getHandlebarTemplate(e)({name:t,componentName:getComponentName(t),moduleName:getComponentModuleName(t),requiredPartials:n,requiredPrefabs:o,requiredWMComponents:i,hasCustomElement:r,insidePrefab:!!s,pagesConfig:m,securityConfig:p,requireCustomComponents:g});await writeFile(`${a}/${t}.module.ts`,l)},writePrefabModuleTsFile=async(e,t,a,n=!1,o)=>{let i=getHandlebarTemplate("prefab-module-ts")({name:e,componentName:getComponentName(e),moduleName:getComponentModuleName(e),requiredPartials:o,requiredWMComponents:a,hasCustomElement:n});await writeFile(`${t}/${e}.module.ts`,i)},generateComponent=async(e,t,a,n,o,i,r,s,m,p=!1)=>{await createDir(e,{recursive:!0});const{markup:g,styles:l,variables:c,script:d,expressions:u}=n,C=[writeComponentHtmlFile(t,safeString(g),e),writeComponentTsFile(o,t,a,e,s,m,n.requiredWMComponents)];return p||writeComponentExpressionsFile("component-expressions",t,safeString(u),e),r||C.concat([writeComponentCssFile(t,safeString(l),e),writeComponentVariablesFile("component-variables",t,safeString(c),e),writeComponentJsFile(i,t,safeString(d),e)]),Promise.all(C)},findRequiredPartials=e=>{const t={};return e("[partialContainer]").map((t,a)=>e(a).attr("content")).toArray().map(e=>({type:"PARTIAL",name:e.trim()})).filter(e=>!t[e.name]&&(t[e.name]=!0))},findRequiredPrefabs=e=>{const t={};return e("[wmPrefab]").map((t,a)=>e(a).attr("prefabname")).toArray().map(e=>({type:"PREFAB",name:e.trim()})).filter(e=>!t[e.name]&&(t[e.name]=!0))},findRequiredCustomWidgets=e=>{const t={};return e("[customWidgetContainer]").map((t,a)=>e(a).attr("widgetname")).toArray().map(e=>({type:"CUSTOMWIDGET",name:e.trim()})).filter(e=>!t[e.name]&&(t[e.name]=!0))},generateCustomWidgetsComponent=async(e,t,a,n)=>{let o,i,r,s;{if(s=`${t}/src/app/customwidgets/${e}`,o="customwidget-component-ts",i="customwidget-component-script",r="customwidget-module-ts",fs.existsSync(`${s}/${e}.component.ts`))return;const a=require("../dependencies/custom-widgets-bundle.cjs.js"),m=await getCustomWidgetPageContents(a,e);n.set(e,m.config);try{const t=cheerio.load(m.markup);findRequiredPartials(t),findRequiredPrefabs(t);await generateComponent(s,e,void 0,m,"customwidget-component-ts","customwidget-component-script",!1,void 0,void 0,!0)}catch(e){throw console.log("failed in "+pageName),e}}};convertHTMLStructure=(e=>{let t=e.replace(/<div\s+wmWidgetContainer\s+customWidgetContainer\s+#wm_custom_widget\d+="wmWidgetContainer"\s+widgetname="([^"]+)"\s+name="([^"]+)"\s*(.*?)\s*\/?>\s*<\/div>/g,(e,t,a,n)=>{let o;return`<${o=`app-custom-${t}`} wmWidgetContainer #wm_custom_widget${a.match(/\d+/)[0]}="wmWidgetContainer" widgetname="${t}" name="${a}" ${n}></${o}>`});return t=modifyFormFields(t)}),modifyFormFields=(e=>{if(/wmWidgetContainer/.test(e)&&/#formWidget/.test(e)){return e.replace(/<div\s+wmWidgetContainer\s+customWidgetContainer(.*?)<\/div>/g,(e,t)=>{let a=t.match(/widgetname=(\w+)/),n=a?a[1]:"div";return`<app-custom-${n} wmWidgetContainer ${t.replace(/customWidgetContainer/,"").trim()}></app-custom-${n}>`})}return e});const generatePagePartialComponent=async(e,t,a,n,o,i,r,s,m,p,g,l)=>{let c,d,u,C,f;if("PAGE"===n?(C=`${o}/src/app/pages/${a}`,c="page-component-ts",d="page-component-script",u="page-module-ts"):"LAYOUT"===n?(C=`${o}/src/app/layouts/${a}`,c="layout-component-ts",u="layout-module-ts",f=p.filter(e=>"PAGE"===e.type&&e.layout===a).map(e=>e.name)):(C=i?`${o}/partials/${a}`:`${o}/src/app/partials/${a}`,c="partial-component-ts",d="partial-component-script",u="partial-module-ts"),fs.existsSync(`${C}/${a}.component.ts`))return;let w=`${e}/${a}`;i&&(w=`${getPrefabPagesDirPath(r,i)}/${a}`);const P=await getPageContents(t,w,`${a}`,a,n,void 0,s);try{const e=cheerio.load(P.markup),l=findRequiredPartials(e),w=findRequiredPrefabs(e),$=findRequiredCustomWidgets(e)||void 0;for(const e of l){const a=getPagesDirPath(r);await generatePagePartialComponent(a,t,e.name,e.type,o,i,r,s,m)}for(const e of $)await generateCustomWidgetsComponent(e.name,o,0,customWidgetConfigMap);$.length&&await generateCustomWidgetConfigFile(customWidgetConfigMap,o),P.markup=convertHTMLStructure(P.markup),await generateComponent(C,a,void 0,P,c,d,"LAYOUT"===n,m,f),await writePagePartialModuleTsFile(u,a,C,l,w,P.requiredWMComponents,P.hasCustomElement,i,p,g,$)}catch(e){throw console.log("failed in "+a),e}},generateComponents=async(e,t,a,n,o,i,r,s,m,p)=>{const g=getPagesDirPath(e);customWidgetConfigMap=new Map;for(const a of i.keys()){const n="__self__"===a?`${g}/Main`:`${getPrefabPagesDirPath(e,a)}/Main`,o=await getPageContents(t,n,"Main",a,"PREFAB",i.get(a),m),c=`${r}/src/app/prefabs/${a}`,d=cheerio.load(o.markup),u=findRequiredPartials(d);await generateComponent(c,a,a,o,"prefab-component-ts","prefab-component-script",!1,p);const C=s[a];for(var l=0;l<C.length;l++)await generatePagePartialComponent(g,t,C[l].name,C[l].type,c,a,e,m,p);await writePrefabModuleTsFile(a,c,o.requiredWMComponents,o.hasCustomElement,u)}if(!isPrefabProject(t)){if(p){const i=getLayoutsDirPath(e);for(let s of a)await generateLayoutComponent(i,t,s.name,s.type,r,s.prefabName,e,m,p,n,o)}for(let a of n)await generatePagePartialComponent(g,t,a.name,a.type,r,a.prefabName,e,m,p)}},generateLayoutComponent=async(e,t,a,n,o,i,r,s,m,p,g)=>{await generatePagePartialComponent(e,t,a,n,o,i,r,s,m,p,g)};module.exports={generateComponents:generateComponents,generatePagePartialComponent:generatePagePartialComponent};
|