UNPKG

ucbuilder

Version:

:Shree Ganeshay Namah: new way app design

187 lines (184 loc) 9.01 kB
import { ucUtil } from "../global/ucUtil.js"; import { nodeFn } from "../renderer/nodeFn.js"; import { TemplateMaker } from "./TemplateMaker.js"; /*export const ASSETS = { "js.tpt.code": import('../../assets/ucbuilder/templates/js.tpt.code?raw'), "js.tpt.designer": import('../../assets/ucbuilder/templates/js.tpt.designer?raw'), "js.tpt.style": import('../../assets/ucbuilder/templates/js.tpt.style?raw'), "js.uc.code": import('../../assets/ucbuilder/templates/js.uc.code?raw'), "js.uc.designer": import('../../assets/ucbuilder/templates/js.uc.designer?raw'), "js.uc.style": import('../../assets/ucbuilder/templates/js.uc.style?raw'), "ts.tpt.code": import('../../assets/ucbuilder/templates/ts.tpt.code?raw'), "ts.tpt.designer": import('../../assets/ucbuilder/templates/ts.tpt.designer?raw'), "ts.tpt.style": import('../../assets/ucbuilder/templates/ts.tpt.style?raw'), "ts.uc.code": import('../../assets/ucbuilder/templates/ts.uc.code?raw'), "ts.uc.designer": import('../../assets/ucbuilder/templates/ts.uc.designer?raw'), "ts.uc.style": import('../../assets/ucbuilder/templates/ts.uc.style?raw'), }*/ export class commonGenerator { rows = []; //DEFAULT_TEMPLEATES: SourceTypeNode; // getfile(pth: string) { // return nodeFn.fs.readFileSync(nodeFn.path.resolveFilePath(import.meta.url, ucUtil.devEsc(pth))); // } //getFileX() /* private initTemplates() { this.DEFAULT_TEMPLEATES = { JS: { TPT: { CODE: this.getfile('{:../../../assets/buildTempates/js/tpt/codefile.php}'), DESIGNER: this.getfile('{:../../../assets/buildTempates/js/tpt/designer.php}'), STYLE: this.getfile('{:../../../assets/buildTempates/js/tpt/styles.css}'), }, UC: { CODE: this.getfile('{:../../../assets/buildTempates/js/uc/codefile.php}'), DESIGNER: this.getfile('{:../../../assets/buildTempates/js/uc/designer.php}'), STYLE: this.getfile('{:../../../assets/buildTempates/js/uc/styles.css}'), }, }, TS: { TPT: { CODE: this.getfile('{:../../../assets/buildTempates/ts/tpt/codefile.php}'), DESIGNER: this.getfile('{:../../../assets/buildTempates/ts/tpt/designer.php}'), STYLE: this.getfile('{:../../../assets/buildTempates/ts/tpt/styles.css}'), }, UC: { CODE: this.getfile('{:../../../assets/buildTempates/ts/uc/codefile.php}'), DESIGNER: this.getfile('{:../../../assets/buildTempates/ts/uc/designer.php}'), STYLE: this.getfile('{:../../../assets/buildTempates/ts/uc/styles.css}'), }, } } } private _CodeFilesNode(type: 'js' | 'ts', extType: SpecialExtType): CodeFilesNode { switch (type) { case 'js': return _BaseTypeNode(this.DEFAULT_TEMPLEATES.JS, extType); case 'ts': return _BaseTypeNode(this.DEFAULT_TEMPLEATES.TS, extType); } function _BaseTypeNode(parent: BaseTypeNode, extType: SpecialExtType): CodeFilesNode { switch (extType) { case '.tpt': return parent.TPT; case '.uc': return parent.UC; } return undefined; } return undefined; }*/ designerTMPLT = {}; codefileTMPLT = {}; styleTMPLT = {}; tMaker = new TemplateMaker(import.meta.url); //dTpt = '' as string; constructor() { //this.initTemplates(); //this.rgxManage = new regsManage(); // this.dTpt = //console.log(this.DEFAULT_TEMPLEATES); } /*Events = { onDemandDesignerFile: (type: 'js' | 'ts', extType: SpecialExtType) => { return this._CodeFilesNode(type, extType).DESIGNER; }, onDemandCodeFile: (type: 'js' | 'ts', extType: SpecialExtType) => { return this._CodeFilesNode(type, extType).CODE; }, onDemandStyleFile: (type: 'js' | 'ts', extType: SpecialExtType) => { return this._CodeFilesNode(type, extType).STYLE; } }*/ //rgxManage: regsManage; static ensureDirectoryExistence(filePath) { const dirname = nodeFn.path.dirname(filePath); if (!nodeFn.fs.existsSync(dirname)) { nodeFn.fs.mkdirSync(dirname, { recursive: true }); } /*var dirname = nodeFn.path.dirname(filePath); if (nodeFn.fs.existsSync(dirname)) { return true; } this.ensureDirectoryExistence(dirname); nodeFn.fs.mkdirSync(dirname);*/ } static readTemplate(type, extType, fileType) { let tptFileName = `${type}${extType}${fileType}`; const tptDirpath = ucUtil.devEsc(`{:../../assets/ucbuilder/templates}`); let fpath = nodeFn.path.resolve(`assets/ucbuilder/templates/${tptFileName}`); fpath = nodeFn.path.resolveFilePath(import.meta.url, nodeFn.path.join(tptDirpath, tptFileName)); const data = nodeFn.fs.readFileSync(fpath, 'binary'); return data; } static templateUnMapped = new Map(); filex(type, extType, fileType) { let tptFileName = `${type}${extType}${fileType}`; if (commonGenerator.templateUnMapped.has(tptFileName)) return commonGenerator.templateUnMapped.get(tptFileName); else { /*if (!nodeFn.fs.existsSync(fpath)) { return ASSETS[tptFileName]; }*/ const data = commonGenerator.readTemplate(type, extType, fileType); const _fn = this.tMaker.compileTemplate(data); commonGenerator.templateUnMapped.set(tptFileName, _fn); return _fn; } } generateFiles(rows = []) { let _this = this; console.log(rows); if (rows == undefined || rows.length == 0) return; this.rows = rows; let _data = ""; const pref = this.rows[0]?.src.callerProject.config.preference; let dirDeclaration = pref?.dirDeclaration; // let fileWisePath = pref?.fileWisePath; /* if (pref != undefined) { }*/ const declareEntries = Object.entries(dirDeclaration); for (let i = 0, len = this.rows.length; i < len; i++) { const row = this.rows[i]; //let srctype = row.src.projectInfo.config.type; let uctype = row.src.extCode; let codeFileSrctype = 'code', designerFileSrctype = 'designer'; /*if (srctype == 'js') { codeFileSrctype = '.js'; designerFileSrctype = '.designer.js'; } else { codeFileSrctype = 'code'; designerFileSrctype = 'designer'; }*/ // if (pref.outDir) continue; for (const [decName, fTypeInfo] of declareEntries) { if (decName == 'out') continue; let srctype = 'ts'; //fTypeInfo.fileWisePath.code.extension["#_trim"]('.'); commonGenerator.ensureDirectoryExistence(row.src.pathOf[designerFileSrctype]); _data = this.filex(srctype, uctype, '.designer')(row); nodeFn.fs.writeFileSync(row.src.pathOf[designerFileSrctype], _data); if (row.htmlFileContent != undefined) nodeFn.fs.writeFileSync(`${row.src.pathOf.html}`, row.htmlFileContent); if (!nodeFn.fs.existsSync(row.src.pathOf[codeFileSrctype])) { _data = this.filex(srctype, uctype, '.code')(row); nodeFn.fs.writeFileSync(row.src.pathOf[codeFileSrctype], _data); } if (!nodeFn.fs.existsSync(row.src.pathOf.scss)) { _data = this.filex(srctype, uctype, '.style')(row); nodeFn.fs.writeFileSync(row.src.pathOf.scss, _data); } } /* _data = _this.tMaker.compileTemplate(this.filex(srctype, uctype, '.designer'))(row); nodeFn.fs.writeFileSync(row.src.pathOf[designerFileSrctype], _data); if (row.htmlFileContent != undefined) nodeFn.fs.writeFileSync(`${row.src.pathOf.html}`, row.htmlFileContent); if (!nodeFn.fs.existsSync(row.src.pathOf[codeFileSrctype])) { _data = _this.tMaker.compileTemplate(this.filex(srctype, uctype, '.code'))(row); nodeFn.fs.writeFileSync(row.src.pathOf[codeFileSrctype], _data); } if (!nodeFn.fs.existsSync(row.src.pathOf.scss)) { _data = _this.tMaker.compileTemplate(this.filex(srctype, uctype, '.style'))(row); nodeFn.fs.writeFileSync(row.src.pathOf.scss, _data); }*/ } } } //# sourceMappingURL=commonGenerator.js.map