@simitgroup/simpleapp-generator 1.6.6-n-alpha → 1.6.6-p-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/ReleaseNote.md +3 -0
  2. package/dist/buildinschemas/customfield.d.ts.map +1 -1
  3. package/dist/buildinschemas/customfield.js +13 -2
  4. package/dist/buildinschemas/customfield.js.map +1 -1
  5. package/dist/framework.d.ts +2 -0
  6. package/dist/framework.d.ts.map +1 -1
  7. package/dist/framework.js +94 -57
  8. package/dist/framework.js.map +1 -1
  9. package/dist/generate.d.ts.map +1 -1
  10. package/dist/generate.js +160 -34
  11. package/dist/generate.js.map +1 -1
  12. package/dist/index.js +30 -12
  13. package/dist/index.js.map +1 -1
  14. package/dist/type.d.ts +5 -0
  15. package/dist/type.d.ts.map +1 -1
  16. package/dist/type.js.map +1 -1
  17. package/package.json +1 -1
  18. package/src/buildinschemas/customfield.ts +14 -3
  19. package/src/framework.ts +309 -251
  20. package/src/generate.ts +592 -434
  21. package/src/index.ts +136 -118
  22. package/src/type.ts +5 -0
  23. package/templates/basic/miniAppJsSdk/resource-bridge.service.ts.eta +117 -0
  24. package/templates/basic/miniAppStreamlitSdk/resource-bridge.service.ts.eta +213 -0
  25. package/templates/basic/nest/apischema.ts.eta +56 -27
  26. package/templates/basic/nest/controller.ts.eta +2 -1
  27. package/templates/basic/nest/type.ts.eta +28 -10
  28. package/templates/basic/nuxt/resource-bridge.service.ts.eta +162 -0
  29. package/templates/miniAppJsSdk/src/index.ts.eta +28 -0
  30. package/templates/miniAppJsSdk/src/services/bridge-resource-accessor.service.ts.eta +70 -0
  31. package/templates/miniAppJsSdk/src/services/bridge.service.ts.eta +91 -0
  32. package/templates/miniAppJsSdk/src/types/service.type.ts.eta +22 -0
  33. package/templates/miniAppStreamlitSdk/simtrain_eco_mini_app_streamlit_sdk/sdk.py.eta +73 -0
  34. package/templates/nest/src/simpleapp/apischemas/customfield.ts.eta +21 -0
  35. package/templates/nest/src/simpleapp/generate/jsonschemas/index.ts.eta +11 -0
  36. package/templates/nest/src/simpleapp/types/customfield.ts.eta +14 -0
  37. package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +2 -3
  38. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +13 -12
  39. package/templates/nuxt/simpleapp/generate/clients/SimpleAppCustomFieldClient.ts.eta +122 -125
  40. package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/common.constant.ts.eta +15 -0
  41. package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/resource.constant.ts.eta +46 -0
  42. package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge-resource-accessor.service.ts.eta +63 -0
  43. package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge.service.ts.eta +110 -0
  44. package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/bridge.type.ts.eta +72 -0
  45. package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/resource-mapper.type.ts.eta +55 -0
  46. package/templates/nuxt/types/others.ts.eta +74 -65
  47. package/templates/nuxt/types/schema.ts.eta +225 -188
  48. package/templates/project/build.sh.eta +9 -0
package/src/generate.ts CHANGED
@@ -1,511 +1,669 @@
1
- import * as constants from './constant'
2
- import {readJsonSchemaBuilder} from './processors/jsonschemabuilder'
3
- import {generateWorkflows} from './processors/bpmnbuilder'
4
- import {allforeignkeys,allfields} from './storage'
5
- import {TypeGenerateDocumentVariable,ChildModels,ModuleObject, SchemaType, SchemaConfig,SchemaPrintFormat } from './type'
6
- import { Logger, ILogObj } from "tslog";
1
+ import * as constants from './constant';
2
+ import { readJsonSchemaBuilder } from './processors/jsonschemabuilder';
3
+ import { generateWorkflows } from './processors/bpmnbuilder';
4
+ import { allforeignkeys, allfields } from './storage';
5
+ import {
6
+ TypeGenerateDocumentVariable,
7
+ ChildModels,
8
+ ModuleObject,
9
+ SchemaType,
10
+ SchemaConfig,
11
+ SchemaPrintFormat
12
+ } from './type';
13
+ import { Logger, ILogObj } from 'tslog';
7
14
 
8
15
  const log: Logger<ILogObj> = new Logger();
9
- const clc = require("cli-color");
16
+ const clc = require('cli-color');
10
17
  const path = require('path');
11
- import {mkdirSync, readdir,readFileSync,writeFileSync,existsSync,copyFileSync, readdirSync} from 'fs'
12
- import _ from 'lodash'
13
- import * as buildinschemas from './buildinschemas'
18
+ import {
19
+ mkdirSync,
20
+ readdir,
21
+ readFileSync,
22
+ writeFileSync,
23
+ existsSync,
24
+ copyFileSync,
25
+ readdirSync
26
+ } from 'fs';
27
+ import _ from 'lodash';
28
+ import * as buildinschemas from './buildinschemas';
14
29
  import { JSONSchema7 } from 'json-schema';
15
- import { generatePrintformat } from './processors/jrxmlbuilder'
30
+ import { generatePrintformat } from './processors/jrxmlbuilder';
31
+
16
32
  const { Eta } = require('eta');
17
- const { capitalizeFirstLetter }= require('./libs');
33
+ const { capitalizeFirstLetter } = require('./libs');
18
34
  // const X_DOCUMENT_TYPE='x-document-type'
19
35
  // const X_DOCUMENT_NAME='x-document-name'
20
36
  // const X_COLLECTION_NAME='x-collection-name'
21
- const X_SIMPLEAPP_CONFIG='x-simpleapp-config'
37
+ const X_SIMPLEAPP_CONFIG = 'x-simpleapp-config';
22
38
  // const extFb = '.xfb.json';
23
39
  // const extHfb = '.xhfb.json';
24
40
  // const extjsonschema = '.jsonschema.json';
25
41
  // const extgroups = '.group.json';
26
42
  let jsonschemas = {};
27
- let configs:any = {}
43
+ let configs: any = {};
28
44
  const docs = [];
29
- let frontendFolder=''
30
- let backendFolder=''
31
- let frontendpagefolder=''
32
- const allroles:any={}
33
- let langdata:any = {}
34
- let allbpmn:any = {}
35
- let activatemodules:ModuleObject[]=[]
36
- let generateTypes:any = {}
37
-
38
-
39
- export const run = async (paraconfigs:any,genFor:string[],callback:Function) => {
40
- configs = paraconfigs
41
- frontendFolder=configs.frontendFolder
42
- backendFolder=configs.backendFolder
43
- const printformats:SchemaPrintFormat[] = []
44
- const groupFolder = configs.groupFolder
45
- const defaultLangFile = configs.defaultLangFile ?? frontendFolder +'/../lang/default.json'
46
- if(genFor.includes('nest')){
47
- generateTypes['nest']=backendFolder
45
+ let frontendFolder = '';
46
+ let backendFolder = '';
47
+ let miniAppSdkFolder = {};
48
+ let frontendpagefolder = '';
49
+ const allroles: any = {};
50
+ let langdata: any = {};
51
+ let allbpmn: any = {};
52
+ let activatemodules: ModuleObject[] = [];
53
+ let generateTypes: any = {};
54
+
55
+ export const run = async (
56
+ paraconfigs: any,
57
+ genFor: string[],
58
+ callback: Function
59
+ ) => {
60
+ configs = paraconfigs;
61
+ frontendFolder = configs.frontendFolder;
62
+ backendFolder = configs.backendFolder;
63
+ miniAppSdkFolder = configs.miniAppSdkFolder;
64
+
65
+ const printformats: SchemaPrintFormat[] = [];
66
+ const groupFolder = configs.groupFolder;
67
+ const defaultLangFile =
68
+ configs.defaultLangFile ?? frontendFolder + '/../lang/default.json';
69
+ if (genFor.includes('nest')) {
70
+ generateTypes['nest'] = backendFolder;
48
71
  }
49
- if(genFor.includes('nuxt')){
50
- generateTypes['nuxt']=frontendFolder
72
+ if (genFor.includes('nuxt')) {
73
+ generateTypes['nuxt'] = frontendFolder;
74
+ }
75
+ if (genFor.includes('miniAppJsSdk')) {
76
+ generateTypes['miniAppJsSdk'] = miniAppSdkFolder['js'];
77
+ }
78
+ if (genFor.includes('miniAppStreamlitSdk')) {
79
+ generateTypes['miniAppStreamlitSdk'] = miniAppSdkFolder['streamlit'];
51
80
  }
52
81
  // console.log("genForgenForgenForgenFor",genFor,generateTypes)
53
- //
54
- frontendpagefolder = `${frontendFolder}/pages/[xorg]`
55
- const buildinschemanames = Object.keys(buildinschemas)
56
- for(let i=0; i<buildinschemanames.length;i++){
57
- const schemaname = buildinschemanames[i]
82
+ //
83
+ frontendpagefolder = `${frontendFolder}/pages/[xorg]`;
84
+ const buildinschemanames = Object.keys(buildinschemas);
85
+ for (let i = 0; i < buildinschemanames.length; i++) {
86
+ const schemaname = buildinschemanames[i];
58
87
  // const filenamearr=schemaname.split('.')
59
88
  // if(_.last(filenamearr)!='json')return
60
- // .forEach(async(schemaname)=>{
61
- const cloneschema:JSONSchema7 = {...buildinschemas[schemaname]}
89
+ // .forEach(async(schemaname)=>{
90
+ const cloneschema: JSONSchema7 = { ...buildinschemas[schemaname] };
62
91
  // console.log("=====>>>>>",schemaname,cloneschema)
63
- await processSchema(schemaname,cloneschema)
92
+ await processSchema(schemaname, cloneschema);
64
93
  }
65
94
 
66
95
  //printformats
67
- const files = readdirSync(configs.jsonschemaFolder)
68
- for(let j = 0; j< files.length;j++){
69
- const file = files[j]
70
- const filenamearr=file.split('.')
71
- if(_.last(filenamearr)!='json')return
96
+ const files = readdirSync(configs.jsonschemaFolder);
97
+ for (let j = 0; j < files.length; j++) {
98
+ const file = files[j];
99
+ const filenamearr = file.split('.');
100
+ if (_.last(filenamearr) != 'json') return;
72
101
  // log.warn(file)
73
- const fullfilename = `${configs.jsonschemaFolder}/${file}`
74
- try{
75
- const jsoncontent = readFileSync(fullfilename, 'utf-8');
102
+ const fullfilename = `${configs.jsonschemaFolder}/${file}`;
103
+ try {
104
+ const jsoncontent = readFileSync(fullfilename, 'utf-8');
76
105
  // log.info("Process ",fullfilename)
77
- const jsonschema = JSON.parse(jsoncontent)
78
- const schemaconfig = jsonschema["x-simpleapp-config"]
79
- if(schemaconfig['printFormats']){
80
- const formats:SchemaPrintFormat[] = schemaconfig['printFormats']
81
- for(let formatno=0;formatno< formats.length; formatno++ ){
106
+ const jsonschema = JSON.parse(jsoncontent);
107
+ const schemaconfig = jsonschema['x-simpleapp-config'];
108
+ if (schemaconfig['printFormats']) {
109
+ const formats: SchemaPrintFormat[] = schemaconfig['printFormats'];
110
+ for (let formatno = 0; formatno < formats.length; formatno++) {
82
111
  // log.warn("Format ",formatno,formats[formatno].formatId)
83
- printformats.push(formats[formatno])
112
+ printformats.push(formats[formatno]);
84
113
  }
85
114
  }
86
- await processSchema(file.replace('.json',''),jsonschema)
87
- }
88
- catch(e:any){
89
- log.error('\nFile : '+fullfilename+'\n');
115
+ await processSchema(file.replace('.json', ''), jsonschema);
116
+ } catch (e: any) {
117
+ log.error('\nFile : ' + fullfilename + '\n');
90
118
  throw e;
91
- }
119
+ }
92
120
  }
93
-
94
121
 
95
122
  //prepare group/roles
96
- const systemgroups = readdirSync(`${groupFolder}`)
97
- for(let g = 0; g< systemgroups.length;g++){
98
-
99
- const groupfile = systemgroups[g]
123
+ const systemgroups = readdirSync(`${groupFolder}`);
124
+ for (let g = 0; g < systemgroups.length; g++) {
125
+ const groupfile = systemgroups[g];
100
126
  // log.info("Process group ",groupfile)
101
- const groupjsonstr = readFileSync(`${groupFolder}/${groupfile}`, 'utf-8');
102
-
127
+ const groupjsonstr = readFileSync(`${groupFolder}/${groupfile}`, 'utf-8');
128
+
103
129
  const groupdata = JSON.parse(groupjsonstr);
104
- const documentname = groupfile.split('.')[0]
105
- const roles = prepareRoles(groupdata)
106
- allroles[documentname]=roles
130
+ const documentname = groupfile.split('.')[0];
131
+ const roles = prepareRoles(groupdata);
132
+ allroles[documentname] = roles;
107
133
  }
108
-
109
- if(existsSync(defaultLangFile)){
134
+
135
+ if (existsSync(defaultLangFile)) {
110
136
  // log.info("Process lang file ",defaultLangFile)
111
- const langjsonstr = readFileSync(defaultLangFile, 'utf-8');
112
-
113
- langdata = JSON.parse(langjsonstr);
114
-
137
+ const langjsonstr = readFileSync(defaultLangFile, 'utf-8');
138
+
139
+ langdata = JSON.parse(langjsonstr);
115
140
  }
116
141
 
117
-
118
- if(configs.bpmnFolder){
142
+ if (configs.bpmnFolder) {
119
143
  // log.info("Process bpmn folder ",configs.bpmnFolder)
120
- allbpmn = await generateWorkflows(configs,genFor)
144
+ allbpmn = await generateWorkflows(configs, genFor);
121
145
  }
122
-
123
- generateSystemFiles(activatemodules,allbpmn)
124
146
 
125
- generatePrintformat(configs,printformats)
147
+ generateSystemFiles(activatemodules, allbpmn);
148
+
149
+ generatePrintformat(configs, printformats);
126
150
 
127
- console.log("Process Complete... Start Run callback");
128
-
129
- callback()
130
- }
151
+ console.log('Process Complete... Start Run callback');
131
152
 
153
+ callback();
154
+ };
132
155
 
133
156
  // const processSchema=async (file:string,defFolder:string)=>{
134
- const processSchema= async (schemaname:string,jsondata:JSONSchema7)=>{
135
-
136
- const config:SchemaConfig = jsondata['x-simpleapp-config']
137
- let doctype = config.documentType
138
- let docname = config.documentName
139
-
140
- const rendertype = 'basic';
141
- jsonschemas[docname] = jsondata;
142
- const copyofjsonschema = {...jsondata}
143
- const allmodels:ChildModels = await readJsonSchemaBuilder(docname, jsondata);
144
- generateSchema(docname, doctype, rendertype, allmodels);
145
- const moduleindex = activatemodules.findIndex(item=>item.doctype == doctype)
146
- if(moduleindex<0){
147
- activatemodules.push({
148
- doctype:doctype,
149
- docname:capitalizeFirstLetter(docname),
150
- pagetype: config.pageType??'',
151
- api:config.additionalApis,
152
- schema : copyofjsonschema
153
- })
154
- }
155
- else{
156
- activatemodules[moduleindex].pagetype = config.pageType??''
157
- activatemodules[moduleindex].api = config.additionalApis
158
- activatemodules[moduleindex].schema = copyofjsonschema
159
- }
160
- // } else {
161
- // log.warn(`Load `+clc.yellow(file) + ` but it is not supported`)
162
- // }
163
- }
164
-
165
-
166
- const isGenerateTest = (data:TypeGenerateDocumentVariable) => data.autocompletecode && data.autocompletename
167
-
157
+ const processSchema = async (schemaname: string, jsondata: JSONSchema7) => {
158
+ const config: SchemaConfig = jsondata['x-simpleapp-config'];
159
+ let doctype = config.documentType;
160
+ let docname = config.documentName;
161
+
162
+ const rendertype = 'basic';
163
+ jsonschemas[docname] = jsondata;
164
+ const copyofjsonschema = { ...jsondata };
165
+ const allmodels: ChildModels = await readJsonSchemaBuilder(docname, jsondata);
166
+ generateSchema(docname, doctype, rendertype, allmodels);
167
+ const moduleindex = activatemodules.findIndex(
168
+ (item) => item.doctype == doctype
169
+ );
170
+ if (moduleindex < 0) {
171
+ activatemodules.push({
172
+ doctype: doctype,
173
+ docname: capitalizeFirstLetter(docname),
174
+ pagetype: config.pageType ?? '',
175
+ api: config.additionalApis,
176
+ schema: copyofjsonschema
177
+ });
178
+ } else {
179
+ activatemodules[moduleindex].pagetype = config.pageType ?? '';
180
+ activatemodules[moduleindex].api = config.additionalApis;
181
+ activatemodules[moduleindex].schema = copyofjsonschema;
182
+ }
183
+ // } else {
184
+ // log.warn(`Load `+clc.yellow(file) + ` but it is not supported`)
185
+ // }
186
+ };
187
+
188
+ const isGenerateTest = (data: TypeGenerateDocumentVariable) =>
189
+ data.autocompletecode && data.autocompletename;
190
+
168
191
  /**
169
192
  * generate frontend nuxt and backend nest codes.
170
- *
171
- */
172
- const generateSchema = ( docname: string,
193
+ *
194
+ */
195
+ const generateSchema = (
196
+ docname: string,
173
197
  doctype: string,
174
198
  rendertype: string,
175
- allmodels: ChildModels)=>{
199
+ allmodels: ChildModels
200
+ ) => {
201
+ const simpleapptemplates = `${constants.templatedir}/basic`;
202
+ const finalizefolder = `${constants.templatedir}/nest`;
203
+ const modelname = _.upperFirst(docname);
204
+ const currentmodel = allmodels[modelname];
176
205
 
177
-
178
- const simpleapptemplates = `${constants.templatedir}/basic`
179
- const finalizefolder = `${constants.templatedir}/nest`
180
- const modelname = _.upperFirst(docname)
181
- const currentmodel = allmodels[modelname]
206
+ const resourceName =
207
+ jsonschemas[docname]?.['x-simpleapp-config']?.resourceName ?? docname;
182
208
 
183
- //console.log("---^^^^^------",modelname,docname, doctype, rendertype,currentmodel,allmodels)
184
- const variables:TypeGenerateDocumentVariable = {
185
- name: docname,
186
- doctype: doctype,
187
- models: allmodels,
188
- autocompletecode:currentmodel.codeField??'',
189
- autocompletename:currentmodel.nameField??'',
190
- moreAutoComplete:currentmodel.moreAutoComplete ??[],
191
- schema: currentmodel.model,
192
- apiSchemaName: capitalizeFirstLetter(docname), //capitalizeFirstLetter(doctype) + 'ApiSchema',
193
- typename: capitalizeFirstLetter(docname),
194
- fullApiSchemaName:
195
- doctype + 'apischema.' + capitalizeFirstLetter(docname),
196
- fullTypeName: doctype + 'type.' + capitalizeFirstLetter(docname),
197
- jsonschema: jsonschemas[docname],
198
- bothEndCode: '',
199
- frontEndCode: '',
200
- backEndCode: '',
201
- controllerCode:'',
202
- apiSchemaCode:'',
203
- docStatusSettings: currentmodel.docStatusSettings??[],
204
- apiSettings: currentmodel.apiSettings??[],
205
- isolationtype: currentmodel.isolationtype,
206
- hasdocformat: currentmodel.hasdocformat,
207
- foreignkeys: currentmodel.foreignkeys ?? {}
208
- };
209
-
210
- const templatefolder = `${constants.templatedir}/${rendertype}`
211
- // log.info(`- Generate ${docname}, ${doctype}, ${templatefolder}`)
212
- const eta = new Eta({
213
- views: '/',
214
- functionHeader: getCodeGenHelper()
215
-
216
- // 'const capitalizeFirstLetter = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);' +
217
- // 'const initType=(str)=>{return ["string","number","boolean","array","object"].includes(str) ? capitalizeFirstLetter(str) : str;}'+
218
- // 'const camelCaseToWords = (s: string) =>{const result = s.replace(/([A-Z])/g, \' $1\');return result.charAt(0).toUpperCase() + result.slice(1);}',
219
-
220
- });
221
-
222
- const backendTargetFolder = `${backendFolder}/src/simpleapp/generate`
223
- const simpleappTargetFolder = `${backendFolder}/src/simpleapp`
224
- const backendServiceFolder = `${backendFolder}/src/simpleapp/services`
225
-
226
-
227
- Object.keys(generateTypes).forEach((foldertype)=>{
228
-
229
-
230
- //generate code for every schema
231
- const generateTemplatefolder = `${constants.templatedir}/basic/${foldertype}`
232
- const allfiles = readdirSync(generateTemplatefolder,{recursive:true})
233
- for(let j=0; j<allfiles.length;j++){
234
-
235
- const filename:string = String(allfiles[j])
236
- const templatepath = `${generateTemplatefolder}/${filename}`
237
-
238
- if(_.last(filename.split('.'))!='eta'){
239
- // log.warn("skip file: ",filename)
240
- continue;
209
+ //console.log("---^^^^^------",modelname,docname, doctype, rendertype,currentmodel,allmodels)
210
+ const variables: TypeGenerateDocumentVariable = {
211
+ resourceName: resourceName,
212
+ name: docname,
213
+ doctype: doctype,
214
+ models: allmodels,
215
+ autocompletecode: currentmodel.codeField ?? '',
216
+ autocompletename: currentmodel.nameField ?? '',
217
+ moreAutoComplete: currentmodel.moreAutoComplete ?? [],
218
+ schema: currentmodel.model,
219
+ apiSchemaName: capitalizeFirstLetter(docname), //capitalizeFirstLetter(doctype) + 'ApiSchema',
220
+ typename: capitalizeFirstLetter(docname),
221
+ fullApiSchemaName: doctype + 'apischema.' + capitalizeFirstLetter(docname),
222
+ fullTypeName: doctype + 'type.' + capitalizeFirstLetter(docname),
223
+ jsonschema: jsonschemas[docname],
224
+ bothEndCode: '',
225
+ frontEndCode: '',
226
+ backEndCode: '',
227
+ controllerCode: '',
228
+ apiSchemaCode: '',
229
+ docStatusSettings: currentmodel.docStatusSettings ?? [],
230
+ apiSettings: currentmodel.apiSettings ?? [],
231
+ isolationtype: currentmodel.isolationtype,
232
+ hasdocformat: currentmodel.hasdocformat,
233
+ foreignkeys: currentmodel.foreignkeys ?? {}
234
+ };
235
+
236
+ const templatefolder = `${constants.templatedir}/${rendertype}`;
237
+ // log.info(`- Generate ${docname}, ${doctype}, ${templatefolder}`)
238
+ const eta = new Eta({
239
+ views: '/',
240
+ functionHeader: getCodeGenHelper()
241
+
242
+ // 'const capitalizeFirstLetter = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);' +
243
+ // 'const initType=(str)=>{return ["string","number","boolean","array","object"].includes(str) ? capitalizeFirstLetter(str) : str;}'+
244
+ // 'const camelCaseToWords = (s: string) =>{const result = s.replace(/([A-Z])/g, \' $1\');return result.charAt(0).toUpperCase() + result.slice(1);}',
245
+ });
246
+
247
+ const backendTargetFolder = `${backendFolder}/src/simpleapp/generate`;
248
+ const simpleappTargetFolder = `${backendFolder}/src/simpleapp`;
249
+ const backendServiceFolder = `${backendFolder}/src/simpleapp/services`;
250
+
251
+ Object.keys(generateTypes).forEach((foldertype) => {
252
+ //generate code for every schema
253
+ const generateTemplatefolder = `${constants.templatedir}/basic/${foldertype}`;
254
+ const allfiles = readdirSync(generateTemplatefolder, { recursive: true });
255
+ for (let j = 0; j < allfiles.length; j++) {
256
+ const filename: string = String(allfiles[j]);
257
+ const templatepath = `${generateTemplatefolder}/${filename}`;
258
+
259
+ if (_.last(filename.split('.')) != 'eta') {
260
+ // log.warn("skip file: ",filename)
261
+ continue;
262
+ }
263
+
264
+ // no turn on split mobile url, skip create mobile page
265
+ if (!configs?.splitMobilePage && filename.includes('mobile.')) continue;
266
+ if (foldertype == 'nest') {
267
+ const arrfilename: string[] = filename.split('.');
268
+ const filecategory = arrfilename[0];
269
+ const filetype = arrfilename[1];
270
+ const autogeneratetypes = [
271
+ 'apischema',
272
+ 'controller',
273
+ 'jsonschema',
274
+ 'model',
275
+ 'resolver',
276
+ 'processor',
277
+ 'type',
278
+ 'default'
279
+ ];
280
+ // log.info("process nest: ",doctype," :",filename)
281
+ if (autogeneratetypes.includes(filecategory)) {
282
+ //multiple files in folder, append s at folder name
283
+ const storein = `${backendTargetFolder}/${filecategory}s`;
284
+ const targetfile = `${storein}/${doctype}.${filecategory}.${filetype}`;
285
+ if (!existsSync(storein)) {
286
+ mkdirSync(storein, { recursive: true });
287
+ }
288
+
289
+ const filecontent = eta.render(templatepath, variables);
290
+ writeFileSync(targetfile, filecontent);
291
+ // console.log("Write complete")
292
+ } else if (filecategory == 'service') {
293
+ //service file won't override if exists
294
+ const targetfolder = `${simpleappTargetFolder}/${filecategory}s`;
295
+ const targetfile = `${targetfolder}/${doctype}.${filecategory}.${filetype}`;
296
+ if (!existsSync(targetfolder)) {
297
+ mkdirSync(targetfolder, { recursive: true });
298
+ }
299
+
300
+ if (
301
+ !existsSync(targetfile) ||
302
+ readFileSync(targetfile, 'utf-8').includes(
303
+ '--remove-this-line-to-prevent-override--'
304
+ )
305
+ ) {
306
+ // log.info("Write ",targetfile)
307
+ const filecontent = eta.render(templatepath, variables);
308
+ writeFileSync(targetfile, filecontent);
309
+ } else {
310
+ // log.info("skip ",targetfile)
311
+ }
312
+ } else if (filecategory == 'test' && isGenerateTest(variables)) {
313
+ const targetfolder = `${backendFolder}/test/documents/${docname}`;
314
+ const targetfile = `${targetfolder}/${docname}.e2e-spec.ts`;
315
+ // log.warn("test file: ",targetfile)
316
+ // `${backendServiceFolder}/${doctype}.${filecategory}.${filetype}`
317
+ if (!existsSync(targetfolder)) {
318
+ mkdirSync(targetfolder, { recursive: true });
319
+ }
320
+ if (!existsSync(targetfile)) {
321
+ log.info('process: ', targetfile);
322
+ const filecontent = eta.render(templatepath, variables);
323
+ writeFileSync(targetfile, filecontent);
324
+ //create stub files
325
+ mkdirSync(`${targetfolder}/stub`, { recursive: true });
326
+ writeFileSync(
327
+ `${targetfolder}/stub/id1.create.ts`,
328
+ 'export default () => ({_id:"00000000-0000-0000-0000-000000000001",})'
329
+ );
330
+ writeFileSync(
331
+ `${targetfolder}/stub/id1.update.ts`,
332
+ 'export default () => ({_id:"00000000-0000-0000-0000-000000000001",})'
333
+ );
334
+ writeFileSync(
335
+ `${targetfolder}/stub/id2.create.ts`,
336
+ 'export default () => ({_id:"00000000-0000-0000-0000-000000000002",})'
337
+ );
338
+ }
241
339
  }
242
-
243
- // no turn on split mobile url, skip create mobile page
244
- if(!configs?.splitMobilePage && filename.includes('mobile.')) continue
245
- if(foldertype=='nest'){
246
- const arrfilename:string[] = filename.split('.')
247
- const filecategory = arrfilename[0]
248
- const filetype = arrfilename[1]
249
- const autogeneratetypes = ['apischema','controller','jsonschema','model','resolver','processor','type','default']
250
- // log.info("process nest: ",doctype," :",filename)
251
- if(autogeneratetypes.includes(filecategory)){
252
- //multiple files in folder, append s at folder name
253
- const storein = `${backendTargetFolder}/${filecategory}s`
254
- const targetfile = `${storein}/${doctype}.${filecategory}.${filetype}`
255
- if(!existsSync(storein)){
256
- mkdirSync(storein,{recursive:true})
257
- }
258
-
259
- const filecontent = eta.render(templatepath, variables)
260
- writeFileSync(targetfile,filecontent);
261
- // console.log("Write complete")
262
- }else if(filecategory=='service' ){ //service file won't override if exists
263
- const targetfolder = `${simpleappTargetFolder}/${filecategory}s`
264
- const targetfile = `${targetfolder}/${doctype}.${filecategory}.${filetype}`
265
- if(!existsSync(targetfolder)){
266
- mkdirSync(targetfolder,{recursive:true})
267
- }
268
-
269
- if(!existsSync(targetfile) || readFileSync(targetfile, 'utf-8').includes('--remove-this-line-to-prevent-override--')){
270
- // log.info("Write ",targetfile)
271
- const filecontent = eta.render(templatepath, variables)
272
- writeFileSync(targetfile,filecontent);
340
+ } else if (foldertype == 'nuxt') {
341
+ // console.log("Process nuxt: ",docname)
342
+ const capname = capitalizeFirstLetter(docname);
343
+ // const resourceName =
344
+
345
+ const validateWritePage = (targetfile: string, isexists: boolean) => {
346
+ if (
347
+ !jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
348
+ !targetfile.includes('Viewer') &&
349
+ !targetfile.includes('Form')
350
+ ) {
351
+ return false;
352
+ } else if (!isexists) {
353
+ return true;
354
+ } else if (
355
+ !existsSync(targetfile) ||
356
+ readFileSync(targetfile, 'utf-8').includes(
357
+ '--remove-this-line-to-prevent-override--'
358
+ ) ||
359
+ readFileSync(targetfile, 'utf-8').includes('delete-me')
360
+ ) {
361
+ return true;
362
+ } else {
363
+ return false;
364
+ }
365
+ };
366
+ const mapfiles = {
367
+ 'pages.form.vue.eta': {
368
+ to: 'components/form',
369
+ as: `Form${_.upperFirst(docname)}.vue`,
370
+ validate: validateWritePage
371
+ },
372
+ 'pages.mobile.[id].vue.eta': {
373
+ to: `pages/[xorg]/mobile/${docname}`,
374
+ as: '[id].vue',
375
+ validate: validateWritePage
376
+ },
377
+ 'pages.mobile.landing.vue.eta': {
378
+ to: `pages/[xorg]/mobile/${docname}`,
379
+ as: `index.vue`,
380
+ validate: validateWritePage
381
+ },
382
+ 'component.select.vue.eta': {
383
+ to: 'components/select',
384
+ as: `Select${_.upperFirst(docname)}.vue`,
385
+ validate: validateWritePage
386
+ },
387
+ 'pages.viewer.vue.eta': {
388
+ to: `components/viewer`,
389
+ as: `Viewer${_.upperFirst(docname)}.vue`,
390
+ validate: validateWritePage
391
+ },
392
+ 'pages.[id].vue.eta': {
393
+ to: `pages/[xorg]/${docname}`,
394
+ as: '[id].vue',
395
+ validate: validateWritePage
396
+ },
397
+ 'pages.landing.vue.eta': {
398
+ to: `pages/[xorg]/${docname}`,
399
+ as: `../${docname}.vue`,
400
+ validate: validateWritePage
401
+ },
402
+
403
+ 'simpleapp.doc.ts.eta': {
404
+ to: `simpleapp/docs`,
405
+ as: `${capname}Doc.ts`,
406
+ validate: (targetfile: string, isexists: boolean) => !isexists
407
+ },
408
+ 'default.ts.eta': {
409
+ to: `simpleapp/generate/defaults`,
410
+ as: `${capname}.default.ts`,
411
+ validate: (targetfile: string, isexists: boolean) => {
412
+ return true;
273
413
  }
274
- else{
275
- // log.info("skip ",targetfile)
414
+ },
415
+
416
+ 'simpleapp.generate.client.ts.eta': {
417
+ to: `simpleapp/generate/clients`,
418
+ as: `${capname}Client.ts`,
419
+ validate: (targetfile: string, isexists: boolean) => {
420
+ return true;
276
421
  }
277
-
278
- }else if(filecategory=='test' && isGenerateTest(variables)){
279
-
280
- const targetfolder = `${backendFolder}/test/documents/${docname}`
281
- const targetfile = `${targetfolder}/${docname}.e2e-spec.ts`
282
- // log.warn("test file: ",targetfile)
283
- // `${backendServiceFolder}/${doctype}.${filecategory}.${filetype}`
284
- if(!existsSync(targetfolder)){
285
- mkdirSync(targetfolder,{recursive:true})
286
- }
287
- if(!existsSync(targetfile)){
288
- log.info("process: ",targetfile)
289
- const filecontent = eta.render(templatepath, variables)
290
- writeFileSync(targetfile,filecontent);
291
- //create stub files
292
- mkdirSync(`${targetfolder}/stub`,{recursive:true})
293
- writeFileSync(`${targetfolder}/stub/id1.create.ts`,'export default () => ({_id:"00000000-0000-0000-0000-000000000001",})');
294
- writeFileSync(`${targetfolder}/stub/id1.update.ts`,'export default () => ({_id:"00000000-0000-0000-0000-000000000001",})');
295
- writeFileSync(`${targetfolder}/stub/id2.create.ts`,'export default () => ({_id:"00000000-0000-0000-0000-000000000002",})');
296
-
422
+ },
423
+
424
+ 'resource-bridge.service.ts.eta': {
425
+ to: 'simpleapp/generate/miniApp/bridge/services/resources',
426
+ as: `${_.kebabCase(resourceName)}-bridge.service.ts`,
427
+ validate: (targetfile: string, isexists: boolean) => {
428
+ return true;
297
429
  }
298
430
  }
299
-
300
- }else if(foldertype=='nuxt'){
301
- // console.log("Process nuxt: ",docname)
302
- const capname = capitalizeFirstLetter(docname)
303
-
304
- const validateWritePage = (targetfile:string,isexists:boolean)=>{
305
- if(!jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] && !targetfile.includes('Viewer') && !targetfile.includes('Form')){
306
- return false
307
- }
308
- else if(!isexists){
309
- return true
310
- }else if(!existsSync(targetfile) || readFileSync(targetfile, 'utf-8').includes('--remove-this-line-to-prevent-override--')
311
- || readFileSync(targetfile, 'utf-8').includes('delete-me')){
312
- return true
313
- }else{
314
- return false
315
- }
431
+ };
432
+
433
+ // if(configs?.splitMobilePage){
434
+ // mapfiles['pages.mobile.[id].vue.eta'] = {
435
+ // to:`pages/[xorg]/mobile/${docname}`,
436
+ // as:'[id].vue',
437
+ // validate: validateWritePage
438
+ // }
439
+ // mapfiles['pages.mobile.landing.vue.eta'] = {
440
+ // to:`pages/[xorg]/mobile/${docname}`,
441
+ // as:`index.vue`,
442
+ // validate: validateWritePage
443
+ // }
444
+ // }
445
+
446
+ const target = mapfiles[filename];
447
+ // console.log(target);
448
+ const targetfolder = `${generateTypes[foldertype]}/${target.to}`;
449
+ const targetfile = `${targetfolder}/${target.as}`;
450
+
451
+ // console.log("targetfile",targetfile);
452
+ if (
453
+ jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
454
+ !existsSync(targetfolder)
455
+ ) {
456
+ console.log('Mkdir', targetfolder);
457
+ mkdirSync(targetfolder, { recursive: true });
458
+ }
459
+
460
+ const isexists = existsSync(targetfile);
461
+ const iswrite: boolean = target.validate(targetfile, isexists);
462
+ // log.info("iswrite: ",iswrite)
463
+
464
+ if (iswrite) {
465
+ const filecontent = eta.render(templatepath, variables);
466
+ writeFileSync(targetfile, filecontent);
467
+ }
468
+ // console.log("complete, go to next file")
469
+ } else if (foldertype === 'miniAppJsSdk') {
470
+ const validateWritePage = (targetfile: string, isexists: boolean) => {
471
+ if (
472
+ !jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
473
+ !targetfile.includes('Viewer') &&
474
+ !targetfile.includes('Form')
475
+ ) {
476
+ return false;
477
+ } else if (!isexists) {
478
+ return true;
479
+ } else if (
480
+ !existsSync(targetfile) ||
481
+ readFileSync(targetfile, 'utf-8').includes(
482
+ '--remove-this-line-to-prevent-override--'
483
+ ) ||
484
+ readFileSync(targetfile, 'utf-8').includes('delete-me')
485
+ ) {
486
+ return true;
487
+ } else {
488
+ return false;
316
489
  }
317
- const mapfiles = {
318
- 'pages.form.vue.eta': {
319
- to:'components/form',
320
- as: `Form${_.upperFirst(docname)}.vue`,
321
- validate: validateWritePage
322
- },
323
- 'pages.mobile.[id].vue.eta': {
324
- to:`pages/[xorg]/mobile/${docname}`,
325
- as:'[id].vue',
326
- validate: validateWritePage
327
- },
328
- 'pages.mobile.landing.vue.eta':{
329
- to:`pages/[xorg]/mobile/${docname}`,
330
- as:`index.vue`,
331
- validate: validateWritePage
332
- },
333
- 'component.select.vue.eta': {
334
- to:'components/select',
335
- as: `Select${_.upperFirst(docname)}.vue`,
336
- validate: validateWritePage
337
- },
338
- 'pages.viewer.vue.eta': {
339
- to:`components/viewer`,
340
- as: `Viewer${_.upperFirst(docname)}.vue`,
341
- validate: validateWritePage
342
- },
343
- 'pages.[id].vue.eta': {
344
- to:`pages/[xorg]/${docname}`,
345
- as:'[id].vue',
346
- validate: validateWritePage
347
- },
348
- 'pages.landing.vue.eta': {
349
- to:`pages/[xorg]/${docname}`,
350
- as:`../${docname}.vue`,
351
- validate: validateWritePage
352
- },
353
-
354
- 'simpleapp.doc.ts.eta': {
355
- to:`simpleapp/docs`,
356
- as:`${capname}Doc.ts`,
357
- validate: (targetfile:string,isexists:boolean)=>!isexists
358
- },
359
- 'default.ts.eta': {
360
- to:`simpleapp/generate/defaults`,
361
- as:`${capname}.default.ts`,
362
- validate: (targetfile:string,isexists:boolean)=>{
363
- return true
364
- }
365
- },
366
-
367
- 'simpleapp.generate.client.ts.eta': {
368
- to:`simpleapp/generate/clients`,
369
- as:`${capname}Client.ts`,
370
- validate: (targetfile:string,isexists:boolean)=>{
371
- return true
372
- }
373
- },
490
+ };
491
+
492
+ const mapfiles = {
493
+ 'resource-bridge.service.ts.eta': {
494
+ to: 'src/services/resources',
495
+ as: `${_.kebabCase(resourceName)}-bridge.service.ts`,
496
+ validate: (targetfile: string, isexists: boolean) => {
497
+ return true;
498
+ }
374
499
  }
500
+ };
375
501
 
502
+ const target = mapfiles[filename];
503
+ const targetfolder = `${generateTypes[foldertype]}/${target.to}`;
504
+ const targetfile = `${targetfolder}/${target.as}`;
376
505
 
377
- // if(configs?.splitMobilePage){
378
- // mapfiles['pages.mobile.[id].vue.eta'] = {
379
- // to:`pages/[xorg]/mobile/${docname}`,
380
- // as:'[id].vue',
381
- // validate: validateWritePage
382
- // }
383
- // mapfiles['pages.mobile.landing.vue.eta'] = {
384
- // to:`pages/[xorg]/mobile/${docname}`,
385
- // as:`index.vue`,
386
- // validate: validateWritePage
387
- // }
388
- // }
389
-
390
- const target = mapfiles[filename]
391
- // console.log(target);
392
- const targetfolder = `${generateTypes[foldertype]}/${target.to}`
393
- const targetfile = `${targetfolder}/${target.as}`
394
-
395
- // console.log("targetfile",targetfile);
396
- if(jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] && !existsSync(targetfolder)){
397
- console.log("Mkdir",targetfolder)
398
- mkdirSync(targetfolder,{recursive:true})
399
- }
506
+ if (
507
+ jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
508
+ !existsSync(targetfolder)
509
+ ) {
510
+ console.log('Mkdir', targetfolder);
511
+ mkdirSync(targetfolder, { recursive: true });
512
+ }
400
513
 
514
+ const isexists = existsSync(targetfile);
515
+ const iswrite: boolean = target.validate(targetfile, isexists);
516
+ // log.info("iswrite: ",iswrite)
401
517
 
402
- const isexists = existsSync(targetfile)
403
- const iswrite:boolean = target.validate(targetfile,isexists)
404
- // log.info("iswrite: ",iswrite)
405
-
406
- if(iswrite){
407
- const filecontent = eta.render(templatepath, variables)
408
- writeFileSync(targetfile,filecontent);
518
+ if (iswrite) {
519
+ const filecontent = eta.render(templatepath, variables);
520
+ writeFileSync(targetfile, filecontent);
521
+ }
522
+ } else if (foldertype === 'miniAppStreamlitSdk') {
523
+ const validateWritePage = (targetfile: string, isexists: boolean) => {
524
+ if (
525
+ !jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
526
+ !targetfile.includes('Viewer') &&
527
+ !targetfile.includes('Form')
528
+ ) {
529
+ return false;
530
+ } else if (!isexists) {
531
+ return true;
532
+ } else if (
533
+ !existsSync(targetfile) ||
534
+ readFileSync(targetfile, 'utf-8').includes(
535
+ '--remove-this-line-to-prevent-override--'
536
+ ) ||
537
+ readFileSync(targetfile, 'utf-8').includes('delete-me')
538
+ ) {
539
+ return true;
540
+ } else {
541
+ return false;
542
+ }
543
+ };
544
+
545
+ const mapfiles = {
546
+ 'resource-bridge.service.ts.eta': {
547
+ to: 'simtrain_eco_mini_app_streamlit_sdk/services/resources',
548
+ as: `${_.snakeCase(resourceName)}.py`,
549
+ validate: (targetfile: string, isexists: boolean) => {
550
+ return true;
409
551
  }
410
- // console.log("complete, go to next file")
411
-
412
-
552
+ }
553
+ };
413
554
 
414
- }
415
- }
416
-
555
+ const target = mapfiles[filename];
556
+ const targetfolder = `${generateTypes[foldertype]}/${target.to}`;
557
+ const targetfile = `${targetfolder}/${target.as}`;
417
558
 
418
- })
419
- // console.log("Complete generate schema")
420
-
559
+ if (
560
+ jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
561
+ !existsSync(targetfolder)
562
+ ) {
563
+ console.log('Mkdir', targetfolder);
564
+ mkdirSync(targetfolder, { recursive: true });
565
+ }
421
566
 
422
- }
567
+ const isexists = existsSync(targetfile);
568
+ const iswrite: boolean = target.validate(targetfile, isexists);
569
+ // log.info("iswrite: ",iswrite)
423
570
 
571
+ if (iswrite) {
572
+ const filecontent = eta.render(templatepath, variables);
573
+ if (!existsSync(path.dirname(targetfile)))
574
+ mkdirSync(path.dirname(targetfile), { recursive: true });
575
+ writeFileSync(targetfile, filecontent);
576
+ }
577
+ }
578
+ }
579
+ });
580
+ };
424
581
 
425
- const generateSystemFiles=(modules:ModuleObject[],allbpmn)=>{
582
+ const generateSystemFiles = (modules: ModuleObject[], allbpmn) => {
426
583
  const renderProperties = {
427
- configs:configs,
428
- modules:modules,
429
- allroles:allroles,
430
- foreignkeys:allforeignkeys,
431
- allfields:allfields,
584
+ configs: configs,
585
+ modules: modules,
586
+ allroles: allroles,
587
+ foreignkeys: allforeignkeys,
588
+ allfields: allfields,
432
589
  allbpmn: allbpmn,
433
- lang:langdata
434
- }
435
-
436
-
437
- Object.getOwnPropertyNames(generateTypes).forEach((foldertype)=>{
438
- const frameworkpath = generateTypes[foldertype]
439
- // log.info("Generate ",foldertype)
440
- const frameworkfolder = `${constants.templatedir}/${foldertype}`
441
- const frameworkfiles = readdirSync(frameworkfolder,{recursive:true})
442
- const eta = new Eta({views:frameworkfolder,
443
- functionHeader: getCodeGenHelper()});
444
-
445
- //generate code for framework
446
- for(let index=0; index<frameworkfiles.length; index++){
447
- // log.info("Process systemfiles ",frameworkfiles[index])
448
- const longfilename:string = String(frameworkfiles[index])
449
- const patharr = longfilename.split('/')
450
- const filename = _.last(patharr)
451
- const arrfilename:string[] = filename.split('.')
452
- // log.info("check longfilename:::",longfilename,"become====",arrfilename)
453
- //only process .eta
454
- if(['eta','_eta'].includes(_.last(arrfilename))){
455
- const relativepath = longfilename.includes('/') ? longfilename.replace(`/${filename}`,'') : ''
456
- const foldername = `${frameworkpath}/${relativepath}`
457
- const shortfilename = filename.replace('.eta','').replace('._eta','')
458
- const targetfilename = `${foldername}/${shortfilename}`
459
- let forceoverride=true
460
- if(filename.includes('._eta') && existsSync(targetfilename)){
461
- const filecontent = readFileSync(targetfilename, 'utf-8')
462
-
463
- if(filecontent.includes('--remove-this-line-to-prevent-override--')){
464
- forceoverride=true
465
- }else{
466
- forceoverride=false
467
- }
468
- }
469
- // log.warn("Process=== ",targetfilename)
470
- if(existsSync(targetfilename) && forceoverride == false){
471
- // log.info("file exists, skip: ",targetfilename)
472
- continue;
473
- }
590
+ lang: langdata
591
+ };
592
+
593
+ Object.getOwnPropertyNames(generateTypes).forEach((foldertype) => {
594
+ const frameworkpath = generateTypes[foldertype];
595
+ // log.info("Generate ",foldertype)
596
+ const frameworkfolder = `${constants.templatedir}/${foldertype}`;
597
+ const frameworkfiles = readdirSync(frameworkfolder, { recursive: true });
598
+ const eta = new Eta({
599
+ views: frameworkfolder,
600
+ functionHeader: getCodeGenHelper()
601
+ });
602
+
603
+ //generate code for framework
604
+ for (let index = 0; index < frameworkfiles.length; index++) {
605
+ // log.info("Process systemfiles ",frameworkfiles[index])
606
+ const longfilename: string = String(frameworkfiles[index]);
607
+ const patharr = longfilename.split('/');
608
+ const filename = _.last(patharr);
609
+ const arrfilename: string[] = filename.split('.');
610
+ // log.info("check longfilename:::",longfilename,"become====",arrfilename)
611
+ //only process .eta
612
+ if (['eta', '_eta'].includes(_.last(arrfilename))) {
613
+ const relativepath = longfilename.includes('/')
614
+ ? longfilename.replace(`/${filename}`, '')
615
+ : '';
616
+ const foldername = `${frameworkpath}/${relativepath}`;
617
+ const shortfilename = filename.replace('.eta', '').replace('._eta', '');
618
+ const targetfilename = `${foldername}/${shortfilename}`;
619
+ let forceoverride = true;
620
+ if (filename.includes('._eta') && existsSync(targetfilename)) {
621
+ const filecontent = readFileSync(targetfilename, 'utf-8');
474
622
 
475
-
476
- if(!existsSync(foldername)){
477
- mkdirSync(foldername,{recursive:true})
623
+ if (
624
+ filecontent.includes('--remove-this-line-to-prevent-override--')
625
+ ) {
626
+ forceoverride = true;
627
+ } else {
628
+ forceoverride = false;
478
629
  }
479
- // const templatename = `${frameworkfolder}/${longfilename}`.replace(".eta","").replace('._eta','')
480
- // log.info("Write template:",targetfilename)
481
- const txt = eta.render(longfilename, renderProperties)
482
- writeFileSync(targetfilename,txt)
483
-
484
- }else{
485
- // log.warn("skip: ",longfilename)
486
630
  }
487
-
631
+ // log.warn("Process=== ",targetfilename)
632
+ if (existsSync(targetfilename) && forceoverride == false) {
633
+ // log.info("file exists, skip: ",targetfilename)
634
+ continue;
635
+ }
636
+
637
+ if (!existsSync(foldername)) {
638
+ mkdirSync(foldername, { recursive: true });
488
639
  }
489
- })
490
-
491
- }
492
-
493
- const prepareRoles =(groupsettings) => {
494
- let roles = []
495
- const docnames = Object.getOwnPropertyNames(groupsettings)
496
- for(let i = 0; i< docnames.length; i++){
497
- let docname = docnames[i]
498
- let docpermissions:string[] = groupsettings[docname]
499
- for(let j=0;j<docpermissions.length;j++){
500
- const perm = docpermissions[j]
501
- const typename = _.upperFirst(docname)
502
- roles.push(`${typename}_${perm}`)
640
+ // const templatename = `${frameworkfolder}/${longfilename}`.replace(".eta","").replace('._eta','')
641
+ // log.info("Write template:",targetfilename)
642
+ const txt = eta.render(longfilename, renderProperties);
643
+ writeFileSync(targetfilename, txt);
644
+ } else {
645
+ // log.warn("skip: ",longfilename)
646
+ }
503
647
  }
504
- }
505
- return roles
506
- }
648
+ });
649
+ };
507
650
 
651
+ const prepareRoles = (groupsettings) => {
652
+ let roles = [];
653
+ const docnames = Object.getOwnPropertyNames(groupsettings);
654
+ for (let i = 0; i < docnames.length; i++) {
655
+ let docname = docnames[i];
656
+ let docpermissions: string[] = groupsettings[docname];
657
+ for (let j = 0; j < docpermissions.length; j++) {
658
+ const perm = docpermissions[j];
659
+ const typename = _.upperFirst(docname);
660
+ roles.push(`${typename}_${perm}`);
661
+ }
662
+ }
663
+ return roles;
664
+ };
508
665
 
509
- const getCodeGenHelper = () => 'const capitalizeFirstLetter = (str) => !str ? `Object` : str.slice(0, 1).toUpperCase() + str.slice(1);' +
510
- 'const initType=(str)=>{return ["string","number","boolean","array","object"].includes(str) ? capitalizeFirstLetter(str) : str;};' +
511
- 'const camelCaseToWords = (s) => {const result = s.replace(/([A-Z])/g, \' $1\');return result.charAt(0).toUpperCase() + result.slice(1);}'
666
+ const getCodeGenHelper = () =>
667
+ 'const capitalizeFirstLetter = (str) => !str ? `Object` : str.slice(0, 1).toUpperCase() + str.slice(1);' +
668
+ 'const initType=(str)=>{return ["string","number","boolean","array","object"].includes(str) ? capitalizeFirstLetter(str) : str;};' +
669
+ "const camelCaseToWords = (s) => {const result = s.replace(/([A-Z])/g, ' $1');return result.charAt(0).toUpperCase() + result.slice(1);}";