generate src wwws

This commit is contained in:
2025-01-27 15:25:43 +01:00
parent c9504f8dae
commit d96018f8a1
2 changed files with 32 additions and 6 deletions

View File

@@ -16,6 +16,15 @@ const log = conf.api.activelog.includes(currentmod);
const Wwws = {};
Wwws.getwco = (wconame, ctx) => {
/**
* In a webpage to add a wco
* <script src="/api/adminapi/wwws/getwco/wco.js?wcotribe=adminapi&tribe=adminapi&xapp=admin&pagename=apxid&code=enjoy"></script>
* This will update /tribe/objects/wwws/itm/xapp.json
* A wco has a /adminapi/objects/wco/itm/wconame.json
*
*
*
*/
const filereq = `../${ctx.wcotribe}/objects/wco/${wconame}/${wconame}.js`;
const wcoconf = `../${ctx.wcotribe}/objects/wco/itm/${wconame}.json`;
if (!fs.existsSync(filereq) || !fs.existsSync(wcoconf)) {
@@ -32,13 +41,28 @@ Wwws.getwco = (wconame, ctx) => {
const webconf = `../${ctx.tribe}/objects/wwws/itm/${ctx.xapp}.json`;
const wcoinfo = fs.readJSONSync(wcoconf);
const webpage = fs.readJSONSync(webconf);
// check that webconf for tailwindcsscontent property exist for this wco request
const pathtocheckfortw=[`../adminapi/objects/wco/${wconame}/*.{html,js,mustache}`,`../${ctx.tribe}/objects/wwws/${ctx.xapp}/src/**/*.{html,js,mustache}`]
if (!webconf.tailwindcsscontent){
webconf.tailwindcsscontent=[]
}
pathtocheckfortw.forEach(tw=>{
if (!webconf.tailwindcsscontent.includes(tw)){
webconf.tailwindcsscontent.push(tw)
}
})
// check that all tpl for this compoent are well in pages tpl object
if (wcoinfo.tpl && Object.keys(wcoinfo.tpl).length > 0) {
Object.keys(wcoinfo.tpl).forEach((t) => {
//console.log(ctx.pagename,"---",t)
//console.log(Object.keys(webpage.pages[ctx.pagename].tpl))
if (!Object.keys(webpage.pages[ctx.pagename].tpl).includes(t)) {
//console.log(wcoinfo.tpl[t])
webpage.pages[ctx.pagename].tpl[t] = wcoinfo.tpl[t];
}
});
}
// check that tpldata exist for the wco, if not create them with template data example into the project
if (wcoinfo.tpldatamodel && Object.keys(wcoinfo.tpldatamodel).length > 0) {
Object.keys(wcoinfo.tpldatamodel).forEach((t) => {
const pathtpldata = `../${ctx.tribe}/objects/wwws/${ctx.xapp}/src/tpldata/${wconame}/${t}`;
@@ -58,6 +82,7 @@ Wwws.getwco = (wconame, ctx) => {
});
});
}
// check if referential are there for this wco
if (wcoinfo.ref && Object.keys(wcoinfo.ref).length > 0) {
Object.keys(wcoinfo.ref).forEach((t) => {
t = t.replace("{{tribe}}", ctx.tribe);
@@ -66,6 +91,7 @@ Wwws.getwco = (wconame, ctx) => {
}
});
}
//check that schema are also their for wco
if (wcoinfo.schema && wcoinfo.schema.length > 0)
[
wcoinfo.schema.forEach((s) => {
@@ -75,7 +101,8 @@ Wwws.getwco = (wconame, ctx) => {
}
}),
];
fs.outputJSONSync(webconf, webpage);
// save the conf for update localdb when the web page request it
fs.outputJSONSync(webconf, webpage, {spaces:2});
return {
status: 200,
ref: "Wwws",