@simitgroup/simpleapp-generator 1.6.6-o-alpha → 1.6.6-q-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 (101) hide show
  1. package/dist/buildinschemas/autoincreament.d.ts.map +1 -1
  2. package/dist/buildinschemas/autoincreament.js +17 -14
  3. package/dist/buildinschemas/autoincreament.js.map +1 -1
  4. package/dist/buildinschemas/branch.d.ts.map +1 -1
  5. package/dist/buildinschemas/branch.js +25 -24
  6. package/dist/buildinschemas/branch.js.map +1 -1
  7. package/dist/buildinschemas/changehistories.d.ts.map +1 -1
  8. package/dist/buildinschemas/changehistories.js +10 -9
  9. package/dist/buildinschemas/changehistories.js.map +1 -1
  10. package/dist/buildinschemas/customfield.d.ts.map +1 -1
  11. package/dist/buildinschemas/customfield.js +16 -15
  12. package/dist/buildinschemas/customfield.js.map +1 -1
  13. package/dist/buildinschemas/docnoformat.d.ts.map +1 -1
  14. package/dist/buildinschemas/docnoformat.js +34 -23
  15. package/dist/buildinschemas/docnoformat.js.map +1 -1
  16. package/dist/buildinschemas/documentevent.d.ts.map +1 -1
  17. package/dist/buildinschemas/documentevent.js +36 -26
  18. package/dist/buildinschemas/documentevent.js.map +1 -1
  19. package/dist/buildinschemas/keyvaluepair.d.ts.map +1 -1
  20. package/dist/buildinschemas/keyvaluepair.js +7 -6
  21. package/dist/buildinschemas/keyvaluepair.js.map +1 -1
  22. package/dist/buildinschemas/organization.d.ts.map +1 -1
  23. package/dist/buildinschemas/organization.js +34 -30
  24. package/dist/buildinschemas/organization.js.map +1 -1
  25. package/dist/buildinschemas/permission.d.ts.map +1 -1
  26. package/dist/buildinschemas/permission.js +16 -7
  27. package/dist/buildinschemas/permission.js.map +1 -1
  28. package/dist/buildinschemas/systemmessage.d.ts.map +1 -1
  29. package/dist/buildinschemas/systemmessage.js +35 -32
  30. package/dist/buildinschemas/systemmessage.js.map +1 -1
  31. package/dist/buildinschemas/tenant.d.ts.map +1 -1
  32. package/dist/buildinschemas/tenant.js +17 -16
  33. package/dist/buildinschemas/tenant.js.map +1 -1
  34. package/dist/buildinschemas/user.d.ts.map +1 -1
  35. package/dist/buildinschemas/user.js +34 -31
  36. package/dist/buildinschemas/user.js.map +1 -1
  37. package/dist/buildinschemas/webhook.d.ts.map +1 -1
  38. package/dist/buildinschemas/webhook.js +24 -23
  39. package/dist/buildinschemas/webhook.js.map +1 -1
  40. package/dist/framework.d.ts +2 -0
  41. package/dist/framework.d.ts.map +1 -1
  42. package/dist/framework.js +92 -57
  43. package/dist/framework.js.map +1 -1
  44. package/dist/generate.d.ts.map +1 -1
  45. package/dist/generate.js +175 -34
  46. package/dist/generate.js.map +1 -1
  47. package/dist/index.js +30 -12
  48. package/dist/index.js.map +1 -1
  49. package/dist/processors/jsonschemabuilder.js +14 -12
  50. package/dist/processors/jsonschemabuilder.js.map +1 -1
  51. package/dist/type.d.ts +44 -5
  52. package/dist/type.d.ts.map +1 -1
  53. package/dist/type.js.map +1 -1
  54. package/package.json +1 -1
  55. package/src/buildinschemas/autoincreament.ts +35 -33
  56. package/src/buildinschemas/branch.ts +47 -47
  57. package/src/buildinschemas/changehistories.ts +31 -30
  58. package/src/buildinschemas/customfield.ts +17 -16
  59. package/src/buildinschemas/docnoformat.ts +54 -43
  60. package/src/buildinschemas/documentevent.ts +42 -33
  61. package/src/buildinschemas/keyvaluepair.ts +25 -25
  62. package/src/buildinschemas/organization.ts +54 -50
  63. package/src/buildinschemas/permission.ts +34 -25
  64. package/src/buildinschemas/systemmessage.ts +39 -38
  65. package/src/buildinschemas/tenant.ts +46 -45
  66. package/src/buildinschemas/user.ts +64 -60
  67. package/src/buildinschemas/webhook.ts +62 -61
  68. package/src/framework.ts +307 -251
  69. package/src/generate.ts +608 -434
  70. package/src/index.ts +136 -118
  71. package/src/processors/jsonschemabuilder.ts +6 -4
  72. package/src/type.ts +287 -226
  73. package/templates/basic/miniAppJsSdk/resource-bridge.service.ts.eta +119 -0
  74. package/templates/basic/miniAppStreamlitSdk/resource-bridge.service.ts.eta +228 -0
  75. package/templates/basic/nuxt/jsonschema.ts.eta +7 -0
  76. package/templates/basic/nuxt/resource-bridge.editable.service.ts.eta +40 -0
  77. package/templates/basic/nuxt/resource-bridge.service.ts.eta +165 -0
  78. package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +27 -9
  79. package/templates/miniAppJsSdk/src/index.ts.eta +28 -0
  80. package/templates/miniAppJsSdk/src/services/bridge-resource-accessor.service.ts.eta +70 -0
  81. package/templates/miniAppJsSdk/src/services/bridge.service.ts.eta +91 -0
  82. package/templates/miniAppJsSdk/src/types/service.type.ts.eta +22 -0
  83. package/templates/miniAppStreamlitSdk/simtrain_eco_mini_app_streamlit_sdk/sdk.py.eta +76 -0
  84. package/templates/nest/src/simpleapp/generate/jsonschemas/index.ts.eta +11 -0
  85. package/templates/nest/src/simpleapp/types/customfield.ts.eta +14 -0
  86. package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +3 -3
  87. package/templates/nuxt/components/simpleApp/SimpleAppInputTable.vue.eta +0 -1
  88. package/templates/nuxt/plugins/18.simpleapp-custom-field-store.ts.eta +9 -3
  89. package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +316 -341
  90. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +32 -21
  91. package/templates/nuxt/simpleapp/generate/jsonSchemas/index.ts.eta +11 -0
  92. package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/common.constant.ts.eta +16 -0
  93. package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/resource.constant.ts.eta +46 -0
  94. package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge-resource-accessor.service.ts.eta +63 -0
  95. package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge.service.ts.eta +129 -0
  96. package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/bridge.type.ts.eta +81 -0
  97. package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/resource-mapper.type.ts.eta +55 -0
  98. package/templates/nuxt/types/others.ts.eta +74 -65
  99. package/templates/nuxt/types/schema.ts.eta +225 -188
  100. package/templates/project/build.sh.eta +4 -0
  101. package/templates/nuxt/simpleapp/generate/clients/SimpleAppCustomFieldClient.ts.eta +0 -191
package/src/generate.ts CHANGED
@@ -1,511 +1,685 @@
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
+ customField: {
235
+ isEnable:
236
+ jsonschemas[docname][X_SIMPLEAPP_CONFIG]?.customField?.isEnable ?? false
237
+ }
238
+ };
239
+
240
+ const templatefolder = `${constants.templatedir}/${rendertype}`;
241
+ // log.info(`- Generate ${docname}, ${doctype}, ${templatefolder}`)
242
+ const eta = new Eta({
243
+ views: '/',
244
+ functionHeader: getCodeGenHelper()
245
+
246
+ // 'const capitalizeFirstLetter = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);' +
247
+ // 'const initType=(str)=>{return ["string","number","boolean","array","object"].includes(str) ? capitalizeFirstLetter(str) : str;}'+
248
+ // 'const camelCaseToWords = (s: string) =>{const result = s.replace(/([A-Z])/g, \' $1\');return result.charAt(0).toUpperCase() + result.slice(1);}',
249
+ });
250
+
251
+ const backendTargetFolder = `${backendFolder}/src/simpleapp/generate`;
252
+ const simpleappTargetFolder = `${backendFolder}/src/simpleapp`;
253
+ const backendServiceFolder = `${backendFolder}/src/simpleapp/services`;
254
+
255
+ Object.keys(generateTypes).forEach((foldertype) => {
256
+ //generate code for every schema
257
+ const generateTemplatefolder = `${constants.templatedir}/basic/${foldertype}`;
258
+ const allfiles = readdirSync(generateTemplatefolder, { recursive: true });
259
+ for (let j = 0; j < allfiles.length; j++) {
260
+ const filename: string = String(allfiles[j]);
261
+ const templatepath = `${generateTemplatefolder}/${filename}`;
262
+
263
+ if (_.last(filename.split('.')) != 'eta') {
264
+ // log.warn("skip file: ",filename)
265
+ continue;
266
+ }
267
+
268
+ // no turn on split mobile url, skip create mobile page
269
+ if (!configs?.splitMobilePage && filename.includes('mobile.')) continue;
270
+ if (foldertype == 'nest') {
271
+ const arrfilename: string[] = filename.split('.');
272
+ const filecategory = arrfilename[0];
273
+ const filetype = arrfilename[1];
274
+ const autogeneratetypes = [
275
+ 'apischema',
276
+ 'controller',
277
+ 'jsonschema',
278
+ 'model',
279
+ 'resolver',
280
+ 'processor',
281
+ 'type',
282
+ 'default'
283
+ ];
284
+ // log.info("process nest: ",doctype," :",filename)
285
+ if (autogeneratetypes.includes(filecategory)) {
286
+ //multiple files in folder, append s at folder name
287
+ const storein = `${backendTargetFolder}/${filecategory}s`;
288
+ const targetfile = `${storein}/${doctype}.${filecategory}.${filetype}`;
289
+ if (!existsSync(storein)) {
290
+ mkdirSync(storein, { recursive: true });
291
+ }
292
+
293
+ const filecontent = eta.render(templatepath, variables);
294
+ writeFileSync(targetfile, filecontent);
295
+ // console.log("Write complete")
296
+ } else if (filecategory == 'service') {
297
+ //service file won't override if exists
298
+ const targetfolder = `${simpleappTargetFolder}/${filecategory}s`;
299
+ const targetfile = `${targetfolder}/${doctype}.${filecategory}.${filetype}`;
300
+ if (!existsSync(targetfolder)) {
301
+ mkdirSync(targetfolder, { recursive: true });
302
+ }
303
+
304
+ if (
305
+ !existsSync(targetfile) ||
306
+ readFileSync(targetfile, 'utf-8').includes(
307
+ '--remove-this-line-to-prevent-override--'
308
+ )
309
+ ) {
310
+ // log.info("Write ",targetfile)
311
+ const filecontent = eta.render(templatepath, variables);
312
+ writeFileSync(targetfile, filecontent);
313
+ } else {
314
+ // log.info("skip ",targetfile)
315
+ }
316
+ } else if (filecategory == 'test' && isGenerateTest(variables)) {
317
+ const targetfolder = `${backendFolder}/test/documents/${docname}`;
318
+ const targetfile = `${targetfolder}/${docname}.e2e-spec.ts`;
319
+ // log.warn("test file: ",targetfile)
320
+ // `${backendServiceFolder}/${doctype}.${filecategory}.${filetype}`
321
+ if (!existsSync(targetfolder)) {
322
+ mkdirSync(targetfolder, { recursive: true });
323
+ }
324
+ if (!existsSync(targetfile)) {
325
+ log.info('process: ', targetfile);
326
+ const filecontent = eta.render(templatepath, variables);
327
+ writeFileSync(targetfile, filecontent);
328
+ //create stub files
329
+ mkdirSync(`${targetfolder}/stub`, { recursive: true });
330
+ writeFileSync(
331
+ `${targetfolder}/stub/id1.create.ts`,
332
+ 'export default () => ({_id:"00000000-0000-0000-0000-000000000001",})'
333
+ );
334
+ writeFileSync(
335
+ `${targetfolder}/stub/id1.update.ts`,
336
+ 'export default () => ({_id:"00000000-0000-0000-0000-000000000001",})'
337
+ );
338
+ writeFileSync(
339
+ `${targetfolder}/stub/id2.create.ts`,
340
+ 'export default () => ({_id:"00000000-0000-0000-0000-000000000002",})'
341
+ );
342
+ }
241
343
  }
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);
273
- }
274
- else{
275
- // log.info("skip ",targetfile)
344
+ } else if (foldertype == 'nuxt') {
345
+ // console.log("Process nuxt: ",docname)
346
+ const capname = capitalizeFirstLetter(docname);
347
+ // const resourceName =
348
+
349
+ const validateWritePage = (targetfile: string, isexists: boolean) => {
350
+ if (
351
+ !jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
352
+ !targetfile.includes('Viewer') &&
353
+ !targetfile.includes('Form')
354
+ ) {
355
+ return false;
356
+ } else if (!isexists) {
357
+ return true;
358
+ } else if (
359
+ !existsSync(targetfile) ||
360
+ readFileSync(targetfile, 'utf-8').includes(
361
+ '--remove-this-line-to-prevent-override--'
362
+ ) ||
363
+ readFileSync(targetfile, 'utf-8').includes('delete-me')
364
+ ) {
365
+ return true;
366
+ } else {
367
+ return false;
368
+ }
369
+ };
370
+ const mapfiles = {
371
+ 'pages.form.vue.eta': {
372
+ to: 'components/form',
373
+ as: `Form${_.upperFirst(docname)}.vue`,
374
+ validate: validateWritePage
375
+ },
376
+ 'pages.mobile.[id].vue.eta': {
377
+ to: `pages/[xorg]/mobile/${docname}`,
378
+ as: '[id].vue',
379
+ validate: validateWritePage
380
+ },
381
+ 'pages.mobile.landing.vue.eta': {
382
+ to: `pages/[xorg]/mobile/${docname}`,
383
+ as: `index.vue`,
384
+ validate: validateWritePage
385
+ },
386
+ 'component.select.vue.eta': {
387
+ to: 'components/select',
388
+ as: `Select${_.upperFirst(docname)}.vue`,
389
+ validate: validateWritePage
390
+ },
391
+ 'pages.viewer.vue.eta': {
392
+ to: `components/viewer`,
393
+ as: `Viewer${_.upperFirst(docname)}.vue`,
394
+ validate: validateWritePage
395
+ },
396
+ 'pages.[id].vue.eta': {
397
+ to: `pages/[xorg]/${docname}`,
398
+ as: '[id].vue',
399
+ validate: validateWritePage
400
+ },
401
+ 'pages.landing.vue.eta': {
402
+ to: `pages/[xorg]/${docname}`,
403
+ as: `../${docname}.vue`,
404
+ validate: validateWritePage
405
+ },
406
+
407
+ 'simpleapp.doc.ts.eta': {
408
+ to: `simpleapp/docs`,
409
+ as: `${capname}Doc.ts`,
410
+ validate: (targetfile: string, isexists: boolean) => !isexists
411
+ },
412
+ 'default.ts.eta': {
413
+ to: `simpleapp/generate/defaults`,
414
+ as: `${capname}.default.ts`,
415
+ validate: (targetfile: string, isexists: boolean) => {
416
+ return true;
276
417
  }
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
-
418
+ },
419
+
420
+ 'simpleapp.generate.client.ts.eta': {
421
+ to: `simpleapp/generate/clients`,
422
+ as: `${capname}Client.ts`,
423
+ validate: (targetfile: string, isexists: boolean) => {
424
+ return true;
297
425
  }
298
- }
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
426
+ },
427
+
428
+ 'resource-bridge.service.ts.eta': {
429
+ to: 'simpleapp/generate/miniApp/bridge/services/resources',
430
+ as: `${_.kebabCase(resourceName)}-bridge.service.ts`,
431
+ validate: (targetfile: string, isexists: boolean) => {
432
+ return true;
307
433
  }
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
434
+ },
435
+ 'resource-bridge.editable.service.ts.eta': {
436
+ to: 'simpleapp/generate/miniApp/bridge/services/editable/resources',
437
+ as: `${_.kebabCase(resourceName)}-bridge.editable.service.ts`,
438
+ validate: (targetfile: string, isexists: boolean) => !isexists
439
+ },
440
+ 'jsonschema.ts.eta': {
441
+ to: 'simpleapp/generate/jsonSchemas',
442
+ as: `${doctype}.jsonschema.ts`,
443
+ validate: (targetfile: string, isexists: boolean) => {
444
+ return true;
315
445
  }
316
446
  }
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
- },
374
- }
447
+ };
375
448
 
449
+ // if(configs?.splitMobilePage){
450
+ // mapfiles['pages.mobile.[id].vue.eta'] = {
451
+ // to:`pages/[xorg]/mobile/${docname}`,
452
+ // as:'[id].vue',
453
+ // validate: validateWritePage
454
+ // }
455
+ // mapfiles['pages.mobile.landing.vue.eta'] = {
456
+ // to:`pages/[xorg]/mobile/${docname}`,
457
+ // as:`index.vue`,
458
+ // validate: validateWritePage
459
+ // }
460
+ // }
376
461
 
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
- }
462
+ const target = mapfiles[filename];
463
+ // console.log(target);
464
+ const targetfolder = `${generateTypes[foldertype]}/${target.to}`;
465
+ const targetfile = `${targetfolder}/${target.as}`;
400
466
 
467
+ // console.log("targetfile",targetfile);
468
+ if (
469
+ jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
470
+ !existsSync(targetfolder)
471
+ ) {
472
+ console.log('Mkdir', targetfolder);
473
+ mkdirSync(targetfolder, { recursive: true });
474
+ }
475
+
476
+ const isexists = existsSync(targetfile);
477
+ const iswrite: boolean = target.validate(targetfile, isexists);
478
+ // log.info("iswrite: ",iswrite)
479
+
480
+ if (iswrite) {
481
+ const filecontent = eta.render(templatepath, variables);
482
+ writeFileSync(targetfile, filecontent);
483
+ }
484
+ // console.log("complete, go to next file")
485
+ } else if (foldertype === 'miniAppJsSdk') {
486
+ const validateWritePage = (targetfile: string, isexists: boolean) => {
487
+ if (
488
+ !jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
489
+ !targetfile.includes('Viewer') &&
490
+ !targetfile.includes('Form')
491
+ ) {
492
+ return false;
493
+ } else if (!isexists) {
494
+ return true;
495
+ } else if (
496
+ !existsSync(targetfile) ||
497
+ readFileSync(targetfile, 'utf-8').includes(
498
+ '--remove-this-line-to-prevent-override--'
499
+ ) ||
500
+ readFileSync(targetfile, 'utf-8').includes('delete-me')
501
+ ) {
502
+ return true;
503
+ } else {
504
+ return false;
505
+ }
506
+ };
401
507
 
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);
508
+ const mapfiles = {
509
+ 'resource-bridge.service.ts.eta': {
510
+ to: 'src/services/resources',
511
+ as: `${_.kebabCase(resourceName)}-bridge.service.ts`,
512
+ validate: (targetfile: string, isexists: boolean) => {
513
+ return true;
409
514
  }
410
- // console.log("complete, go to next file")
411
-
412
-
515
+ }
516
+ };
517
+
518
+ const target = mapfiles[filename];
519
+ const targetfolder = `${generateTypes[foldertype]}/${target.to}`;
520
+ const targetfile = `${targetfolder}/${target.as}`;
413
521
 
522
+ if (
523
+ jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
524
+ !existsSync(targetfolder)
525
+ ) {
526
+ console.log('Mkdir', targetfolder);
527
+ mkdirSync(targetfolder, { recursive: true });
414
528
  }
415
- }
416
-
417
529
 
418
- })
419
- // console.log("Complete generate schema")
420
-
530
+ const isexists = existsSync(targetfile);
531
+ const iswrite: boolean = target.validate(targetfile, isexists);
532
+ // log.info("iswrite: ",iswrite)
533
+
534
+ if (iswrite) {
535
+ const filecontent = eta.render(templatepath, variables);
536
+ writeFileSync(targetfile, filecontent);
537
+ }
538
+ } else if (foldertype === 'miniAppStreamlitSdk') {
539
+ const validateWritePage = (targetfile: string, isexists: boolean) => {
540
+ if (
541
+ !jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
542
+ !targetfile.includes('Viewer') &&
543
+ !targetfile.includes('Form')
544
+ ) {
545
+ return false;
546
+ } else if (!isexists) {
547
+ return true;
548
+ } else if (
549
+ !existsSync(targetfile) ||
550
+ readFileSync(targetfile, 'utf-8').includes(
551
+ '--remove-this-line-to-prevent-override--'
552
+ ) ||
553
+ readFileSync(targetfile, 'utf-8').includes('delete-me')
554
+ ) {
555
+ return true;
556
+ } else {
557
+ return false;
558
+ }
559
+ };
560
+
561
+ const mapfiles = {
562
+ 'resource-bridge.service.ts.eta': {
563
+ to: 'simtrain_eco_mini_app_streamlit_sdk/services/resources',
564
+ as: `${_.snakeCase(resourceName)}.py`,
565
+ validate: (targetfile: string, isexists: boolean) => {
566
+ return true;
567
+ }
568
+ }
569
+ };
421
570
 
422
- }
571
+ const target = mapfiles[filename];
572
+ const targetfolder = `${generateTypes[foldertype]}/${target.to}`;
573
+ const targetfile = `${targetfolder}/${target.as}`;
423
574
 
575
+ if (
576
+ jsonschemas[docname][X_SIMPLEAPP_CONFIG]['pageType'] &&
577
+ !existsSync(targetfolder)
578
+ ) {
579
+ console.log('Mkdir', targetfolder);
580
+ mkdirSync(targetfolder, { recursive: true });
581
+ }
424
582
 
425
- const generateSystemFiles=(modules:ModuleObject[],allbpmn)=>{
583
+ const isexists = existsSync(targetfile);
584
+ const iswrite: boolean = target.validate(targetfile, isexists);
585
+ // log.info("iswrite: ",iswrite)
586
+
587
+ if (iswrite) {
588
+ const filecontent = eta.render(templatepath, variables);
589
+ if (!existsSync(path.dirname(targetfile)))
590
+ mkdirSync(path.dirname(targetfile), { recursive: true });
591
+ writeFileSync(targetfile, filecontent);
592
+ }
593
+ }
594
+ }
595
+ });
596
+ };
597
+
598
+ const generateSystemFiles = (modules: ModuleObject[], allbpmn) => {
426
599
  const renderProperties = {
427
- configs:configs,
428
- modules:modules,
429
- allroles:allroles,
430
- foreignkeys:allforeignkeys,
431
- allfields:allfields,
600
+ configs: configs,
601
+ modules: modules,
602
+ allroles: allroles,
603
+ foreignkeys: allforeignkeys,
604
+ allfields: allfields,
432
605
  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
- }
606
+ lang: langdata
607
+ };
608
+
609
+ Object.getOwnPropertyNames(generateTypes).forEach((foldertype) => {
610
+ const frameworkpath = generateTypes[foldertype];
611
+ // log.info("Generate ",foldertype)
612
+ const frameworkfolder = `${constants.templatedir}/${foldertype}`;
613
+ const frameworkfiles = readdirSync(frameworkfolder, { recursive: true });
614
+ const eta = new Eta({
615
+ views: frameworkfolder,
616
+ functionHeader: getCodeGenHelper()
617
+ });
618
+
619
+ //generate code for framework
620
+ for (let index = 0; index < frameworkfiles.length; index++) {
621
+ // log.info("Process systemfiles ",frameworkfiles[index])
622
+ const longfilename: string = String(frameworkfiles[index]);
623
+ const patharr = longfilename.split('/');
624
+ const filename = _.last(patharr);
625
+ const arrfilename: string[] = filename.split('.');
626
+ // log.info("check longfilename:::",longfilename,"become====",arrfilename)
627
+ //only process .eta
628
+ if (['eta', '_eta'].includes(_.last(arrfilename))) {
629
+ const relativepath = longfilename.includes('/')
630
+ ? longfilename.replace(`/${filename}`, '')
631
+ : '';
632
+ const foldername = `${frameworkpath}/${relativepath}`;
633
+ const shortfilename = filename.replace('.eta', '').replace('._eta', '');
634
+ const targetfilename = `${foldername}/${shortfilename}`;
635
+ let forceoverride = true;
636
+ if (filename.includes('._eta') && existsSync(targetfilename)) {
637
+ const filecontent = readFileSync(targetfilename, 'utf-8');
474
638
 
475
-
476
- if(!existsSync(foldername)){
477
- mkdirSync(foldername,{recursive:true})
639
+ if (
640
+ filecontent.includes('--remove-this-line-to-prevent-override--')
641
+ ) {
642
+ forceoverride = true;
643
+ } else {
644
+ forceoverride = false;
478
645
  }
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
646
  }
487
-
647
+ // log.warn("Process=== ",targetfilename)
648
+ if (existsSync(targetfilename) && forceoverride == false) {
649
+ // log.info("file exists, skip: ",targetfilename)
650
+ continue;
651
+ }
652
+
653
+ if (!existsSync(foldername)) {
654
+ mkdirSync(foldername, { recursive: true });
488
655
  }
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}`)
656
+ // const templatename = `${frameworkfolder}/${longfilename}`.replace(".eta","").replace('._eta','')
657
+ // log.info("Write template:",targetfilename)
658
+ const txt = eta.render(longfilename, renderProperties);
659
+ writeFileSync(targetfilename, txt);
660
+ } else {
661
+ // log.warn("skip: ",longfilename)
662
+ }
503
663
  }
504
- }
505
- return roles
506
- }
664
+ });
665
+ };
507
666
 
667
+ const prepareRoles = (groupsettings) => {
668
+ let roles = [];
669
+ const docnames = Object.getOwnPropertyNames(groupsettings);
670
+ for (let i = 0; i < docnames.length; i++) {
671
+ let docname = docnames[i];
672
+ let docpermissions: string[] = groupsettings[docname];
673
+ for (let j = 0; j < docpermissions.length; j++) {
674
+ const perm = docpermissions[j];
675
+ const typename = _.upperFirst(docname);
676
+ roles.push(`${typename}_${perm}`);
677
+ }
678
+ }
679
+ return roles;
680
+ };
508
681
 
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);}'
682
+ const getCodeGenHelper = () =>
683
+ 'const capitalizeFirstLetter = (str) => !str ? `Object` : str.slice(0, 1).toUpperCase() + str.slice(1);' +
684
+ 'const initType=(str)=>{return ["string","number","boolean","array","object"].includes(str) ? capitalizeFirstLetter(str) : str;};' +
685
+ "const camelCaseToWords = (s) => {const result = s.replace(/([A-Z])/g, ' $1');return result.charAt(0).toUpperCase() + result.slice(1);}";