import chalk from 'chalk' import { exec } from 'child_process' import fs from 'fs' import jszip from 'jszip' import path from 'path' export interface ftCreateProjectArgs { org: string; } export interface ftModelArgs { withjsonannotation: boolean; } export interface ftInitArgs { withjsonannotation: boolean; } export interface ftComponentArgs { stless: boolean; stfull: boolean; sidemenu: boolean; } export interface TsModelArgs { stringid: boolean; controlfields: boolean; codeid: boolean; uuid: boolean; autogenerate: boolean; empty: boolean; inherited: boolean; } export interface TsReportTemplateArgs { boletobancario: string; } export interface TsEnvArgs { environment: string; install: boolean; } export interface TsDbArgs { mariadb: boolean; mysql: boolean; mssql: boolean; oraclesid: boolean; oracleservicename: boolean; postgres: boolean; sqlite: boolean; main: boolean; } export interface NgPageArgs { crud: boolean; } export interface NgServiceArgs { crud: boolean; route: string; } export interface TsControllerArgs { crudc: boolean; crud: boolean; cron: boolean; custom: boolean; stringid: boolean; uuid: boolean; codeid: boolean; controlfields: boolean; autogenerate: boolean; } export interface NameConfig { table: string; model: string; file: string; path: string; } export enum TypeSnippets { Ts, Ng, Ft } export enum TypeDir { main, api, dist, apicontroller, apishared, apimodels, apiviews, apireport, template, vscodedef, ngservice, ngpage, startyproject, sql, sqlDest, reportTemplate, ftSource, ftLib, ftApp, ftModules, ftModels, ftShared, ftComponents, pySource } export enum TypeTemplate { tsdb_mariadb, tsdb_mysql, tsdb_mssql, tsdb_oracleservicename, tsdb_oraclesid, tsdb_postgres, tsdb_sqlite, tspm2_json, tsapp_json, tsmodel_empty, tsview, tsmodel_codeid_control_fields, tsmodel_codeid, tsmodel_control_fields, tsmodel_control_fields_auto_incrment, tsmodel_control_fields_inherited, tsmodel_stringid_control_fields, tsmodel_stringid, tsmodel_uuid_control_fields, tsmodel_uuid, tsmodel, tsmodel_auto_increment, tsmodel_inherited, tsjob, tsjob_websocket, jrboleto_bancario, ngsnippets_websocket_server, tscontroller_cron, tscontroller_crud, tscontroller_custom, tssnippets_codeid, tssnippets_http_delete, tssnippets_http_get, tssnippets_http_post, tssnippets_http_put, tssnippets_stringid, tssnippets_uuid, tssnippets_evt, tssnippets_evtvoid, tssnippets_cronmethod, tssnippets_evtwebsocketclientemessage, tssnippets_evtwebsocketclienteconnection, tssnippets_evtwebsocketclienteclose, tssnippets_evttokenaccessbeforevalidation, tssnippets_evttokenaccessaftervalidation, tssnippets_evtmodelbeforeupdate, tssnippets_evtmodelbeforesoftdelete, tssnippets_evtmodelbeforeinsert, tssnippets_evtmodelbeforedelete, tssnippets_evtmodelafterupdate, tssnippets_evtmodelaftersoftdelete, tssnippets_evtmodelafterinsert, tssnippets_evtmodelafterdelete, tssnippets_evtmappingroutes, tssnippets_evterrorrouter, tssnippets_evterrorcron, tssnippets_evtendrouter, tssnippets_evtendcron, tssnippets_evtcreatecron, tssnippets_evtcreateapiserver, tssnippets_evtbeginrouter, tssnippets_evtbegincron, tssnippets_evtbeginprocess, tssnippets_evtendprocess, tssnippets_evterrorprocess, ngservice_crud, ngservice, ngcomponent_html, ngcomponent_crud_html, ngcomponent_scss, ngcomponent_ts, ngcomponent_crud_ts, ngmodule_page, ngmodule_component, ngrouting_module, ngwebsocket_service, ftapp_module, ftapp_widget, fthttp_overrides_custom, ftcomponent_exception, ftmain, ftmodel, ftmodel_with_annotation, ftmodel_with_annotation_g, ftmodule, ftpage, ftpubspec, ftpubspec_with_annotation, ftrepository, ftpstore_g, ftstore, ftwidget_main_menu, ftwidget_stfull, ftwidget_stless, pystart, pyinstall, pyuninstall } export class Commands { static unZipFile(fileZip: Buffer): Promise { return new Promise((resolve, reject) => { try { jszip.loadAsync(fileZip).then(async (zip) => { resolve(zip) }) } catch (error) { reject(error) } }) } static changeValue(value: string, key: any, newValue: any) { while (true) { if (String(value).indexOf(key) === -1) break value = String(value).replace(key, newValue) } return value } static changeIndex(value: string, params: any[]) { for (let i = 0; i < params.length; i++) { let chave = '{' + i + '}' while (true) { if (String(value).indexOf(chave) === -1) break value = String(value).replace(chave, params[i]) } } return value } static templatePath(typeTemplate: TypeTemplate): string { let templateFileName = this.directory(TypeDir.template); if (typeTemplate == TypeTemplate.tsmodel_codeid_control_fields) templateFileName = path.join(templateFileName, "ts-model-codeid-control-fields.template") else if (typeTemplate == TypeTemplate.tsmodel_control_fields_auto_incrment) templateFileName = path.join(templateFileName, "ts-model-control-fields-auto-increment.template") else if (typeTemplate == TypeTemplate.tsmodel_auto_increment) templateFileName = path.join(templateFileName, "ts-model-auto-increment.template") else if (typeTemplate == TypeTemplate.tsmodel_codeid) templateFileName = path.join(templateFileName, "ts-model-codeid.template") else if (typeTemplate == TypeTemplate.tsmodel_control_fields) templateFileName = path.join(templateFileName, "ts-model-control-fields.template") else if (typeTemplate == TypeTemplate.tsmodel_stringid_control_fields) templateFileName = path.join(templateFileName, "ts-model-stringid-control-fields.template") else if (typeTemplate == TypeTemplate.tsmodel_stringid) templateFileName = path.join(templateFileName, "ts-model-stringid.template") else if (typeTemplate == TypeTemplate.tsmodel_uuid_control_fields) templateFileName = path.join(templateFileName, "ts-model-uuid-control-fields.template") else if (typeTemplate == TypeTemplate.tsmodel_uuid) templateFileName = path.join(templateFileName, "ts-model-uuid.template") else if (typeTemplate == TypeTemplate.tsmodel) templateFileName = path.join(templateFileName, "ts-model.template") else if (typeTemplate == TypeTemplate.tsview) templateFileName = path.join(templateFileName, "ts-view.template") else if (typeTemplate == TypeTemplate.tsjob) templateFileName = path.join(templateFileName, "ts-job.template") else if (typeTemplate == TypeTemplate.tscontroller_cron) templateFileName = path.join(templateFileName, "ts-controller-cron.template") else if (typeTemplate == TypeTemplate.tscontroller_crud) templateFileName = path.join(templateFileName, "ts-controller-crud.template") else if (typeTemplate == TypeTemplate.tscontroller_custom) templateFileName = path.join(templateFileName, "ts-controller-custom.template") else if (typeTemplate == TypeTemplate.tssnippets_codeid) templateFileName = path.join(templateFileName, "ts-snippets-codeid.template") else if (typeTemplate == TypeTemplate.tssnippets_http_delete) templateFileName = path.join(templateFileName, "ts-snippets-httpdelete.template") else if (typeTemplate == TypeTemplate.tssnippets_http_get) templateFileName = path.join(templateFileName, "ts-snippets-httpget.template") else if (typeTemplate == TypeTemplate.tssnippets_http_post) templateFileName = path.join(templateFileName, "ts-snippets-httppost.template") else if (typeTemplate == TypeTemplate.tssnippets_http_put) templateFileName = path.join(templateFileName, "ts-snippets-httpput.template") else if (typeTemplate == TypeTemplate.tssnippets_stringid) templateFileName = path.join(templateFileName, "ts-snippets-stringid.template") else if (typeTemplate == TypeTemplate.tssnippets_uuid) templateFileName = path.join(templateFileName, "ts-snippets-uuid.template") else if (typeTemplate == TypeTemplate.tssnippets_cronmethod) templateFileName = path.join(templateFileName, "ts-snippets-cronmethod.template") else if (typeTemplate == TypeTemplate.ngservice_crud) templateFileName = path.join(templateFileName, "ng-service-crud.template") else if (typeTemplate == TypeTemplate.ngservice) templateFileName = path.join(templateFileName, "ng-service.template") else if (typeTemplate == TypeTemplate.tssnippets_evt) templateFileName = path.join(templateFileName, "ts-snippets-evt.template") else if (typeTemplate == TypeTemplate.tssnippets_evtvoid) templateFileName = path.join(templateFileName, "ts-snippets-evt-void.template") else if (typeTemplate == TypeTemplate.tspm2_json) templateFileName = path.join(templateFileName, "ts-pm2-json.template") else if (typeTemplate == TypeTemplate.tsapp_json) templateFileName = path.join(templateFileName, "ts-app-json.template") else if (typeTemplate == TypeTemplate.jrboleto_bancario) templateFileName = path.join(templateFileName, "jr-boleto-bancario.template") else if (typeTemplate == TypeTemplate.ftapp_module) templateFileName = path.join(templateFileName, "ft-app-module.template") else if (typeTemplate == TypeTemplate.ftapp_widget) templateFileName = path.join(templateFileName, "ft-app-widget.template") else if (typeTemplate == TypeTemplate.fthttp_overrides_custom) templateFileName = path.join(templateFileName, "ft-http-overrides-custom.template") else if (typeTemplate == TypeTemplate.ftmain) templateFileName = path.join(templateFileName, "ft-main.template") else if (typeTemplate == TypeTemplate.ftmodel) templateFileName = path.join(templateFileName, "ft-model.template") else if (typeTemplate == TypeTemplate.ftmodel_with_annotation) templateFileName = path.join(templateFileName, "ft-model-with-annotation.template") else if (typeTemplate == TypeTemplate.ftmodel_with_annotation_g) templateFileName = path.join(templateFileName, "ft-model-with-annotation.g.template") else if (typeTemplate == TypeTemplate.ftmodule) templateFileName = path.join(templateFileName, "ft-module.template") else if (typeTemplate == TypeTemplate.ftpage) templateFileName = path.join(templateFileName, "ft-page.template") else if (typeTemplate == TypeTemplate.ftpubspec) templateFileName = path.join(templateFileName, "ft-pubspec.template") else if (typeTemplate == TypeTemplate.ftpubspec_with_annotation) templateFileName = path.join(templateFileName, "ft-pubspec-with-annotation.template") else if (typeTemplate == TypeTemplate.ftrepository) templateFileName = path.join(templateFileName, "ft-repository.template") else if (typeTemplate == TypeTemplate.ftpstore_g) templateFileName = path.join(templateFileName, "ft-store.g.template") else if (typeTemplate == TypeTemplate.ftstore) templateFileName = path.join(templateFileName, "ft-store.template") else if (typeTemplate == TypeTemplate.ftwidget_main_menu) templateFileName = path.join(templateFileName, "ft-widget-main-menu.template") else if (typeTemplate == TypeTemplate.ftwidget_stfull) templateFileName = path.join(templateFileName, "ft-widget-stfull.template") else if (typeTemplate == TypeTemplate.ftwidget_stless) templateFileName = path.join(templateFileName, "ft-widget-stless.template") else if (typeTemplate == TypeTemplate.ftcomponent_exception) templateFileName = path.join(templateFileName, "ft-component-exception.template") else if (typeTemplate == TypeTemplate.pystart) templateFileName = path.join(templateFileName, "py-start.template") else if (typeTemplate == TypeTemplate.pyinstall) templateFileName = path.join(templateFileName, "py-install.template") else if (typeTemplate == TypeTemplate.pyuninstall) templateFileName = path.join(templateFileName, "py-uninstall.template") else if (typeTemplate == TypeTemplate.tsmodel_empty) templateFileName = path.join(templateFileName, "ts-model-custom.template") else if (typeTemplate == TypeTemplate.tsdb_mariadb) templateFileName = path.join(templateFileName, "ts-db-mariadb.template") else if (typeTemplate == TypeTemplate.tsdb_mssql) templateFileName = path.join(templateFileName, "ts-db-mssql.template") else if (typeTemplate == TypeTemplate.tsdb_mysql) templateFileName = path.join(templateFileName, "ts-db-mysql.template") else if (typeTemplate == TypeTemplate.tsdb_oracleservicename) templateFileName = path.join(templateFileName, "ts-db-oracle-servicename.template") else if (typeTemplate == TypeTemplate.tsdb_oraclesid) templateFileName = path.join(templateFileName, "ts-db-oracle-sid.template") else if (typeTemplate == TypeTemplate.tsdb_postgres) templateFileName = path.join(templateFileName, "ts-db-postgres.template") else if (typeTemplate == TypeTemplate.tsdb_sqlite) templateFileName = path.join(templateFileName, "ts-db-sqlite.template") else if (typeTemplate == TypeTemplate.tsmodel_inherited) templateFileName = path.join(templateFileName, "ts-model-inherited.template") else if (typeTemplate == TypeTemplate.tsmodel_control_fields_inherited) templateFileName = path.join(templateFileName, "ts-model-control-fields-inherited.template") else if (typeTemplate == TypeTemplate.ngcomponent_html) templateFileName = path.join(templateFileName, "ng-component-html.template") else if (typeTemplate == TypeTemplate.ngcomponent_crud_html) templateFileName = path.join(templateFileName, "ng-component-crud-html.template") else if (typeTemplate == TypeTemplate.ngcomponent_scss) templateFileName = path.join(templateFileName, "ng-component-scss.template") else if (typeTemplate == TypeTemplate.ngcomponent_ts) templateFileName = path.join(templateFileName, "ng-component-ts.template") else if (typeTemplate == TypeTemplate.ngcomponent_crud_ts) templateFileName = path.join(templateFileName, "ng-component-crud-ts.template") else if (typeTemplate == TypeTemplate.ngmodule_page) templateFileName = path.join(templateFileName, "ng-module-page.template") else if (typeTemplate == TypeTemplate.ngmodule_component) templateFileName = path.join(templateFileName, "ng-module-component.template") else if (typeTemplate == TypeTemplate.ngrouting_module) templateFileName = path.join(templateFileName, "ng-routing-module.template") else if (typeTemplate == TypeTemplate.tssnippets_evtwebsocketclientemessage) templateFileName = path.join(templateFileName, "ts-snippets-evt-websocketclientemessage.template") else if (typeTemplate == TypeTemplate.tssnippets_evtwebsocketclienteconnection) templateFileName = path.join(templateFileName, "ts-snippets-evt-websocketclienteconnection.template") else if (typeTemplate == TypeTemplate.tssnippets_evtwebsocketclienteclose) templateFileName = path.join(templateFileName, "ts-snippets-evt-websocketclienteclose.template") else if (typeTemplate == TypeTemplate.tssnippets_evttokenaccessbeforevalidation) templateFileName = path.join(templateFileName, "ts-snippets-evt-tokenaccessbeforevalidation.template") else if (typeTemplate == TypeTemplate.tssnippets_evttokenaccessaftervalidation) templateFileName = path.join(templateFileName, "ts-snippets-evt-tokenaccessaftervalidation.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmodelbeforeupdate) templateFileName = path.join(templateFileName, "ts-snippets-evt-modelbeforeupdate.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmodelbeforesoftdelete) templateFileName = path.join(templateFileName, "ts-snippets-evt-modelbeforesoftdelete.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmodelbeforeinsert) templateFileName = path.join(templateFileName, "ts-snippets-evt-modelbeforeinsert.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmodelbeforedelete) templateFileName = path.join(templateFileName, "ts-snippets-evt-modelbeforedelete.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmodelafterupdate) templateFileName = path.join(templateFileName, "ts-snippets-evt-modelafterupdate.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmodelaftersoftdelete) templateFileName = path.join(templateFileName, "ts-snippets-evt-modelaftersoftdelete.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmodelafterinsert) templateFileName = path.join(templateFileName, "ts-snippets-evt-modelafterinsert.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmodelafterdelete) templateFileName = path.join(templateFileName, "ts-snippets-evt-modelafterdelete.template") else if (typeTemplate == TypeTemplate.tssnippets_evtmappingroutes) templateFileName = path.join(templateFileName, "ts-snippets-evt-mappingroutes.template") else if (typeTemplate == TypeTemplate.tssnippets_evterrorrouter) templateFileName = path.join(templateFileName, "ts-snippets-evt-errorrouter.template") else if (typeTemplate == TypeTemplate.tssnippets_evterrorcron) templateFileName = path.join(templateFileName, "ts-snippets-evt-errorcron.template") else if (typeTemplate == TypeTemplate.tssnippets_evtendrouter) templateFileName = path.join(templateFileName, "ts-snippets-evt-endrouter.template") else if (typeTemplate == TypeTemplate.tssnippets_evtendcron) templateFileName = path.join(templateFileName, "ts-snippets-evt-endcron.template") else if (typeTemplate == TypeTemplate.tssnippets_evtcreatecron) templateFileName = path.join(templateFileName, "ts-snippets-evt-createcron.template") else if (typeTemplate == TypeTemplate.tssnippets_evtcreateapiserver) templateFileName = path.join(templateFileName, "ts-snippets-evt-createapiserver.template") else if (typeTemplate == TypeTemplate.tssnippets_evtbeginrouter) templateFileName = path.join(templateFileName, "ts-snippets-evt-beginrouter.template") else if (typeTemplate == TypeTemplate.tssnippets_evtbegincron) templateFileName = path.join(templateFileName, "ts-snippets-evt-begincron.template") else if (typeTemplate == TypeTemplate.ngsnippets_websocket_server) templateFileName = path.join(templateFileName, "ng-snippets-websocket-server.template") else if (typeTemplate == TypeTemplate.ngwebsocket_service) templateFileName = path.join(templateFileName, "ng-websocket-service.template") else if (typeTemplate == TypeTemplate.tsjob_websocket) templateFileName = path.join(templateFileName, "ts-job-websocket.template") else if (typeTemplate == TypeTemplate.tssnippets_evtbeginprocess) templateFileName = path.join(templateFileName, "ts-snippets-evt-beginprocess.template") else if (typeTemplate == TypeTemplate.tssnippets_evtendprocess) templateFileName = path.join(templateFileName, "ts-snippets-evt-endprocess.template") else if (typeTemplate == TypeTemplate.tssnippets_evterrorprocess) templateFileName = path.join(templateFileName, "ts-snippets-evt-errorprocess.template") return templateFileName; } static tamplateToFile(typeTemplate: TypeTemplate, fileName: string, params: string[]) { let templateContent = Commands.template(typeTemplate, params); fs.writeFileSync(fileName, templateContent); } static template(typeTemplate: TypeTemplate, params: string[], mainDirectory: string = ''): string { let templateFileName = Commands.templatePath(typeTemplate); let templateContent = fs.readFileSync(templateFileName).toString(); templateContent = Commands.changeIndex(templateContent, params); return templateContent; } static directory(typeDir: TypeDir): string { if (typeDir == TypeDir.api) return path.resolve(`./src`) if (typeDir == TypeDir.dist) return path.resolve(`./dist`) if (typeDir == TypeDir.apicontroller) return path.resolve(`./src/controllers`) if (typeDir == TypeDir.apishared) return path.resolve(`./dist/shared`) if (typeDir == TypeDir.apimodels) return path.resolve(`./src/models`) if (typeDir == TypeDir.apiviews) return path.resolve(`./src/views`) if (typeDir == TypeDir.apireport) return path.resolve(`./src/report`) if (typeDir == TypeDir.template) return path.join(__dirname, `template`) if (typeDir == TypeDir.vscodedef) return path.resolve(`./.vscode`) if (typeDir == TypeDir.ngservice) return path.resolve(`./src/app/service`) if (typeDir == TypeDir.ngpage) return path.resolve(`./src/app/pages`) if (typeDir == TypeDir.startyproject) return path.join(__dirname, `shared`) if (typeDir == TypeDir.sql) return path.resolve(`./src/sql`) if (typeDir == TypeDir.sqlDest) return path.resolve(`./dist/sql`) if (typeDir == TypeDir.reportTemplate) return path.resolve(`./src/report/template`) if (typeDir == TypeDir.ftSource) return path.resolve(`./`) if (typeDir == TypeDir.ftLib) return path.resolve(`./lib`) if (typeDir == TypeDir.ftApp) return path.resolve(`./lib/app`) if (typeDir == TypeDir.ftModules) return path.resolve(`./lib/app/modules`) if (typeDir == TypeDir.ftModels) return path.resolve(`./lib/app/models`) if (typeDir == TypeDir.ftShared) return path.resolve(`./lib/app/shared`) if (typeDir == TypeDir.ftComponents) return path.resolve(`./lib/app/components`) if (typeDir == TypeDir.pySource) return path.resolve(`./`) return path.resolve(`./`) } static error(message: string): void { console.log(chalk.bgRed(chalk.white(message))); } static info(message: string): void { console.log(chalk.cyan(message)) } static execCommand(command: string): Promise { return new Promise((resolve, reject) => { exec(command, (error) => { if (error) { return reject(error) } resolve() }) }) } static nameConfig(name: string, type: string = 'model'): NameConfig { name = Commands.changeValue(name, ' ', '_'); let configAt: NameConfig = {}; configAt.table = name.split("/").length > 1 ? name.split("/")[name.split("/").length - 1] : name; configAt.model = configAt.table[0].toUpperCase() + configAt.table.slice(1); configAt.model = Commands.changeValue(configAt.model, '_', '') configAt.table = Commands.changeValue(configAt.table, '_', '') configAt.file = `${configAt.table}_${type}.ts` if (name.split("/").length > 1) { for (let i = 0; i <= name.split("/").length - 2; i++) { if (configAt.path) configAt.path += `/${name.split("/")[i]}` else configAt.path = name.split("/")[i] } } else configAt.path = ""; return configAt; } static tsDb(name: string, args: TsDbArgs) { let configNameAt = Commands.nameConfig(name); let appName = `${configNameAt.table}.db.json`; let main = "false" if (args.main) main = 'true'; let templateList = []; if (args.mariadb) templateList.push(TypeTemplate.tsdb_mariadb) if (args.mysql) templateList.push(TypeTemplate.tsdb_mysql) if (args.mssql) templateList.push(TypeTemplate.tsdb_mssql) if (args.oracleservicename) templateList.push(TypeTemplate.tsdb_oracleservicename) if (args.oraclesid) templateList.push(TypeTemplate.tsdb_oraclesid) if (args.postgres) templateList.push(TypeTemplate.tsdb_postgres) if (args.sqlite) templateList.push(TypeTemplate.tsdb_sqlite) if (templateList.length > 1) return Commands.error("Only one database type is allowed to be selected!"); let templateContent = Commands.template(templateList[0], [main]); let pathApp = Commands.directory(TypeDir.api); pathApp = path.join(pathApp, appName); if (fs.existsSync(pathApp)) return Commands.error(`The ${appName} already exists!`); fs.writeFileSync(pathApp, templateContent); Commands.createSnippets(TypeSnippets.Ts); Commands.info("The Db script was created successfully!"); } static async ngWebSocket() { let configNameAt = Commands.nameConfig("websocket"); let pathService = Commands.directory(TypeDir.ngservice); if (configNameAt.path) pathService = path.join(pathService, configNameAt.path) if (!fs.existsSync(pathService)) fs.mkdirSync(pathService, { recursive: true }); let router = "" if (configNameAt.path) router = `${configNameAt.path}/${configNameAt.table}` else router = configNameAt.table; Commands.createSnippets(TypeSnippets.Ng); Commands.tamplateToFile(TypeTemplate.ngwebsocket_service, path.join(pathService, `${configNameAt.table}.service.ts`), []); Commands.createSnippets(TypeSnippets.Ng); Commands.info("The websocket service was created successfully!"); } static async ngComponent(name: string) { let configNameAt = Commands.nameConfig(name); let command = `ng g c pages/${`${configNameAt.path}/${configNameAt.table}`} --skip-tests --style=scss --selector=cp-${configNameAt.table}` await Commands.execCommand(command); Commands.createSnippets(TypeSnippets.Ng); Commands.info("The Component was created successfully!"); } static ngPage(name: string, args: NgPageArgs) { let configNameAt = Commands.nameConfig(name); let pathPage = path.join(Commands.directory(TypeDir.ngpage), configNameAt.path); pathPage = path.join(pathPage, configNameAt.table); if (fs.existsSync(pathPage)) return Commands.error(`Page ${configNameAt.model} already exists!`) fs.mkdirSync(pathPage, { recursive: true }) Commands.tamplateToFile(args.crud ? TypeTemplate.ngcomponent_crud_html : TypeTemplate.ngcomponent_html, path.join(pathPage, `${configNameAt.table}.component.html`), [configNameAt.model, configNameAt.table]); Commands.tamplateToFile(TypeTemplate.ngcomponent_scss, path.join(pathPage, `${configNameAt.table}.component.scss`), [configNameAt.model, configNameAt.table]); Commands.tamplateToFile(args.crud ? TypeTemplate.ngcomponent_crud_ts : TypeTemplate.ngcomponent_ts, path.join(pathPage, `${configNameAt.table}.component.ts`), [configNameAt.model, configNameAt.table]); Commands.tamplateToFile(TypeTemplate.ngrouting_module, path.join(pathPage, `${configNameAt.table}-routing.module.ts`), [configNameAt.model, configNameAt.table]); Commands.tamplateToFile(TypeTemplate.ngmodule_page, path.join(pathPage, `${configNameAt.table}.module.ts`), [configNameAt.model, configNameAt.table]); Commands.createSnippets(TypeSnippets.Ng); Commands.info("The page was created successfully!"); } static ngService(name: string, args: NgServiceArgs) { let configNameAt = Commands.nameConfig(name); let typeTemplate = args.crud ? TypeTemplate.ngservice_crud : TypeTemplate.ngservice; let pathService = Commands.directory(TypeDir.ngservice); if (configNameAt.path) pathService = path.join(pathService, configNameAt.path) if (!fs.existsSync(pathService)) fs.mkdirSync(pathService, { recursive: true }); let router = "" if (configNameAt.path) router = `${configNameAt.path}/${configNameAt.table}` else router = configNameAt.table; Commands.createSnippets(TypeSnippets.Ng); Commands.tamplateToFile(typeTemplate, path.join(pathService, `${configNameAt.table}.service.ts`), [configNameAt.model, args.crud ? configNameAt.table : router, router]); Commands.createSnippets(TypeSnippets.Ng); Commands.info("The service was created successfully!"); } static tsView(name: string) { let configNameAt = Commands.nameConfig(name, 'view'); let templateContent = Commands.template(TypeTemplate.tsview, [configNameAt.table, configNameAt.model]); let pathView = Commands.directory(TypeDir.apiviews); if (configNameAt.path) pathView = path.join(pathView, configNameAt.path) if (!fs.existsSync(pathView)) fs.mkdirSync(pathView, { recursive: true }); pathView = path.join(pathView, configNameAt.file); if (fs.existsSync(pathView)) return Commands.error("The view model already exists!"); fs.writeFileSync(pathView, templateContent); Commands.createSnippets(TypeSnippets.Ts); Commands.info("The view model was created successfully!"); } static tsModel(name: string, args: TsModelArgs) { let configNameAt = Commands.nameConfig(name); let typeTemplate = args.empty ? TypeTemplate.tsmodel_empty : args.controlfields ? TypeTemplate.tsmodel_control_fields : TypeTemplate.tsmodel; if (Object.keys(args).length > 2) return Commands.error("Do not use combined generation commands!"); if (!args.empty) { if (args.autogenerate) typeTemplate = args.controlfields ? TypeTemplate.tsmodel_control_fields_auto_incrment : TypeTemplate.tsmodel_auto_increment; else if (args.codeid) typeTemplate = args.controlfields ? TypeTemplate.tsmodel_codeid_control_fields : TypeTemplate.tsmodel_codeid; else if (args.stringid) typeTemplate = args.controlfields ? TypeTemplate.tsmodel_stringid_control_fields : TypeTemplate.tsmodel_stringid; else if (args.uuid) typeTemplate = args.controlfields ? TypeTemplate.tsmodel_uuid_control_fields : TypeTemplate.tsmodel_uuid; else if (args.inherited) typeTemplate = args.controlfields ? TypeTemplate.tsmodel_control_fields_inherited : TypeTemplate.tsmodel_inherited; } let importBase = Commands.importBasePath(configNameAt.path); let templateContent = Commands.template(typeTemplate, [configNameAt.table, configNameAt.model, importBase]); let pathModel = Commands.directory(TypeDir.apimodels); if (configNameAt.path) pathModel = path.join(pathModel, configNameAt.path) if (!fs.existsSync(pathModel)) fs.mkdirSync(pathModel, { recursive: true }); pathModel = path.join(pathModel, configNameAt.file); if (fs.existsSync(pathModel)) return Commands.error("The model already exists!"); fs.writeFileSync(pathModel, templateContent); Commands.createSnippets(TypeSnippets.Ts); Commands.info("The model was created successfully!"); } static tsApp(args: TsEnvArgs) { let appName = args.environment ? `app.${args.environment}.json` : "app.json"; let templateContent = Commands.template(TypeTemplate.tsapp_json, []); let pathApp = Commands.directory(TypeDir.api); pathApp = path.join(pathApp, appName); if (fs.existsSync(pathApp)) return Commands.error(`The ${appName} already exists!`); fs.writeFileSync(pathApp, templateContent); Commands.createSnippets(TypeSnippets.Ts); Commands.info("The App script was created successfully!"); } static copyFolderSync(from: string, to: string) { if (!fs.existsSync(to)) fs.mkdirSync(to); fs.readdirSync(from).forEach(element => { if (fs.lstatSync(path.join(from, element)).isFile()) { fs.copyFileSync(path.join(from, element), path.join(to, element)); } else { Commands.copyFolderSync(path.join(from, element), path.join(to, element)); } }); } static async tsBuild(args: TsEnvArgs) { await Commands.execCommand(`cd ${Commands.directory(TypeDir.main)}`) if (fs.existsSync(Commands.directory(TypeDir.dist))) fs.rmSync(Commands.directory(TypeDir.dist), { recursive: true }) Commands.compileTs() Commands.info("Copy includes files...") if (!fs.existsSync(Commands.directory(TypeDir.dist))) fs.mkdirSync(Commands.directory(TypeDir.dist)) const pkgProject = require(path.resolve('./package.json')); let includes = pkgProject.includes; for (let i = 0; i < includes.length; i++) { let pathFile = path.join(Commands.directory(TypeDir.main), includes[i]) let pathFileDest = path.join(Commands.directory(TypeDir.dist), includes[i]) pathFileDest = String(pathFileDest).replace("src/", "") pathFileDest = String(pathFileDest).replace("src\\", "") if (!fs.existsSync(path.dirname(pathFileDest))) fs.mkdirSync(path.dirname(pathFileDest)) if (fs.statSync(pathFile).isDirectory()) Commands.copyFolderSync(pathFile, pathFileDest) else fs.copyFileSync(pathFile, pathFileDest) } if (fs.existsSync(Commands.directory(TypeDir.sql))) Commands.copyFolderSync(Commands.directory(TypeDir.sql), Commands.directory(TypeDir.sqlDest)); let env = args.environment ? `.${args.environment}` : "" let fileConfig = `app${env}.json`; if (!fs.existsSync(path.join(Commands.directory(TypeDir.api), fileConfig))) return Commands.error(`File config <${fileConfig}> not found!`) fs.copyFileSync(path.join(Commands.directory(TypeDir.api), fileConfig), path.join(Commands.directory(TypeDir.dist), "app.json")) fs.copyFileSync(path.join(Commands.directory(TypeDir.main), "package.json"), path.join(Commands.directory(TypeDir.dist), "package.json")) if (args.install) { Commands.info("Install packages.") await Commands.execCommand(`cd dist && npm i && cd ..`) } Commands.info("Build completed successfully.") } static tsReport(args: TsReportTemplateArgs) { if (args.boletobancario) { let reportName = `${args.boletobancario}.jrxml`; let templateContent = Commands.template(TypeTemplate.jrboleto_bancario, []); let pathReport = path.join(Commands.directory(TypeDir.reportTemplate), args.boletobancario); if (!fs.existsSync(pathReport)) fs.mkdirSync(pathReport); pathReport = path.join(pathReport, reportName); if (fs.existsSync(pathReport)) return Commands.error(`The ${pathReport} already exists!`); fs.writeFileSync(pathReport, templateContent); } Commands.createSnippets(TypeSnippets.Ts); Commands.info("The Report Template was created successfully!"); } static compileTs() { Commands.info("Project compilation started...") Commands.execCommand('tsc') } static tsPm2() { let templateContent = Commands.template(TypeTemplate.tspm2_json, []); let pathPm2 = Commands.directory(TypeDir.api); pathPm2 = path.join(pathPm2, "startpm2.json"); if (fs.existsSync(pathPm2)) return Commands.error("The startpm2.json already exists!"); fs.writeFileSync(pathPm2, templateContent); Commands.createSnippets(TypeSnippets.Ts); Commands.info("The Pm2 script was created successfully!"); } static tsInit() { let apiZipFile = path.join(Commands.directory(TypeDir.startyproject), 'api.zip'); let apiZipBuffer = fs.readFileSync(apiZipFile) Commands.unZipFile(apiZipBuffer).then(async (fileZip) => { let fileList = Object.keys(fileZip.files) for (const i in fileList) { const zipFile = fileZip.file(fileList[i]) if (!zipFile) { const directory = path.resolve(`./${fileList[i]}`) if (!fs.existsSync(directory)) { fs.mkdirSync(directory) } } else { const file = await zipFile.async("nodebuffer") const dirName = path.dirname(path.resolve(Commands.directory(TypeDir.main), fileList[i])) if (!fs.existsSync(dirName)) fs.mkdirSync(dirName) fs.writeFileSync(path.resolve(Commands.directory(TypeDir.main), fileList[i]), file) } } Commands.info("Installing packages...") await Commands.execCommand('npm i') Commands.info("Updating main package!...") await Commands.execCommand('npm i synapseapi') Commands.createSnippets(TypeSnippets.Ts); Commands.info("The starty project was created successfully!!"); }).catch((error) => Commands.error(error)) } static importBasePath(path: string): string { let importBase = ''; if (!path) { importBase = `../` } else { let pathClassSplit = path.split('/') let pathReturn = "../" for (let i = 0; i < pathClassSplit.length; i++) { pathReturn += "../" } importBase = pathReturn } return importBase; } static tsJob(name: string, id: string) { if (name.split("/").length > 1) return Commands.error("Jobs does not support subdirectory!"); id = id.replace(" ", "_") let jobPath = `${Commands.directory(TypeDir.api)}/${name.toLowerCase()}_job.ts`; let jobContent = Commands.template(TypeTemplate.tsjob, [id.toLowerCase()]); if (fs.existsSync(jobPath)) return Commands.error("The job already exists!"); fs.writeFileSync(jobPath, jobContent); const pkgProject = require(path.resolve('./package.json')); pkgProject.scripts[`start_${name.toLowerCase()}_job`] = `ts-node --files -r tsconfig-paths/register ./src/${name.toLowerCase()}_job` fs.writeFileSync(path.resolve('./package.json'), JSON.stringify(pkgProject, null, 2)) Commands.createSnippets(TypeSnippets.Ts); Commands.info("The job was created successfully!"); } static tsController(name: string, args: TsControllerArgs) { let configNameAt = Commands.nameConfig(name, 'controller'); if (args.cron || args.custom) if (args.controlfields || args.codeid || args.stringid || args.uuid) return Commands.error("Cron or Custom Controllers must not provide the attributes , , or !") let importBase = Commands.importBasePath(configNameAt.path); let typeTemplate = args.cron ? TypeTemplate.tscontroller_cron : args.crud ? TypeTemplate.tscontroller_crud : TypeTemplate.tscontroller_custom; let router = "" if (configNameAt.path) router = `${configNameAt.path}/${configNameAt.table}` else router = configNameAt.table; let templateContent = Commands.template(typeTemplate, [configNameAt.model, TypeTemplate.tscontroller_custom ? configNameAt.table : router, importBase, configNameAt.path ? `${configNameAt.path}/` : "", router]); let pathController = Commands.directory(TypeDir.apicontroller); if (configNameAt.path) pathController = path.join(pathController, configNameAt.path) if (!fs.existsSync(pathController)) fs.mkdirSync(pathController, { recursive: true }); pathController = path.join(pathController, configNameAt.file); if (fs.existsSync(pathController)) return Commands.error("The Controller already exists!"); fs.writeFileSync(pathController, templateContent); Commands.info("The controller was created successfully!"); if (args.crudc) { Commands.tsModel(name, args); } else Commands.createSnippets(TypeSnippets.Ts); } static createTsSnippets() { Commands.createSnippets(TypeSnippets.Ts); Commands.info("The snippets was created successfully!"); } static createSnippets(typeSnippet: TypeSnippets) { let contentSnippet = ''; let pathSnippet = ''; pathSnippet = Commands.directory(TypeDir.vscodedef); if (typeSnippet == TypeSnippets.Ts) { contentSnippet = Commands.template(TypeTemplate.tssnippets_codeid, []) if (!fs.existsSync(pathSnippet)) fs.mkdirSync(pathSnippet) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-codeid.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_http_delete, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-httpdelete.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_http_get, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-httpget.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_http_post, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-httppost.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_http_put, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-httpput.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_stringid, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-stringid.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_uuid, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-uuid.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evt, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_cronmethod, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-cronmethod.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtvoid, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-void.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtwebsocketclientemessage, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-websocketclientemessage.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtwebsocketclienteconnection, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-websocketclienteconnection.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtwebsocketclienteclose, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-websocketclienteclose.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evttokenaccessbeforevalidation, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-tokenaccessbeforevalidation.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evttokenaccessaftervalidation, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-tokenaccessaftervalidation.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmodelbeforeupdate, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-modelbeforeupdate.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmodelbeforesoftdelete, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-modelbeforesoftdelete.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmodelbeforeinsert, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-modelbeforeinsert.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmodelbeforedelete, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-modelbeforedelete.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmodelafterupdate, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-modelafterupdate.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmodelaftersoftdelete, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-modelaftersoftdelete.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmodelafterinsert, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-modelafterinsert.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmodelafterdelete, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-modelafterdelete.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtmappingroutes, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-mappingroutes.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evterrorrouter, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-errorrouter.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evterrorcron, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-errorcron.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtendrouter, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-endrouter.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtendcron, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-endcron.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtcreatecron, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-createcron.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtcreateapiserver, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-createapiserver.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtbeginrouter, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-beginrouter.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtbegincron, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-begincron.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtbeginprocess, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-beginprocess.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evtendprocess, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-endprocess.code-snippets"), contentSnippet); contentSnippet = Commands.template(TypeTemplate.tssnippets_evterrorprocess, []) fs.writeFileSync(path.join(pathSnippet, "ts-snippets-evt-errorprocess.code-snippets"), contentSnippet); } else if (typeSnippet == TypeSnippets.Ng) { contentSnippet = Commands.template(TypeTemplate.ngsnippets_websocket_server, []) if (!fs.existsSync(pathSnippet)) fs.mkdirSync(pathSnippet) fs.writeFileSync(path.join(pathSnippet, "ng-snippets-websocket-server.code-snippets"), contentSnippet); } } static isProjectFlutter(mainDirectory: string = ''): boolean { let pubspecFile = path.join(Commands.directory(TypeDir.ftSource), "pubspec.yaml") if (!fs.existsSync(pubspecFile)) { Commands.error("The selected folder is not a flutter project!") return false; } return true; } static ftCreateComponent(name: string, args: ftComponentArgs) { if (!Commands.isProjectFlutter()) return; let configNameAt = Commands.nameConfig(name); if (Object.keys(args).length == 0) Commands.error("Component type not set!") if (args.stless && args.stfull) Commands.error("Only one component type must be defined!") Commands.info("Creating component..."); let templateWidgetContent = Commands.template( args.sidemenu ? TypeTemplate.ftwidget_main_menu : args.stfull ? TypeTemplate.ftwidget_stfull : TypeTemplate.ftwidget_stless, [configNameAt.model]); let widgetPath = path.join(Commands.directory(TypeDir.ftComponents), `${configNameAt.table}_component.dart`); if (!fs.existsSync(Commands.directory(TypeDir.ftComponents))) fs.mkdirSync(Commands.directory(TypeDir.ftComponents)); if (fs.existsSync(widgetPath)) return Commands.error(`${configNameAt.model} component already exists!`); fs.writeFileSync(widgetPath, templateWidgetContent); Commands.info("The flutter component was created successfully!"); } static ftCreateModel(name: string, args: ftModelArgs) { if (!Commands.isProjectFlutter()) return; let configNameAt = Commands.nameConfig(name); Commands.info("Creating model..."); let modelBasePath = Commands.directory(TypeDir.ftModels); if (configNameAt.path) modelBasePath = path.join(modelBasePath, configNameAt.path) if (!fs.existsSync(modelBasePath)) fs.mkdirSync(modelBasePath, { recursive: true }); let templateModelContent = Commands.template(args.withjsonannotation ? TypeTemplate.ftmodel_with_annotation : TypeTemplate.ftmodel, [configNameAt.model, configNameAt.table]); let modelPath = path.join(modelBasePath, `${configNameAt.table}_model.dart`); if (!fs.existsSync(Commands.directory(TypeDir.ftModels))) fs.mkdirSync(Commands.directory(TypeDir.ftModels)); if (fs.existsSync(modelPath)) return Commands.error(`${configNameAt.model} model already exists!`); fs.writeFileSync(modelPath, templateModelContent); if (args.withjsonannotation) { let templateModelgContent = Commands.template(TypeTemplate.ftmodel_with_annotation_g, [configNameAt.model, configNameAt.table]); let modelgPath = path.join(modelBasePath, `${configNameAt.table}_model.g.dart`); fs.writeFileSync(modelgPath, templateModelgContent); } Commands.info("The flutter model was created successfully!"); } static ftCreateRepository(name: string) { if (!Commands.isProjectFlutter()) return; if (!name) return Commands.error("The name parameter has not been set"); let configNameAt = Commands.nameConfig(name); Commands.info("Creating repository..."); let templateRepositoryContent = Commands.template(TypeTemplate.ftrepository, [configNameAt.model]); let repositoryPath = path.join(Commands.directory(TypeDir.ftModules), configNameAt.path); if (!fs.existsSync(repositoryPath)) fs.mkdirSync(repositoryPath, { recursive: true }); repositoryPath = path.join(repositoryPath, `${configNameAt.table}_repository.dart`); if (fs.existsSync(repositoryPath)) return Commands.error(`${configNameAt.model} repository already exists!`); fs.writeFileSync(repositoryPath, templateRepositoryContent); Commands.info("The flutter repostiory was created successfully!"); } static ftCreatePage(name: string) { if (!Commands.isProjectFlutter()) return; let configNameAt = Commands.nameConfig(name); let entityPath = path.join(Commands.directory(TypeDir.ftModules), configNameAt.table); if (fs.existsSync(entityPath)) return Commands.error(`Entity ${configNameAt.model} already exists!`) fs.mkdirSync(entityPath) let appModuleFile = path.join(Commands.directory(TypeDir.ftApp), "app_module.dart"); let appModuleContent = fs.readFileSync(appModuleFile).toString(); appModuleContent = String(appModuleContent).replace('/*paths*/', `r.module('/${configNameAt.table}', module: ${configNameAt.model}Module());\n /*paths*/`); appModuleContent = String(appModuleContent).replace('/*imports*/', `import 'modules/${configNameAt.table}/${configNameAt.table}_module.dart';\n/*imports*/`); Commands.tamplateToFile(TypeTemplate.ftpage, path.join(Commands.directory(TypeDir.ftModules), configNameAt.table, `${configNameAt.table}_page.dart`), [configNameAt.model, configNameAt.table]); Commands.tamplateToFile(TypeTemplate.ftmodule, path.join(Commands.directory(TypeDir.ftModules), configNameAt.table, `${configNameAt.table}_module.dart`), [configNameAt.model, configNameAt.table]); Commands.tamplateToFile(TypeTemplate.ftstore, path.join(Commands.directory(TypeDir.ftModules), configNameAt.table, `${configNameAt.table}_store.dart`), [configNameAt.model, configNameAt.table]); Commands.tamplateToFile(TypeTemplate.ftrepository, path.join(Commands.directory(TypeDir.ftModules), configNameAt.table, `${configNameAt.table}_repository.dart`), [configNameAt.model, configNameAt.table]); Commands.tamplateToFile(TypeTemplate.ftpstore_g, path.join(Commands.directory(TypeDir.ftModules), configNameAt.table, `${configNameAt.table}_store.g.dart`), [configNameAt.model, configNameAt.table]); fs.writeFileSync(appModuleFile, appModuleContent); Commands.info(`The flutter page ${configNameAt.model} was created successfully!`); } static ftInit(args: ftInitArgs) { if (!Commands.isProjectFlutter()) return; let directoryAt = Commands.directory(TypeDir.ftSource).split('/'); if (Array.isArray(directoryAt) && directoryAt.length == 1) { directoryAt = Commands.directory(TypeDir.ftSource).split('\\'); } let name = directoryAt[directoryAt.length - 1].toLowerCase(); let configNameAt = Commands.nameConfig(name); Commands.info("Updating pubspec.yaml..."); let desc = "Projeto Flutter"; let templatePubspecContent = Commands.template(args.withjsonannotation ? TypeTemplate.ftpubspec_with_annotation : TypeTemplate.ftpubspec, [name, desc]); let pubspecPath = path.join(Commands.directory(TypeDir.ftSource), "pubspec.yaml"); fs.writeFileSync(pubspecPath, templatePubspecContent); Commands.info("Cleaning up lib folder..."); let testPath = path.join(Commands.directory(TypeDir.ftSource), 'test'); if (fs.existsSync(testPath)) fs.rmSync(testPath, { recursive: true }); if (fs.existsSync(Commands.directory(TypeDir.ftLib))) fs.rmSync(Commands.directory(TypeDir.ftLib), { recursive: true }); Commands.info("Creating base directories..."); fs.mkdirSync(Commands.directory(TypeDir.ftLib)); fs.mkdirSync(Commands.directory(TypeDir.ftApp)); fs.mkdirSync(Commands.directory(TypeDir.ftModules)); fs.mkdirSync(Commands.directory(TypeDir.ftShared)); fs.mkdirSync(Commands.directory(TypeDir.ftComponents)); fs.mkdirSync(Commands.directory(TypeDir.ftModels)); Commands.info("Creating project files..."); Commands.tamplateToFile(TypeTemplate.ftmain, path.join(Commands.directory(TypeDir.ftLib), "main.dart"), [name, desc]); Commands.tamplateToFile(TypeTemplate.ftapp_widget, path.join(Commands.directory(TypeDir.ftApp), "app_widget.dart"), [desc]); Commands.tamplateToFile(TypeTemplate.ftapp_module, path.join(Commands.directory(TypeDir.ftApp), "app_module.dart"), []); Commands.tamplateToFile(TypeTemplate.fthttp_overrides_custom, path.join(Commands.directory(TypeDir.ftShared), "http_overrides_custom.dart"), []); Commands.tamplateToFile(TypeTemplate.ftcomponent_exception, path.join(Commands.directory(TypeDir.ftShared), "api_exception.dart"), []); Commands.ftCreatePage("home"); Commands.info("O flutter project init was executed successfully!"); } static async ftCreateProject(name: string, args: ftCreateProjectArgs) { let configNameAt = Commands.nameConfig(name); if (!args || !args.org) return Commands.error("The -org parameter has not been set") args.org = Commands.changeValue(args.org, ' ', '_') Commands.info("Creating flutter project...") await Commands.execCommand(`flutter create ${configNameAt.table} --org ${args.org}`) Commands.info(`Project successfully created! Enter the folder using the command and type the command.`); } static ftHomologateVersion() { Commands.info("Flutter Version 3.19.6") } static async ftBuildRunner() { if (!Commands.isProjectFlutter()) return; Commands.info("Running build runner...") await Commands.execCommand("dart run build_runner build --delete-conflicting-outputs"); Commands.info("The build_runner command was executed successfully!"); } static async pyInit(name: string) { let configNameAt = Commands.nameConfig(name); let startTemplate = Commands.template(TypeTemplate.pystart, []); let installTemplate = Commands.template(TypeTemplate.pyinstall, []); let uninstallTemplate = Commands.template(TypeTemplate.pyuninstall, []); let pathApp = Commands.directory(TypeDir.pySource); pathApp = path.join(pathApp, configNameAt.table); if (!fs.existsSync(pathApp)) fs.mkdirSync(pathApp) let startBat = path.join(pathApp, `start.${process.platform == 'win32' ? "bat" : "sh"}`); let installBat = path.join(pathApp, `install.${process.platform == 'win32' ? "bat" : "sh"}`); let uninstallBat = path.join(pathApp, `uninstall.${process.platform == 'win32' ? "bat" : "sh"}`); let appPy = path.join(pathApp, "app.py"); fs.writeFileSync(startBat, startTemplate); fs.writeFileSync(installBat, installTemplate); fs.writeFileSync(uninstallBat, uninstallTemplate); fs.writeFileSync(appPy, `print("Hello World!")`); await Commands.execCommand(`cd ${configNameAt.table} && python -m venv libs`); Commands.info("The Start script was created successfully!"); } }