@things-factory/operato-tools 7.0.1-beta.0 → 7.0.1-beta.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,22 +4,21 @@ import { Entity, EntityColumn } from '@things-factory/resource-base'
4
4
 
5
5
  const { camelCase, startCase, snakeCase, kebabCase } = require('lodash')
6
6
  const { plural } = require('pluralize')
7
- const fs = require('fs');
8
-
7
+ const fs = require('fs')
9
8
 
10
9
  @Resolver()
11
10
  export class OperatoToolCreateService {
12
11
  @Query(returns => Boolean, { description: 'Operato Tool Create Service' })
13
12
  async toolCreateService(@Arg('id') id: string, @Ctx() context: any): Promise<Boolean> {
14
13
  const { domain } = context.state
15
- // Entity 조회
14
+ // Entity 조회
16
15
  const entity: Entity = await getRepository(Entity).findOne({
17
16
  where: {
18
17
  id
19
18
  }
20
19
  })
21
20
 
22
- // Entity 컬럼 조회
21
+ // Entity 컬럼 조회
23
22
  const entityColumns: EntityColumn[] = await getRepository(EntityColumn).find({
24
23
  where: {
25
24
  domain: { id: domain.id },
@@ -27,32 +26,38 @@ export class OperatoToolCreateService {
27
26
  }
28
27
  })
29
28
 
30
- let { name = '', bundle = '' } = entity || {};
29
+ let { name = '', bundle = '' } = entity || {}
31
30
 
32
- // 프로젝트 Root Path 구하기
33
- let appRootPath: string = this.getProjectRootPath();
34
- let serviceName: string = kebabCase(name);
35
- // 서비스 경로 생성
36
- await this.createServicePath(appRootPath, bundle, serviceName);
31
+ // 프로젝트 Root Path 구하기
32
+ let appRootPath: string = this.getProjectRootPath()
33
+ let serviceName: string = kebabCase(name)
34
+ // 서비스 경로 생성
35
+ await this.createServicePath(appRootPath, bundle, serviceName)
37
36
 
38
- // 서비스 파일 생성
39
- await this.createServiceFiles(appRootPath, bundle, name, serviceName, entity, entityColumns);
37
+ // 서비스 파일 생성
38
+ await this.createServiceFiles(appRootPath, bundle, name, serviceName, entity, entityColumns)
40
39
 
41
- return true;
40
+ return true
42
41
  }
43
42
 
44
-
45
43
  /**
46
- * 서비스 연관 파일 생성
47
- * @param appRootPath
48
- * @param moduleName
49
- * @param name
44
+ * 서비스 연관 파일 생성
45
+ * @param appRootPath
46
+ * @param moduleName
47
+ * @param name
50
48
  * @param serviceName
51
- * @param entity
52
- * @param entityColumns
49
+ * @param entity
50
+ * @param entityColumns
53
51
  */
54
- async createServiceFiles(appRootPath: string, moduleName: string, name: string, serviceName: string, entity: Entity, entityColumns: EntityColumn[]) {
55
- // 이름 케이스 워드 만들기
52
+ async createServiceFiles(
53
+ appRootPath: string,
54
+ moduleName: string,
55
+ name: string,
56
+ serviceName: string,
57
+ entity: Entity,
58
+ entityColumns: EntityColumn[]
59
+ ) {
60
+ // 이름 케이스 워드 만들기
56
61
  let nameMap = {
57
62
  name: serviceName,
58
63
  tableName: entity.tableName,
@@ -62,437 +67,454 @@ export class OperatoToolCreateService {
62
67
  pluralPascalCaseName: startCase(camelCase(plural(name))).replace(/ /g, ''),
63
68
  pluralCamelCaseName: camelCase(plural(name))
64
69
  }
65
- let servicePath = `${appRootPath}/packages/${moduleName}/server/service/`;
70
+ let servicePath = `${appRootPath}/packages/${moduleName}/server/service/`
66
71
 
67
- if(['JSON','COPY'].includes(entity.dataProp)){
68
- await this.createHistoryServiceFiles(servicePath, serviceName, entity, entityColumns, nameMap);
72
+ if (['JSON', 'COPY'].includes(entity.dataProp)) {
73
+ await this.createHistoryServiceFiles(servicePath, serviceName, entity, entityColumns, nameMap)
69
74
  } else {
70
- await this.createNoHistoryServiceFiels(servicePath, serviceName, entity, entityColumns, nameMap);
75
+ await this.createNoHistoryServiceFiels(servicePath, serviceName, entity, entityColumns, nameMap)
71
76
  }
72
77
  }
73
78
 
74
- async createHistoryServiceFiles(servicePath: string, serviceName: string, entity: Entity, entityColumns: EntityColumn[], nameMap: any){
75
- // 서비스 연관 파일 생성
76
- await this.writeFile(servicePath + `${serviceName}/index.ts`, serviceHistoryIndex, nameMap);
77
-
78
- // Entity
79
- let entityText = this.createEntityText(entity, entityColumns);
80
- await this.writeFile(servicePath + `${serviceName}/${serviceName}.ts`, entityText, nameMap);
81
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-query.ts`, serviceQuery, nameMap);
82
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-mutation.ts`, serviceMutation, nameMap);
83
- // TYPE
84
- let typeText = this.createTypeText(entityColumns);
85
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-type.ts`, typeText, nameMap);
86
-
87
-
88
- // 이력관리 entity 생성
89
- let historyText = this.createHistoryEntityText(entity, entityColumns);
90
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-history.ts`, historyText, nameMap);
91
- let entitySubscriberEntityToJson = '';
92
- if(entity.dataProp == 'JSON'){
93
- entitySubscriberEntityToJson =
94
- `
79
+ async createHistoryServiceFiles(
80
+ servicePath: string,
81
+ serviceName: string,
82
+ entity: Entity,
83
+ entityColumns: EntityColumn[],
84
+ nameMap: any
85
+ ) {
86
+ // 서비스 연관 파일 생성
87
+ await this.writeFile(servicePath + `${serviceName}/index.ts`, serviceHistoryIndex, nameMap)
88
+
89
+ // Entity
90
+ let entityText = this.createEntityText(entity, entityColumns)
91
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}.ts`, entityText, nameMap)
92
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-query.ts`, serviceQuery, nameMap)
93
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-mutation.ts`, serviceMutation, nameMap)
94
+ // TYPE
95
+ let typeText = this.createTypeText(entityColumns)
96
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-type.ts`, typeText, nameMap)
97
+
98
+ // 이력관리 entity 생성
99
+ let historyText = this.createHistoryEntityText(entity, entityColumns)
100
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-history.ts`, historyText, nameMap)
101
+ let entitySubscriberEntityToJson = ''
102
+ if (entity.dataProp == 'JSON') {
103
+ entitySubscriberEntityToJson = `
95
104
  public createHistoryEntity(manager, entity) {
96
105
  let history = manager.create(this.historyEntity, entity);
97
106
  history.historyJson = JSON.stringify(entity);
98
107
  return history;
99
108
  }
100
109
  `
101
- await this.writeFile(servicePath + `${serviceName}/event-subscriber.ts`, serviceEntitySubscriber, nameMap);
102
- } else {
103
- entitySubscriberEntityToJson = '';
104
- }
105
- let subscriberTxt = serviceEntitySubscriber.replace(/{{entityToJson}}/g, entitySubscriberEntityToJson);
106
- await this.writeFile(servicePath + `${serviceName}/event-subscriber.ts`, subscriberTxt, nameMap);
107
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-history-query.ts`, serviceHistoryQuery, nameMap);
108
- // TYPE
109
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-history-type.ts`, sereviceHistoryType, nameMap);
110
-
111
-
112
- // 전체 서비스 index.ts 파일
113
- let allServiceIdxPath = servicePath + 'index.ts';
114
- if (await this.existsPath(allServiceIdxPath) == false) {
115
- await this.writeFile(allServiceIdxPath, allIndex, nameMap);
116
- }
117
-
118
- let allIdxFileTxt = await fs.readFileSync(allServiceIdxPath, 'utf8');
119
-
120
- if (allIdxFileTxt.indexOf(`export * from './${nameMap.name}/${nameMap.name}-history'`) < 0) {
121
- allIdxFileTxt = allIdxFileTxt.replace(
122
- /\/\* EXPORT ENTITY TYPES \*\//,
123
- `/* EXPORT ENTITY TYPES */\nexport * from './${nameMap.name}/${nameMap.name}-history'`
124
- );
125
- }
110
+ await this.writeFile(servicePath + `${serviceName}/event-subscriber.ts`, serviceEntitySubscriber, nameMap)
111
+ } else {
112
+ entitySubscriberEntityToJson = ''
113
+ }
114
+ let subscriberTxt = serviceEntitySubscriber.replace(/{{entityToJson}}/g, entitySubscriberEntityToJson)
115
+ await this.writeFile(servicePath + `${serviceName}/event-subscriber.ts`, subscriberTxt, nameMap)
116
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-history-query.ts`, serviceHistoryQuery, nameMap)
117
+ // TYPE
118
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-history-type.ts`, sereviceHistoryType, nameMap)
119
+
120
+ // 전체 서비스 index.ts 파일
121
+ let allServiceIdxPath = servicePath + 'index.ts'
122
+ if ((await this.existsPath(allServiceIdxPath)) == false) {
123
+ await this.writeFile(allServiceIdxPath, allIndex, nameMap)
124
+ }
126
125
 
127
- if (allIdxFileTxt.indexOf(`export * from './${nameMap.name}/${nameMap.name}'`) < 0) {
128
- allIdxFileTxt = allIdxFileTxt.replace(
129
- /\/\* EXPORT ENTITY TYPES \*\//,
130
- `/* EXPORT ENTITY TYPES */\nexport * from './${nameMap.name}/${nameMap.name}'`
131
- );
132
- }
133
-
134
- if (allIdxFileTxt.indexOf(`import { entities as ${nameMap.pascalCaseName}Entities, resolvers as ${nameMap.pascalCaseName}Resolvers, subscribers as ${nameMap.pascalCaseName}EntitySubscribers } from './${nameMap.name}'`) < 0) {
135
- allIdxFileTxt = allIdxFileTxt.replace(
136
- /\/\* IMPORT ENTITIES AND RESOLVERS \*\//,
137
- `/* IMPORT ENTITIES AND RESOLVERS */\nimport { entities as ${nameMap.pascalCaseName}Entities, resolvers as ${nameMap.pascalCaseName}Resolvers, subscribers as ${nameMap.pascalCaseName}EntitySubscribers } from './${nameMap.name}'`
138
- );
139
- }
140
-
141
-
142
- if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}Entities,`) < 0) {
143
- allIdxFileTxt = allIdxFileTxt.replace(
144
- /\/\* ENTITIES \*\//, `/* ENTITIES */\n\t...${nameMap.pascalCaseName}Entities,`
145
- );
146
- }
147
-
148
- if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}Resolvers,`) < 0) {
149
- allIdxFileTxt = allIdxFileTxt.replace(
150
- /\/\* RESOLVER CLASSES \*\//,
151
- `/* RESOLVER CLASSES */\n\t\t...${nameMap.pascalCaseName}Resolvers,`
152
- );
153
- }
154
-
155
- if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}EntitySubscribers,`) < 0) {
156
- allIdxFileTxt = allIdxFileTxt.replace(
157
- /\/\* SUBSCRIBERS \*\//,
158
- `/* SUBSCRIBERS */\n\t\t...${nameMap.pascalCaseName}EntitySubscribers,`
159
- );
160
- }
161
-
162
- await this.writeFile(allServiceIdxPath, allIdxFileTxt, nameMap);
163
- }
126
+ let allIdxFileTxt = await fs.readFileSync(allServiceIdxPath, 'utf8')
164
127
 
165
- async createNoHistoryServiceFiels(servicePath: string, serviceName: string, entity: Entity, entityColumns: EntityColumn[], nameMap: any){
166
- // 서비스 연관 파일 생성
167
- await this.writeFile(servicePath + `${serviceName}/index.ts`, serviceIndex, nameMap);
168
-
169
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-query.ts`, serviceQuery, nameMap);
170
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-mutation.ts`, serviceMutation, nameMap);
171
-
172
- // Entity
173
- let entityText = this.createEntityText(entity, entityColumns);
174
- await this.writeFile(servicePath + `${serviceName}/${serviceName}.ts`, entityText, nameMap);
175
-
176
- // TYPE
177
- let typeText = this.createTypeText(entityColumns);
178
- await this.writeFile(servicePath + `${serviceName}/${serviceName}-type.ts`, typeText, nameMap);
179
-
180
-
181
- // 전체 서비스 index.ts 파일
182
- let allServiceIdxPath = servicePath + 'index.ts';
183
- if (await this.existsPath(allServiceIdxPath) == false) {
184
- await this.writeFile(allServiceIdxPath, allIndex, nameMap);
185
- }
186
-
187
- let allIdxFileTxt = await fs.readFileSync(allServiceIdxPath, 'utf8');
188
-
189
- if (allIdxFileTxt.indexOf(`export * from './${nameMap.name}/${nameMap.name}'`) < 0) {
190
- allIdxFileTxt = allIdxFileTxt.replace(
191
- /\/\* EXPORT ENTITY TYPES \*\//,
192
- `/* EXPORT ENTITY TYPES */\nexport * from './${nameMap.name}/${nameMap.name}'`
193
- );
194
- }
195
-
196
- if (allIdxFileTxt.indexOf(`import { entities as ${nameMap.pascalCaseName}Entities, resolvers as ${nameMap.pascalCaseName}Resolvers } from './${nameMap.name}'`) < 0) {
197
- allIdxFileTxt = allIdxFileTxt.replace(
198
- /\/\* IMPORT ENTITIES AND RESOLVERS \*\//,
199
- `/* IMPORT ENTITIES AND RESOLVERS */\nimport { entities as ${nameMap.pascalCaseName}Entities, resolvers as ${nameMap.pascalCaseName}Resolvers } from './${nameMap.name}'`
200
- );
201
- }
202
-
203
-
204
- if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}Entities,`) < 0) {
205
- allIdxFileTxt = allIdxFileTxt.replace(
206
- /\/\* ENTITIES \*\//, `/* ENTITIES */\n\t...${nameMap.pascalCaseName}Entities,`
207
- );
208
- }
209
-
210
- if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}Resolvers,`) < 0) {
211
- allIdxFileTxt = allIdxFileTxt.replace(
212
- /\/\* RESOLVER CLASSES \*\//,
213
- `/* RESOLVER CLASSES */\n\t\t...${nameMap.pascalCaseName}Resolvers,`
214
- );
215
- }
128
+ if (allIdxFileTxt.indexOf(`export * from './${nameMap.name}/${nameMap.name}-history'`) < 0) {
129
+ allIdxFileTxt = allIdxFileTxt.replace(
130
+ /\/\* EXPORT ENTITY TYPES \*\//,
131
+ `/* EXPORT ENTITY TYPES */\nexport * from './${nameMap.name}/${nameMap.name}-history'`
132
+ )
133
+ }
134
+
135
+ if (allIdxFileTxt.indexOf(`export * from './${nameMap.name}/${nameMap.name}'`) < 0) {
136
+ allIdxFileTxt = allIdxFileTxt.replace(
137
+ /\/\* EXPORT ENTITY TYPES \*\//,
138
+ `/* EXPORT ENTITY TYPES */\nexport * from './${nameMap.name}/${nameMap.name}'`
139
+ )
140
+ }
216
141
 
217
- await this.writeFile(allServiceIdxPath, allIdxFileTxt, nameMap);
142
+ if (
143
+ allIdxFileTxt.indexOf(
144
+ `import { entities as ${nameMap.pascalCaseName}Entities, resolvers as ${nameMap.pascalCaseName}Resolvers, subscribers as ${nameMap.pascalCaseName}EntitySubscribers } from './${nameMap.name}'`
145
+ ) < 0
146
+ ) {
147
+ allIdxFileTxt = allIdxFileTxt.replace(
148
+ /\/\* IMPORT ENTITIES AND RESOLVERS \*\//,
149
+ `/* IMPORT ENTITIES AND RESOLVERS */\nimport { entities as ${nameMap.pascalCaseName}Entities, resolvers as ${nameMap.pascalCaseName}Resolvers, subscribers as ${nameMap.pascalCaseName}EntitySubscribers } from './${nameMap.name}'`
150
+ )
151
+ }
152
+
153
+ if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}Entities,`) < 0) {
154
+ allIdxFileTxt = allIdxFileTxt.replace(
155
+ /\/\* ENTITIES \*\//,
156
+ `/* ENTITIES */\n\t...${nameMap.pascalCaseName}Entities,`
157
+ )
158
+ }
159
+
160
+ if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}Resolvers,`) < 0) {
161
+ allIdxFileTxt = allIdxFileTxt.replace(
162
+ /\/\* RESOLVER CLASSES \*\//,
163
+ `/* RESOLVER CLASSES */\n\t\t...${nameMap.pascalCaseName}Resolvers,`
164
+ )
165
+ }
166
+
167
+ if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}EntitySubscribers,`) < 0) {
168
+ allIdxFileTxt = allIdxFileTxt.replace(
169
+ /\/\* SUBSCRIBERS \*\//,
170
+ `/* SUBSCRIBERS */\n\t\t...${nameMap.pascalCaseName}EntitySubscribers,`
171
+ )
172
+ }
173
+
174
+ await this.writeFile(allServiceIdxPath, allIdxFileTxt, nameMap)
218
175
  }
219
176
 
177
+ async createNoHistoryServiceFiels(
178
+ servicePath: string,
179
+ serviceName: string,
180
+ entity: Entity,
181
+ entityColumns: EntityColumn[],
182
+ nameMap: any
183
+ ) {
184
+ // 서비스 연관 파일 생성
185
+ await this.writeFile(servicePath + `${serviceName}/index.ts`, serviceIndex, nameMap)
186
+
187
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-query.ts`, serviceQuery, nameMap)
188
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-mutation.ts`, serviceMutation, nameMap)
189
+
190
+ // Entity
191
+ let entityText = this.createEntityText(entity, entityColumns)
192
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}.ts`, entityText, nameMap)
193
+
194
+ // TYPE
195
+ let typeText = this.createTypeText(entityColumns)
196
+ await this.writeFile(servicePath + `${serviceName}/${serviceName}-type.ts`, typeText, nameMap)
197
+
198
+ // 전체 서비스 index.ts 파일
199
+ let allServiceIdxPath = servicePath + 'index.ts'
200
+ if ((await this.existsPath(allServiceIdxPath)) == false) {
201
+ await this.writeFile(allServiceIdxPath, allIndex, nameMap)
202
+ }
203
+
204
+ let allIdxFileTxt = await fs.readFileSync(allServiceIdxPath, 'utf8')
205
+
206
+ if (allIdxFileTxt.indexOf(`export * from './${nameMap.name}/${nameMap.name}'`) < 0) {
207
+ allIdxFileTxt = allIdxFileTxt.replace(
208
+ /\/\* EXPORT ENTITY TYPES \*\//,
209
+ `/* EXPORT ENTITY TYPES */\nexport * from './${nameMap.name}/${nameMap.name}'`
210
+ )
211
+ }
212
+
213
+ if (
214
+ allIdxFileTxt.indexOf(
215
+ `import { entities as ${nameMap.pascalCaseName}Entities, resolvers as ${nameMap.pascalCaseName}Resolvers } from './${nameMap.name}'`
216
+ ) < 0
217
+ ) {
218
+ allIdxFileTxt = allIdxFileTxt.replace(
219
+ /\/\* IMPORT ENTITIES AND RESOLVERS \*\//,
220
+ `/* IMPORT ENTITIES AND RESOLVERS */\nimport { entities as ${nameMap.pascalCaseName}Entities, resolvers as ${nameMap.pascalCaseName}Resolvers } from './${nameMap.name}'`
221
+ )
222
+ }
223
+
224
+ if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}Entities,`) < 0) {
225
+ allIdxFileTxt = allIdxFileTxt.replace(
226
+ /\/\* ENTITIES \*\//,
227
+ `/* ENTITIES */\n\t...${nameMap.pascalCaseName}Entities,`
228
+ )
229
+ }
230
+
231
+ if (allIdxFileTxt.indexOf(`...${nameMap.pascalCaseName}Resolvers,`) < 0) {
232
+ allIdxFileTxt = allIdxFileTxt.replace(
233
+ /\/\* RESOLVER CLASSES \*\//,
234
+ `/* RESOLVER CLASSES */\n\t\t...${nameMap.pascalCaseName}Resolvers,`
235
+ )
236
+ }
237
+
238
+ await this.writeFile(allServiceIdxPath, allIdxFileTxt, nameMap)
239
+ }
220
240
 
221
241
  /**
222
- * 엔티티 타입 텍스트
223
- * @param entityColumns
224
- * @returns
242
+ * 엔티티 타입 텍스트
243
+ * @param entityColumns
244
+ * @returns
225
245
  */
226
246
  createTypeText(entityColumns: EntityColumn[]) {
227
- let typeText = sereviceType;
247
+ let typeText = sereviceType
228
248
 
229
249
  let newTypeColumns = entityColumns.map(column => {
230
- if (column.name == 'id') return '';
231
- if (column.name == 'domain_id') return '';
232
- if (column.name == 'created_at') return '';
233
- if (column.name == 'updated_at') return '';
234
- if (column.name == 'creator_id') return '';
235
- if (column.name == 'updater_id') return '';
236
-
237
- let fieldType: string = this.getFieldType(column);
238
- let colTxtType: string = this.getColTxtType(column);
239
-
240
- let colName = camelCase(column.name);
241
- let fieldAnn = `@Field(${fieldType.length == 0 ? '' : 'type =>' + fieldType + ','} { nullable: ${column.nullable} })`;
250
+ if (column.name == 'id') return ''
251
+ if (column.name == 'domain_id') return ''
252
+ if (column.name == 'created_at') return ''
253
+ if (column.name == 'updated_at') return ''
254
+ if (column.name == 'creator_id') return ''
255
+ if (column.name == 'updater_id') return ''
256
+
257
+ let fieldType: string = this.getFieldType(column)
258
+ let colTxtType: string = this.getColTxtType(column)
259
+
260
+ let colName = camelCase(column.name)
261
+ let fieldAnn = `@Field(${fieldType.length == 0 ? '' : 'type =>' + fieldType + ','} { nullable: ${column.nullable} })`
242
262
  let columnTxt = `${colName}${column.nullable ? '?' : ''}: ${colTxtType}`
243
263
 
244
- return " " + fieldAnn + "\n " + columnTxt + "\n";
264
+ return ' ' + fieldAnn + '\n ' + columnTxt + '\n'
245
265
  })
246
266
 
247
- typeText = typeText.replace(/{{newTypeColumns}}/g, newTypeColumns.join("\n"));
267
+ typeText = typeText.replace(/{{newTypeColumns}}/g, newTypeColumns.join('\n'))
248
268
 
249
269
  let patchTypeColumns = entityColumns.map(column => {
250
- if (column.name == 'id') return '';
251
- if (column.name == 'domain_id') return '';
252
- if (column.name == 'created_at') return '';
253
- if (column.name == 'updated_at') return '';
254
- if (column.name == 'creator_id') return '';
255
- if (column.name == 'updater_id') return '';
270
+ if (column.name == 'id') return ''
271
+ if (column.name == 'domain_id') return ''
272
+ if (column.name == 'created_at') return ''
273
+ if (column.name == 'updated_at') return ''
274
+ if (column.name == 'creator_id') return ''
275
+ if (column.name == 'updater_id') return ''
256
276
 
257
- let fieldType: string = this.getFieldType(column);
258
- let colTxtType: string = this.getColTxtType(column);
277
+ let fieldType: string = this.getFieldType(column)
278
+ let colTxtType: string = this.getColTxtType(column)
259
279
 
260
280
  // patch ?
261
- column.nullable = true;
281
+ column.nullable = true
262
282
 
263
- let colName = camelCase(column.name);
264
- let fieldAnn = `@Field(${fieldType.length == 0 ? '' : 'type =>' + fieldType + ','} { nullable: ${column.nullable} })`;
283
+ let colName = camelCase(column.name)
284
+ let fieldAnn = `@Field(${fieldType.length == 0 ? '' : 'type =>' + fieldType + ','} { nullable: ${column.nullable} })`
265
285
  let columnTxt = `${colName}${column.nullable ? '?' : ''}: ${colTxtType}`
266
286
 
267
- return " " + fieldAnn + "\n " + columnTxt + "\n";
287
+ return ' ' + fieldAnn + '\n ' + columnTxt + '\n'
268
288
  })
269
289
 
270
- typeText = typeText.replace(/{{patchTypeColumns}}/g, patchTypeColumns.join("\n"));
290
+ typeText = typeText.replace(/{{patchTypeColumns}}/g, patchTypeColumns.join('\n'))
271
291
 
272
- return typeText;
292
+ return typeText
273
293
  }
274
294
 
275
295
  /**
276
- * 엔티티 생성 텍스트
277
- * @param entity
278
- * @param entityColumns
279
- * @returns
296
+ * 엔티티 생성 텍스트
297
+ * @param entity
298
+ * @param entityColumns
299
+ * @returns
280
300
  */
281
301
  createEntityText(entity: Entity, entityColumns: EntityColumn[]) {
282
- let entityText = serviceEntity;
302
+ let entityText = serviceEntity
283
303
 
284
304
  // 컬럼 정렬
285
305
  let sortedCols: EntityColumn[] = entityColumns.sort(function (a, b) {
286
- return a.rank - b.rank;
306
+ return a.rank - b.rank
287
307
  })
288
308
 
289
- // 컬럼 정보 txt 변환
309
+ // 컬럼 정보 txt 변환
290
310
  let entityColsText: string[] = sortedCols.map(x => {
291
- return this.columnToEntityColumn(x);
311
+ return this.columnToEntityColumn(x)
292
312
  })
293
313
 
294
- if(['COPY','JSON'].includes(entity.dataProp)){
314
+ if (['COPY', 'JSON'].includes(entity.dataProp)) {
295
315
  entityColsText.push(`
296
316
  @VersionColumn({ default: 1 })
297
317
  @Field({ nullable: true })
298
318
  dataRevisionNo?: number = 1`)
299
319
  }
300
320
 
301
- entityText = entityText.replace(/{{entityColumns}}/g, entityColsText.join("\n"));
321
+ entityText = entityText.replace(/{{entityColumns}}/g, entityColsText.join('\n'))
302
322
 
303
323
  // index 정보
304
- let indexAnn = ``;
305
- let sortedIdxCols: EntityColumn[] = entityColumns.filter(x => x.uniqRank && x.uniqRank > 0).sort(function (a, b) {
306
- return a.uniqRank - b.uniqRank;
307
- })
324
+ let indexAnn = ``
325
+ let sortedIdxCols: EntityColumn[] = entityColumns
326
+ .filter(x => x.uniqRank && x.uniqRank > 0)
327
+ .sort(function (a, b) {
328
+ return a.uniqRank - b.uniqRank
329
+ })
308
330
 
309
331
  if (sortedIdxCols.length > 0) {
310
- indexAnn = `@Index('ix_{{snakeCase name}}_0', ({{camelCase name}}: {{pascalCase name}}) => [{{indexColumns}}], { unique: true })`;
332
+ indexAnn = `@Index('ix_{{snakeCase name}}_0', ({{camelCase name}}: {{pascalCase name}}) => [{{indexColumns}}], { unique: true })`
311
333
 
312
334
  let idxColumns = sortedIdxCols.map(x => {
313
- let colName = x.name;
314
- if (x.name == 'domain_id') colName = 'domain';
315
- if (x.name == 'creator_id') colName = 'creator';
316
- if (x.name == 'updater_id') colName = 'updater';
317
-
335
+ let colName = x.name
336
+ if (x.name == 'domain_id') colName = 'domain'
337
+ if (x.name == 'creator_id') colName = 'creator'
338
+ if (x.name == 'updater_id') colName = 'updater'
318
339
 
319
- return '{{camelCase name}}.' + camelCase(colName);
340
+ return '{{camelCase name}}.' + camelCase(colName)
320
341
  })
321
342
 
322
- indexAnn = indexAnn.replace(/{{indexColumns}}/g, idxColumns.join(","));
343
+ indexAnn = indexAnn.replace(/{{indexColumns}}/g, idxColumns.join(','))
323
344
  }
324
- entityText = entityText.replace(/{{indexAnn}}/g, indexAnn);
345
+ entityText = entityText.replace(/{{indexAnn}}/g, indexAnn)
325
346
 
326
- return entityText;
347
+ return entityText
327
348
  }
328
349
 
329
350
  /**
330
- * 이력관리 엔티티 생성 텍스트
331
- * @param entity
332
- * @param entityColumns
333
- * @returns
351
+ * 이력관리 엔티티 생성 텍스트
352
+ * @param entity
353
+ * @param entityColumns
354
+ * @returns
334
355
  */
335
356
  createHistoryEntityText(entity: Entity, entityColumns: EntityColumn[]) {
336
- let entityText = entity.dataProp == 'JSON' ? serviceEntityHistJson : serviceEntityHistCopy;
357
+ let entityText = entity.dataProp == 'JSON' ? serviceEntityHistJson : serviceEntityHistCopy
337
358
 
338
359
  // 컬럼 정렬
339
360
  let sortedCols: EntityColumn[] = entityColumns.sort(function (a, b) {
340
- return a.rank - b.rank;
361
+ return a.rank - b.rank
341
362
  })
342
363
 
343
- // 컬럼 정보 txt 변환
364
+ // 컬럼 정보 txt 변환
344
365
  let entityColsText: string[] = sortedCols.map(x => {
345
- return this.columnToEntityColumn(x);
366
+ return this.columnToEntityColumn(x)
346
367
  })
347
368
 
348
- entityText = entityText.replace(/{{entityColumns}}/g, entityColsText.join("\n"));
349
- return entityText;
369
+ entityText = entityText.replace(/{{entityColumns}}/g, entityColsText.join('\n'))
370
+ return entityText
350
371
  }
351
372
 
352
-
353
-
354
373
  /**
355
- * EntityColumn to entity column Text
356
- * @param column
357
- * @returns
374
+ * EntityColumn to entity column Text
375
+ * @param column
376
+ * @returns
358
377
  */
359
378
  columnToEntityColumn(column: EntityColumn) {
360
- if (column.name == 'id') return '';
361
- if (column.name == 'domain_id') return '';
362
- if (column.name == 'created_at') return '';
363
- if (column.name == 'updated_at') return '';
364
- if (column.name == 'creator_id') return '';
365
- if (column.name == 'updater_id') return '';
366
-
367
-
368
- let colType: string = column.colType;
369
- if (column.colType == 'double') colType = 'double precision';
370
- if (column.colType == 'long') colType = 'bigint';
371
- if (column.colType == 'string') colType = 'character varying';
372
- if (column.colType == 'datetime') colType = 'timestamp without time zone';
373
-
374
- let colSize: string = '';
375
- if (column.colType == 'string') colSize = column.colSize;
379
+ if (column.name == 'id') return ''
380
+ if (column.name == 'domain_id') return ''
381
+ if (column.name == 'created_at') return ''
382
+ if (column.name == 'updated_at') return ''
383
+ if (column.name == 'creator_id') return ''
384
+ if (column.name == 'updater_id') return ''
385
+
386
+ let colType: string = column.colType
387
+ if (column.colType == 'double') colType = 'double precision'
388
+ if (column.colType == 'long') colType = 'bigint'
389
+ if (column.colType == 'string') colType = 'character varying'
390
+ if (column.colType == 'datetime') colType = 'timestamp without time zone'
391
+
392
+ let colSize: string = ''
393
+ if (column.colType == 'string') {
394
+ //@ts-ignore
395
+ colSize = column.colSize
396
+ }
376
397
 
377
- let fieldType: string = this.getFieldType(column);
378
- let colTxtType: string = this.getColTxtType(column);
398
+ let fieldType: string = this.getFieldType(column)
399
+ let colTxtType: string = this.getColTxtType(column)
379
400
 
380
- let colName = camelCase(column.name);
401
+ let colName = camelCase(column.name)
381
402
 
382
- let columnAnn = `@Column({name:'${column.name}', type: '${colType}', nullable: ${column.nullable} ${colSize.length == 0 ? '' : ',length:' + colSize} })`;
383
- let fieldAnn = `@Field(${fieldType.length == 0 ? '' : 'type =>' + fieldType + ','} { nullable: ${column.nullable} })`;
403
+ let columnAnn = `@Column({name:'${column.name}', type: '${colType}', nullable: ${column.nullable} ${colSize.length == 0 ? '' : ',length:' + colSize} })`
404
+ let fieldAnn = `@Field(${fieldType.length == 0 ? '' : 'type =>' + fieldType + ','} { nullable: ${column.nullable} })`
384
405
  let columnTxt = `${colName}${column.nullable ? '?' : ''}: ${colTxtType}`
385
406
 
386
- return " " + columnAnn + "\n " + fieldAnn + "\n " + columnTxt + "\n";
407
+ return ' ' + columnAnn + '\n ' + fieldAnn + '\n ' + columnTxt + '\n'
387
408
  }
388
409
 
389
410
  getFieldType(column: EntityColumn) {
390
- let fieldType: string = '';
411
+ let fieldType: string = ''
391
412
 
392
- if (column.colType == 'double') fieldType = 'Float';
393
- if (column.colType == 'float') fieldType = 'Float';
394
- if (column.colType == 'long') fieldType = 'Int';
395
- if (column.colType == 'integer') fieldType = 'Int';
413
+ if (column.colType == 'double') fieldType = 'Float'
414
+ if (column.colType == 'float') fieldType = 'Float'
415
+ if (column.colType == 'long') fieldType = 'Int'
416
+ if (column.colType == 'integer') fieldType = 'Int'
396
417
 
397
- return fieldType;
418
+ return fieldType
398
419
  }
399
420
 
400
421
  getColTxtType(column: EntityColumn) {
401
- let colTxtType: string = column.colType;
402
- if (column.colType == 'decimal') colTxtType = 'number';
403
- if (column.colType == 'double') colTxtType = 'number';
404
- if (column.colType == 'float') colTxtType = 'number';
405
- if (column.colType == 'integer') colTxtType = 'number';
406
- if (column.colType == 'long') colTxtType = 'number';
407
- if (column.colType == 'datetime') colTxtType = 'Date';
408
- if (column.colType == 'date') colTxtType = 'Date';
409
- if (column.colType == 'text') colTxtType = 'string';
410
- return colTxtType;
422
+ let colTxtType: string = column.colType
423
+ if (column.colType == 'decimal') colTxtType = 'number'
424
+ if (column.colType == 'double') colTxtType = 'number'
425
+ if (column.colType == 'float') colTxtType = 'number'
426
+ if (column.colType == 'integer') colTxtType = 'number'
427
+ if (column.colType == 'long') colTxtType = 'number'
428
+ if (column.colType == 'datetime') colTxtType = 'Date'
429
+ if (column.colType == 'date') colTxtType = 'Date'
430
+ if (column.colType == 'text') colTxtType = 'string'
431
+ return colTxtType
411
432
  }
412
433
 
413
434
  /**
414
- * 파일 생성
415
- * @param filePath
416
- * @param fileText
417
- * @param nameMap
435
+ * 파일 생성
436
+ * @param filePath
437
+ * @param fileText
438
+ * @param nameMap
418
439
  */
419
440
  async writeFile(filePath: string, fileText: string, nameMap: any) {
420
- await fs.writeFileSync(filePath, this.replaceNamesMap(fileText, nameMap), 'utf8');
441
+ await fs.writeFileSync(filePath, this.replaceNamesMap(fileText, nameMap), 'utf8')
421
442
  }
422
443
 
423
444
  /**
424
- * 문자열 치환
425
- * @param text
426
- * @param nameMap
427
- * @returns
445
+ * 문자열 치환
446
+ * @param text
447
+ * @param nameMap
448
+ * @returns
428
449
  */
429
450
  replaceNamesMap(text: string, nameMap: any) {
430
- return text.replace(/{{pascalCase name}}/g, nameMap.pascalCaseName)
451
+ return text
452
+ .replace(/{{pascalCase name}}/g, nameMap.pascalCaseName)
431
453
  .replace(/{{camelCase name}}/g, nameMap.camelCaseName)
432
454
  .replace(/{{snakeCase name}}/g, nameMap.snakeCaseName)
433
455
  .replace(/{{pluralPascalCase name}}/g, nameMap.pluralPascalCaseName)
434
456
  .replace(/{{pluralCamelCase name}}/g, nameMap.pluralCamelCaseName)
435
457
  .replace(/{{tableName}}/g, nameMap.tableName)
436
- .replace(/{{name}}/g, nameMap.name);
458
+ .replace(/{{name}}/g, nameMap.name)
437
459
  }
438
460
 
439
461
  /**
440
- * 서비스 경로 만들기
441
- * @param appRootPath
442
- * @param moduleName
443
- * @param serviceName
462
+ * 서비스 경로 만들기
463
+ * @param appRootPath
464
+ * @param moduleName
465
+ * @param serviceName
444
466
  */
445
467
  async createServicePath(appRootPath: string, moduleName: string, serviceName: string) {
446
- let path: string = appRootPath + '/' + 'packages';
447
- await this.createDir(path);
468
+ let path: string = appRootPath + '/' + 'packages'
469
+ await this.createDir(path)
448
470
 
449
- path = path + '/' + moduleName;
450
- await this.createDir(path);
471
+ path = path + '/' + moduleName
472
+ await this.createDir(path)
451
473
 
452
- path = path + '/server';
453
- await this.createDir(path);
474
+ path = path + '/server'
475
+ await this.createDir(path)
454
476
 
455
- path = path + '/service';
456
- await this.createDir(path);
477
+ path = path + '/service'
478
+ await this.createDir(path)
457
479
 
458
- path = path + '/' + serviceName;
459
- await this.createDir(path);
480
+ path = path + '/' + serviceName
481
+ await this.createDir(path)
460
482
  }
461
483
 
462
484
  /**
463
- * 프로젝트 Root Path 구하기
485
+ * 프로젝트 Root Path 구하기
464
486
  * @returns String
465
487
  */
466
488
  getProjectRootPath() {
467
- let appPath: string = process.env.PWD;
468
- let splitPath: string[] = appPath.split('/');
469
- let pathArr: string[] = [];
489
+ let appPath: string = process.env.PWD
490
+ let splitPath: string[] = appPath.split('/')
491
+ let pathArr: string[] = []
470
492
  for (let i = 0; i < splitPath.length; i++) {
471
493
  if (splitPath[i] == 'packages') {
472
- break;
494
+ break
473
495
  }
474
496
 
475
- pathArr.push(splitPath[i]);
497
+ pathArr.push(splitPath[i])
476
498
  }
477
499
 
478
- return pathArr.join('/');
500
+ return pathArr.join('/')
479
501
  }
480
502
 
481
503
  /**
482
- * 디렉토리 생성
483
- * @param path
504
+ * 디렉토리 생성
505
+ * @param path
484
506
  */
485
507
  async createDir(path: string) {
486
- if (await this.existsPath(path) == false) fs.mkdirSync(path);
508
+ if ((await this.existsPath(path)) == false) fs.mkdirSync(path)
487
509
  }
488
510
 
489
511
  /**
490
- * Path 존재 여부
491
- * @param path
492
- * @returns
512
+ * Path 존재 여부
513
+ * @param path
514
+ * @returns
493
515
  */
494
516
  async existsPath(path: string) {
495
- return await fs.existsSync(path);
517
+ return await fs.existsSync(path)
496
518
  }
497
519
  }
498
520