tnx-shared 5.2.7 → 5.2.10

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.
@@ -804,11 +804,19 @@ function getCurrentVersion(pkgObj, packageName, onGetVersion,) {
804
804
  }, function (error, response, body) {
805
805
  let versionStr;
806
806
  if (body) {
807
+ // nếu gọi api thành công
807
808
  const bodyObj = JSON.parse(body).versions;
808
- const pkgVersions = Object.keys(bodyObj).filter(x => x.startsWith(angularSchemaObj.projectList[packageNameWithoutPrefix].clientVersion));
809
- versionStr = pkgVersions[pkgVersions.length - 1];
809
+ if (bodyObj) {
810
+ // nếu đã từng publish ít nhất 1 version
811
+ const pkgVersions = Object.keys(bodyObj).filter(x => x.startsWith(angularSchemaObj.projectList[packageNameWithoutPrefix].clientVersion));
812
+ versionStr = pkgVersions[pkgVersions.length - 1];
813
+ } else {
814
+ // lấy version đầu tiên
815
+ versionStr = `${angularSchemaObj.projectList[packageNameWithoutPrefix].clientVersion}.0`;
816
+ }
810
817
  }
811
818
  else {
819
+ // không gọi được api, dùng tạm version của local
812
820
  console.warn('cannot get latest version, get from local instead', body);
813
821
  versionStr = pkgObj.version;
814
822
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tnx-shared",
3
- "version": "5.2.7",
3
+ "version": "5.2.10",
4
4
  "clientVersion": "5.2",
5
5
  "version5.0": "5.0.19",
6
6
  "version5.1": "5.1.22",
@@ -131,7 +131,7 @@
131
131
  "jsplumb": "^2.15.6",
132
132
  "ngx-extended-pdf-viewer": "^9.0.5"
133
133
  },
134
- "versionPrev": "5.2.6",
134
+ "versionPrev": "5.2.9",
135
135
  "main": "bundles/tnx-shared.umd.js",
136
136
  "module": "fesm2015/tnx-shared.js",
137
137
  "es2015": "fesm2015/tnx-shared.js",
@@ -1,5 +0,0 @@
1
- FROM euniversitytnapi/tn.clientbase.angular
2
- ARG app_name_lower_case
3
- RUN rm -rf /usr/share/nginx/html/*
4
- COPY ./dist/${app_name_lower_case} /usr/share/nginx/html
5
- CMD ["nginx", "-g", "daemon off;"]
@@ -1,42 +0,0 @@
1
- #!/bin/bash
2
-
3
- while [ "$1" != "" ]; do
4
- case $1 in
5
- -a | --appname)
6
- shift
7
- appname=$1
8
- ;;
9
- -e | --environment)
10
- shift
11
- env=${1/\//-} # Replace dấu / thành - để đánh tag name không bị lỗi. ví dụ feature/feature-1 -> feature-feature-1
12
- ;;
13
- -scope | --scope)
14
- shift
15
- scope=$1
16
- ;;
17
- -imageSuffix | --image-suffix)
18
- shift
19
- suffix=$1
20
- ;;
21
- -tagOnly | --tag-only)
22
- shift
23
- tagonly=$1
24
- ;;
25
- -fromEnvironment | --from-environment)
26
- shift
27
- fromenv=$1
28
- ;;
29
- esac
30
- shift
31
- done
32
-
33
- docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PASS $DOCKER_REGISTRY_SERVER
34
- if ! ($tagonly); then
35
- docker build --build-arg app_name_lower_case=${appname,,} -f Dockerfile.ci -t $DOCKER_REGISTRY_SERVER/$scope/${appname,,}$suffix:$CORE_VERSION-$env .
36
- docker push $DOCKER_REGISTRY_SERVER/$scope/${appname,,}$suffix:$CORE_VERSION-$env
37
- docker tag $DOCKER_REGISTRY_SERVER/$scope/${appname,,}$suffix:$CORE_VERSION-$env $DOCKER_REGISTRY_SERVER/$scope/${appname,,}$suffix:$CORE_VERSION-$env-$IMAGE_VERSION
38
- docker push $DOCKER_REGISTRY_SERVER/$scope/${appname,,}$suffix:$CORE_VERSION-$env-$IMAGE_VERSION
39
- else
40
- docker tag $DOCKER_REGISTRY_SERVER/$scope/${appname,,}$suffix:$CORE_VERSION-$fromenv $DOCKER_REGISTRY_SERVER/$scope/${appname,,}$suffix:$CORE_VERSION-$env-$IMAGE_VERSION
41
- docker push $DOCKER_REGISTRY_SERVER/$scope/${appname,,}$suffix:$CORE_VERSION-$env-$IMAGE_VERSION
42
- fi
@@ -1,703 +0,0 @@
1
- const { task, src, dest, series } = require("gulp");
2
- const rename = require('gulp-rename');
3
- const through = require("through2");
4
- const fs = require('fs');
5
- const argv = require('yargs').argv;
6
- var del = require('del');
7
- const readlineSync = require('readline-sync');
8
- const ci = argv.ci;
9
- const personalEnvironmentName = argv.env;
10
- const resetFlag = argv.resetFlag;
11
- const projectRefDirect = argv.projectRefDirect;
12
- if (!personalEnvironmentName && !ci && !resetFlag) {
13
- console.error('Generated đã bị huỷ, vui lòng chạy generate theo 1 profile cá nhân của bạn, ví dụ npm run generate-all-namnh (namnh là profile cá nhân)');
14
- console.error('------------------------------------------------------------------------------------------------------------------------------------');
15
- return;
16
- }
17
-
18
- const rootProjectPath = '../../../';
19
-
20
- const pathAngularSchema = rootProjectPath + 'angular-schema.json';
21
- const pathGitIgnoreFile = rootProjectPath + '/projects/.gitignore';
22
- const pathAngularSchemaTemplate = 'angular-schema-template.json';
23
- let contentPathShared = `../../commonworkspacev5/App/shared`;
24
- const packageJsonTemplate = 'package.json.tmp';
25
-
26
- let pathShared = rootProjectPath + contentPathShared;
27
- if (ci) {
28
- pathShared = rootProjectPath + `commonworkspacev5/App/shared`;
29
- contentPathShared = `commonworkspacev5/App/shared`;
30
- }
31
- const pathSharedAssets = pathShared + '/shared-assets';
32
- const pathSharedEnvironment = pathShared + '/environments';
33
- const pathBuildConfig = pathShared + '/build-config';
34
- const pathtTsConfig = pathShared;
35
- const pathPackageJson = rootProjectPath + "package.json";
36
-
37
- let angularSchemaObj = {};
38
- let angularSchemaTemplateObj = {};
39
-
40
- String.prototype.replaceAll = function (target, replacement) {
41
- return this.split(target).join(replacement);
42
- };
43
-
44
- task("generateEnvironmentJsonFile", async function () {
45
- const listEnvironment = angularSchemaObj.environments;
46
- // generate application.json file
47
- generateApplicationJsonFile();
48
-
49
- for (const [env, envSetting] of Object.entries(listEnvironment)) {
50
- if (env != personalEnvironmentName) continue;
51
- generateEnvironmentJsonFile(env);
52
- }
53
- })
54
-
55
- task("generateEnvironmentTsFile", async function () {
56
- const listEnvironment = angularSchemaObj.environments;
57
- for (const [env, envSetting] of Object.entries(listEnvironment)) {
58
- if (env != personalEnvironmentName) continue;
59
- if (env == 'prod') continue;
60
- generateEnvironmentTsFile(env);
61
- }
62
- })
63
-
64
- task("generateDockerBuildConfig", async function () {
65
- Object.keys(angularSchemaObj.projectList).filter(x => angularSchemaObj.projectList[x].projectType == 'application').forEach(project => {
66
- const replaceKey = { projectName: project };
67
- copyDockerBuild('nginx.conf', project, replaceKey);
68
- copyDockerBuild('Dockerfile', project, replaceKey);
69
- copyDockerBuild('.dockerignore', project, {});
70
- });
71
- });
72
-
73
- task("updateTsConfigJson", async function () {
74
- copyTsConfig();
75
- });
76
-
77
- task("generateAngularJson", function () {
78
- return modifyFile(pathAngularSchema, rootProjectPath, (content) => {
79
- const parsed = JSON.parse(content);
80
- angularSchemaObj = getAngularSchemaData(parsed);
81
- // transform json into desired shape
82
- const transformed = transformAngularJson(parsed);
83
- // make string from javascript obj
84
- return JSON.stringify(transformed, null, 2);
85
- }, "angular.json");
86
- });
87
-
88
- task("loadAngularSchemaTemplate", function () {
89
- return readFile(pathAngularSchemaTemplate, (content) => {
90
- angularSchemaTemplateObj = cloneObject(content);
91
- return true;
92
- });
93
- });
94
-
95
- task("updatePackageJson", function () {
96
- return modifyFile(pathPackageJson, rootProjectPath, (content) => {
97
- const parsed = JSON.parse(content);
98
- // transform json into desired shape
99
- const transformed = transformPackageJson(angularSchemaObj, angularSchemaTemplateObj, parsed);
100
- // make string from javascript obj
101
- return JSON.stringify(transformed, null, 2);
102
- });
103
- });
104
-
105
- task("confirmCopyProjectToRefDirect", function (done) {
106
- if (readlineSync.keyInYN(`Ban co chac chan muon copy "${projectRefDirect}" project sang de ref truc tiep? Luu y neu da ton tai san project "${projectRefDirect}" ben nay thi co nguy co bi mat code. Neu ban da chac chan thi nhan Y`)) {
107
- return done();
108
- }
109
- console.log('huy copy');
110
- process.exit(1);
111
- });
112
-
113
- task('copyProjectToRefDirect', function () {
114
- const projectList = getProjectList();
115
- if (!projectList) {
116
- console.error(`khong ton tai project ${projectRefDirect} trong projectList tai angular-schema.json`);
117
- }
118
- const projectInfo = projectList[projectRefDirect];
119
- if (!projectInfo) {
120
- console.error(`khong ton tai project ${projectRefDirect} trong projectList tai angular-schema.json`);
121
- }
122
- addProjectToGitIgnore(projectRefDirect);
123
- return src(`${rootProjectPath}${projectInfo.refPath}/**/*`).pipe(dest(`${rootProjectPath}projects/${projectRefDirect}`));
124
- });
125
-
126
- task("confirmUpdateProjectRefDirectToOriginalProject", function (done) {
127
- if (readlineSync.keyInYN(`Ban co chac chan muon update project "${projectRefDirect}" dang ref direct ve thu muc goc? Luu y viec copy nay se overwrite toan bo code o thu muc goc cua project ${projectRefDirect}. Nhan Y de dong y.`)) {
128
- return done();
129
- }
130
- console.log('huy update');
131
- process.exit(1);
132
- });
133
-
134
- task("updateProjectRefDirectToOriginalProject", function () {
135
- const projectList = getProjectList();
136
- if (!projectList) {
137
- console.error(`khong ton tai project ${projectRefDirect} trong projectList tai angular-schema.json`);
138
- }
139
- const projectInfo = projectList[projectRefDirect];
140
- if (!projectInfo) {
141
- console.error(`khong ton tai project ${projectRefDirect} trong projectList tai angular-schema.json`);
142
- }
143
- return src(`${rootProjectPath}projects/${projectRefDirect}/**/*`).pipe(dest(`${rootProjectPath}${projectInfo.refPath}`));
144
- });
145
-
146
- task("reset", function (cb) {
147
- // reset script package.json
148
- resetPackageJson();
149
- // delete tsconfig.json
150
- removeTsConfigJson();
151
- // delete angular.json
152
- removeAngularJson();
153
- cb();
154
- });
155
-
156
- task("onInitDone", function (cb) {
157
- console.log('Tiep theo can chay them script npm run generate-all-<ten profile cau ban>');
158
- cb();
159
- });
160
-
161
- function resetPackageJson() {
162
- modifyFile(packageJsonTemplate, rootProjectPath, null, 'package.json');
163
- }
164
-
165
- function removeTsConfigJson() {
166
- del([`${rootProjectPath}tsconfig.json`], { force: true });
167
- }
168
-
169
- function removeAngularJson() {
170
- del([`${rootProjectPath}angular.json`], { force: true });
171
- }
172
-
173
- /**
174
- * Sửa và copy file sang thư mục mới
175
- * @param {Sửa nội dung từ file} sourceFile
176
- * @param {Thư mục chứa file có nội dung mới} targetDir
177
- * @param {Hàm sửa nội dung file} procressFileContent
178
- * @param {Tên file mới (nếu không khai báo thì lấy giống tên sourceFile)} targetFileName
179
- * @returns promise
180
- */
181
- function modifyFile(sourceFile, targetDir, procressFileContent, targetFileName) {
182
- let t = src(sourceFile)
183
- .pipe(
184
- through.obj((file, enc, cb) => {
185
- // get content of json file
186
- const rawContent = file.contents.toString();
187
- if (procressFileContent) {
188
- const content = procressFileContent(rawContent);
189
- if (content) {
190
- file.contents = Buffer.from(content);
191
- } else {
192
- console.warn(`content file ${sourceFile} after process is null`);
193
- }
194
- }
195
- cb(null, file);
196
- })
197
- );
198
- if (targetFileName) {
199
- // đổi tên file sau khi sửa nội dung
200
- t = t.pipe(rename(targetFileName));
201
- }
202
- t = t.pipe(dest(targetDir));
203
- return t;
204
- }
205
-
206
- function readFile(sourceFile, readContent) {
207
- return src(sourceFile).pipe(
208
- through.obj((file, enc, cb) => {
209
- // get content of json file
210
- const rawContent = file.contents.toString();
211
- readContent(rawContent);
212
- cb(null, file);
213
- })
214
- )
215
- }
216
-
217
- task("init", series("loadAngularSchemaTemplate", "generateAngularJson", "updatePackageJson", "onInitDone"));
218
- function generateEnvironmentTsFile(environment) {
219
- return modifyFile(`${pathSharedEnvironment}/environment.template.ts`, `${pathSharedEnvironment}/${angularSchemaObj.scopeName}`,
220
- (content) => {
221
- return transformEnvironmentTsAndJsonFile(environment, content);
222
- }, `environment.${environment}.ts`);
223
- }
224
-
225
- function transformEnvironmentTsAndJsonFile(envName, input) {
226
- return input.replaceAll("{{environmentName}}", 'application,' + envName).replaceAll('{{scopeName}}', angularSchemaObj.scopeName);
227
- }
228
-
229
- function generateApplicationJsonFile() {
230
- if (!fs.existsSync(`${pathSharedAssets}/environments/${angularSchemaObj.scopeName}/application.json`)) {
231
- return src(`${pathSharedAssets}/environments/application-template.json`)
232
- .pipe(rename(`application.json`))
233
- .pipe(dest(`${pathSharedAssets}/environments/${angularSchemaObj.scopeName}`));
234
- }
235
-
236
- return true;
237
- }
238
-
239
- function generateEnvironmentJsonFile(environment) {
240
- fs.access(`${pathSharedAssets}/environments/${angularSchemaObj.scopeName}/${environment}.json`, (err) => {
241
- if (err) {
242
- return modifyFile(
243
- `${pathSharedAssets}/environments/template.json`,
244
- `${pathSharedAssets}/environments/${angularSchemaObj.scopeName}`,
245
- (content) => {
246
- return transformEnvironmentTsAndJsonFile(environment, content);
247
- },
248
- `${environment}.json`
249
- )
250
- }
251
- });
252
- }
253
-
254
- function copyTsConfig() {
255
- return modifyFile(`${pathtTsConfig}/tsconfig.json`, rootProjectPath, (content) => {
256
- // parse raw json into javscript object
257
- const parsed = JSON.parse(content);
258
- // transform json into desired shape
259
- const transformed = transformTsConfigJson(parsed);
260
- // make string from javascript obj
261
- return JSON.stringify(transformed, null, 2);
262
- });
263
- }
264
-
265
- function copyDockerBuild(fileName, project, replaceList) {
266
- return modifyFile(`${pathBuildConfig}/template/${fileName}`, `${rootProjectPath}./build-config/${project}`,
267
- (content) => {
268
- let op = content;
269
- for (const key in replaceList) {
270
- op = op.replaceAll(`{{${key}}}`, replaceList[key]);
271
- }
272
- return op;
273
- });
274
- }
275
-
276
- function transformTsConfigJson(input) {
277
- const paths = input.compilerOptions.paths;
278
- Object.keys(angularSchemaObj.projectList).filter(x => angularSchemaObj.projectList[x].projectType == 'library').forEach(project => {
279
- buildTsConfigPath(paths, project);
280
- });
281
-
282
- delete paths[`${angularSchemaObj.refPrefix}template`];
283
- delete paths[`${angularSchemaObj.refPrefix}template/*`];
284
- delete paths[`${angularSchemaObj.refPrefix}template-direct`];
285
- delete paths[`${angularSchemaObj.refPrefix}template-direct/*`];
286
- delete paths[`${angularSchemaObj.refPrefix}template-package`];
287
- delete paths[`${angularSchemaObj.refPrefix}template-package/*`];
288
-
289
- return input;
290
- }
291
-
292
- function transformPackageJson(angularSchema, angularSchemaTemplate, input) {
293
- const listEnvironment = angularSchema.environments;
294
- const scopeName = angularSchema.scopeName;
295
- const clientVersion = angularSchema.clientVersion;
296
-
297
- let scriptDependAll = 'npm run depend-tnx-shared';
298
- Object.keys(angularSchema.projectList).filter(x => angularSchema.projectList[x].projectType == 'library').forEach(project => {
299
- const prjList = getProjectList();
300
- const prj = prjList[project];
301
- if (prj.projectType == 'library') {
302
- if (prj.refType != 'package') {
303
- // generate package function only for library
304
- input.scripts[`package-${project}`] = angularSchemaTemplate.scripts[`package-template`]
305
- .replaceAll('{{projectName}}', project);
306
- if (prj.refPath) {
307
- input.scripts[`ref-${project}-${personalEnvironmentName}`] = angularSchemaTemplate.scripts['ref-template']
308
- .replaceAll('{{projectName}}', project)
309
- .replaceAll('{{environmentName}}', personalEnvironmentName);
310
- input.scripts[`ref-update-${project}-${personalEnvironmentName}`] = angularSchemaTemplate.scripts['ref-update-template']
311
- .replaceAll('{{projectName}}', project)
312
- .replaceAll('{{environmentName}}', personalEnvironmentName);
313
- }
314
- } else {
315
- input.scripts[`depend-${project}`] = angularSchemaTemplate.scripts[`depend-template`]
316
- .replaceAll('{{projectName}}', project);
317
- scriptDependAll += ` && npm run depend-${project}`;
318
- }
319
- }
320
- });
321
-
322
- // default install latest version tnx-shared
323
- input.scripts['depend-tnx-shared'] = 'npm install tnx-shared@latest --save';
324
- input.scripts['depend-all'] = scriptDependAll;
325
- input.scripts['prebuild'] = angularSchemaTemplate.scripts[`prebuild-template`];
326
-
327
- // additional dependencies and devDependencies
328
- if (angularSchemaTemplate.dependencies) {
329
- Object.keys(angularSchemaTemplate.dependencies).forEach(item => {
330
- input.dependencies[item] = angularSchemaTemplate.dependencies[item];
331
- });
332
- }
333
-
334
- if (angularSchemaTemplate.devDependencies) {
335
- Object.keys(angularSchemaTemplate.devDependencies).forEach(item => {
336
- input.devDependencies[item] = angularSchemaTemplate.devDependencies[item];
337
- });
338
- }
339
-
340
- for (const [env, envSetting] of Object.entries(listEnvironment)) {
341
- if (personalEnvironmentName != 'init' && env != personalEnvironmentName) continue;
342
- input.scripts[`generate-all-${env}`] = angularSchemaTemplate.scripts[`generate-all-template`]
343
- .replaceAll('{{environmentName}}', env);
344
- }
345
-
346
- Object.keys(angularSchema.projectList).filter(x => angularSchema.projectList[x].projectType == 'application').forEach(project => {
347
- const prj = angularSchema.projectList[project];
348
- const port = prj.port;
349
-
350
- for (const [env, envSetting] of Object.entries(listEnvironment)) {
351
- if (env != personalEnvironmentName) continue;
352
- let additionalParams = '';
353
-
354
- input.scripts[`start-${project}-${env}`] = angularSchemaTemplate.scripts['start-template']
355
- .replaceAll('{{projectName}}', project)
356
- .replaceAll('{{environmentName}}', env)
357
- .replaceAll('{{port}}', port)
358
- .replaceAll('{{additionalParams}}', additionalParams);
359
- input.scripts[`start-quick-${project}-${env}`] = angularSchemaTemplate.scripts['start-quick-template']
360
- .replaceAll('{{projectName}}', project)
361
- .replaceAll('{{environmentName}}', env)
362
- .replaceAll('{{port}}', port)
363
- .replaceAll('{{additionalParams}}', additionalParams);
364
- }
365
-
366
- input.scripts[`deploy-${project}`] = angularSchemaTemplate.scripts['deploy-template']
367
- .replaceAll('{{projectName}}', project)
368
- .replaceAll('{{clientVersion}}', clientVersion)
369
- .replaceAll('{{scopeName}}', scopeName);
370
- input.scripts[`build-${project}-ci`] = angularSchemaTemplate.scripts['build-ci-template']
371
- .replaceAll('{{projectName}}', project);
372
- });
373
-
374
- // add reset all generation
375
- input.scripts[`reset`] = angularSchemaTemplate.scripts['reset-template'];
376
- return input;
377
- }
378
-
379
- function transformAngularJson(input) {
380
- // fix angular.json version = 1
381
- input['version'] = 1;
382
- input['$schema'] = input.schema;
383
- delete input.schema;
384
- const listEnvironment = input.environments;
385
-
386
- Object.keys(input.projectList).forEach(project => {
387
- const projectInfo = input.projectList[project];
388
- const projectType = projectInfo.projectType;
389
- if (!projectType) { console.error(`Project ${project} cần được định nghĩa projectType là application hoặc library`); return false; }
390
- const templateStr = `template-${projectType}`;
391
- // const template = input.projects[templateStr];
392
- const template = angularSchemaTemplateObj.projects[templateStr];
393
- const clonedTemplate = cloneObject(template);
394
- const projectPort = projectInfo.port;
395
-
396
- replaceKey(clonedTemplate, '{{projectName}}', project);
397
-
398
- if (projectType == 'application') {
399
- const build = clonedTemplate.architect.build.configurations;
400
- const buildEnvironmentTemplate = build.environmentTemplate;
401
- const serve = clonedTemplate.architect.serve;
402
- const serveEnvironmentTemplate = serve.configurations.environmentTemplate;
403
-
404
- for (const [env, envSetting] of Object.entries(listEnvironment)) {
405
- if (env != personalEnvironmentName) continue;
406
- const clonedBuildEnvironmentTemplate = cloneObject(buildEnvironmentTemplate);
407
- const clonedServeEnvironmentTemplate = cloneObject(serveEnvironmentTemplate);
408
- clonedBuildEnvironmentTemplate.fileReplacements[0].with =
409
- clonedBuildEnvironmentTemplate.fileReplacements[0].with
410
- .replace('{{environmentName}}', env)
411
- .replace('{{sharedDirectory}}', contentPathShared)
412
- .replace('{{scopeName}}', angularSchemaObj.scopeName);
413
- build[env] = clonedBuildEnvironmentTemplate;
414
- clonedServeEnvironmentTemplate.browserTarget = clonedServeEnvironmentTemplate.browserTarget.replace('{{environmentName}}', env);
415
- clonedServeEnvironmentTemplate.port = +projectPort;
416
- // hmr
417
- clonedServeEnvironmentTemplate.hmr = false; // fix để không bao giờ dùng hmr
418
- if (clonedServeEnvironmentTemplate.hmr == null)
419
- clonedServeEnvironmentTemplate.hmr = true;
420
- // open or not
421
- clonedServeEnvironmentTemplate.open = true; // fix để luôn luôn mở trình duyệt khi debug
422
- if (clonedServeEnvironmentTemplate.open == null)
423
- clonedServeEnvironmentTemplate.open = true;
424
- serve.configurations[env] = clonedServeEnvironmentTemplate;
425
- }
426
-
427
- clonedTemplate.architect.build.options.index = clonedTemplate.architect.build.options.index.replaceAll('{{sharedDirectory}}', contentPathShared);
428
- clonedTemplate.architect.build.options.assets[1].input = clonedTemplate.architect.build.options.assets[1].input.replaceAll('{{sharedDirectory}}', contentPathShared);
429
- const styles = clonedTemplate.architect.build.options.styles;
430
- const scripts = clonedTemplate.architect.build.options.scripts;
431
-
432
- for (let i = 0; i < styles.length; i++) {
433
- styles[i] = styles[i].replaceAll('{{sharedDirectory}}', contentPathShared);
434
- }
435
-
436
- for (let i = 0; i < scripts.length; i++) {
437
- scripts[i] = scripts[i].replaceAll('{{sharedDirectory}}', contentPathShared);
438
- }
439
-
440
- // update share directory
441
- const productionConfiguration = clonedTemplate.architect.build.configurations.production;
442
- for (let i = 0; i < productionConfiguration.fileReplacements.length; i++) {
443
- productionConfiguration.fileReplacements[i].with = productionConfiguration.fileReplacements[i].with.replaceAll('{{sharedDirectory}}', contentPathShared);
444
- }
445
-
446
- delete build.environmentTemplate;
447
- delete serve.configurations.environmentTemplate;
448
- }
449
-
450
- if (!input.projects) {
451
- input.projects = {};
452
- }
453
-
454
- input.projects[project] = clonedTemplate;
455
- });
456
-
457
- delete input.projectList;
458
- delete input.environments;
459
- delete input.projects['template-application'];
460
- delete input.projects['template-library'];
461
- delete input.scopeName;
462
- delete input.clientVersion;
463
- delete input.scripts;
464
- delete input.refPrefix;
465
- delete input.dependencies;
466
- delete input.devDependencies;
467
-
468
- return input;
469
- }
470
-
471
- function cloneObject(obj) {
472
- try {
473
- if (obj === obj.toString()) {
474
- return JSON.parse(obj);
475
- } else {
476
- return JSON.parse(JSON.stringify(obj));
477
- }
478
- } catch (e) {
479
- console.error(e);
480
- }
481
- return null;
482
- }
483
-
484
- function getAngularSchemaData(obj) {
485
- try {
486
- let op = JSON.parse(JSON.stringify(obj));
487
- if (personalEnvironmentName
488
- && op.environments
489
- && op.environments[personalEnvironmentName]
490
- && Object.keys(op.environments[personalEnvironmentName]).length > 0) {
491
- const envData = op.environments[personalEnvironmentName];
492
- op = mergeJSON(op, envData);
493
- }
494
- return op;
495
- } catch (e) {
496
- console.error(e);
497
- }
498
- return null;
499
- }
500
-
501
- function replaceKey(obj, pattern, value) {
502
- for (const [k, v] of Object.entries(obj)) {
503
- if (typeof v !== "object") {
504
- if (obj[k].toString().indexOf(pattern) > -1) {
505
- obj[k] = obj[k].toString().replace(pattern, value);
506
- }
507
- } else {
508
- replaceKey(v, pattern, value);
509
- }
510
- }
511
- }
512
-
513
- function buildTsConfigPath(paths, project) {
514
- const prjList = getProjectList();
515
- const envs = getEnvironments();
516
- const prj = getProjectInfo(project);
517
- const prefix = getRefPrefix();
518
- const isExternal = prj.isExternal;
519
- const refType = prj.refType;
520
- const refPath = prj.refPath;
521
- var pathAlias = project == 'tnx-shared' ? `${prefix}shared` : `${prefix}${project}`;
522
- if (refType != 'package') {
523
- // direct
524
- if (refPath) {
525
- // copy project to current project
526
- // src(`${rootProjectPath}${refPath}`).pipe(dest(`${rootProjectPath}projects`));
527
-
528
- // modify .gitignore file to ignore commit code.
529
- // addProjectToGitIgnore(project);
530
- }
531
-
532
- paths[`${pathAlias}/*`] = [paths[`${prefix}template-direct/*`][0].replaceAll('{{projectName}}', project).replaceAll('{{projectPath}}', '')];
533
- }
534
- }
535
-
536
- function addProjectToGitIgnore(projectName) {
537
- return src(pathGitIgnoreFile)
538
- .pipe(
539
- through.obj((file, enc, cb) => {
540
- // get content of json file
541
- let raw = file.contents.toString();
542
- if (raw.indexOf('/' + projectName) == -1) {
543
- raw += '\r\n/' + projectName;
544
- }
545
- file.contents = Buffer.from(raw);
546
- // pass transformed file into next gulp pipe
547
- cb(null, file);
548
- })
549
- )
550
- .pipe(rename('.gitignore'))
551
- .pipe(dest(rootProjectPath + '/projects'));
552
- }
553
-
554
- function getRefPrefix() {
555
- return angularSchemaObj.refPrefix;
556
- }
557
-
558
- function getProjectInfo(projectName) {
559
- return angularSchemaObj.projectList[projectName];
560
- }
561
-
562
- function getProjectList() {
563
- return angularSchemaObj.projectList;
564
- }
565
-
566
- function getEnvironments() {
567
- return angularSchemaObj.environments;
568
- }
569
-
570
- // Lấy về giá trị theo path ''
571
- function getValueByPath(obj, path) {
572
- if (!path) return null;
573
- const paths = path.split('.');
574
- for (let i = 0; i < paths.length; i++) {
575
- try {
576
- obj = obj[paths[i]];
577
- } catch (err) {
578
- obj = null;
579
- }
580
- }
581
- return obj;
582
- }
583
-
584
- function isObject(obj) {
585
- if (!obj) return false;
586
- var s = JSON.stringify(obj);
587
- if (s && s.startsWith('{'))
588
- return true;
589
- return false;
590
- }
591
-
592
- function isLiteralObject(obj) {
593
- return (obj instanceof Object)
594
- && !isArray(obj)
595
- && !isNumber(obj)
596
- && !isDate(obj)
597
- && !isFunction(obj)
598
- && !isBoolean(obj)
599
- && !isRegular(obj)
600
- && !isString(obj);
601
- }
602
-
603
- function isNumber(obj) {
604
- return obj instanceof Number;
605
- }
606
-
607
- function isDate(obj) {
608
- return obj instanceof Date;
609
- }
610
-
611
- function isFunction(obj) {
612
- return obj instanceof Function;
613
- }
614
-
615
- function isBoolean(obj) {
616
- return obj instanceof Boolean;
617
- }
618
-
619
- function isString(obj) {
620
- return obj instanceof String;
621
- }
622
-
623
- function isRegular(obj) {
624
- return obj instanceof RegExp;
625
- }
626
-
627
- function isArray(obj) {
628
- return obj instanceof Array;
629
- }
630
-
631
- function isSimpleType(obj) {
632
- var t = typeof (obj);
633
- return t == 'number' || t == 'boolean' || t == 'string' || t == 'symbol' || t == 'bigint';
634
- }
635
-
636
- function clone(obj) {
637
- if (obj)
638
- return JSON.parse(JSON.stringify(obj));
639
- return null;
640
- };
641
-
642
- function mergeJSON(target, source) {
643
- if (isArray(source)) {
644
- if (!isArray(target))
645
- target = [];
646
- var i = 0;
647
- for (var item of source) {
648
- if (i < target.length)
649
- target[i] = mergeJSON(target[i], item);
650
- else
651
- target.push(clone(item));
652
- i++;
653
- }
654
- target.length = i;
655
- }
656
- else if (isLiteralObject(source)) {
657
- if (!isLiteralObject(target))
658
- target = {};
659
- else
660
- target = clone(target);
661
-
662
- const keys = Object.keys(source);
663
- if (keys.length > 0) {
664
- keys.forEach(key => {
665
- target[key] = mergeJSON(target[key], source[key]);
666
- });
667
- }
668
- else {
669
- const keys = Object.keys(target);
670
- keys.forEach(key => {
671
- delete target[key];
672
- });
673
- }
674
- }
675
- else {
676
- target = source;
677
- }
678
-
679
- return target;
680
- }
681
-
682
- exports.generateAngularJson = task("generateAngularJson");
683
- exports.loadAngularSchemaTemplate = task('loadAngularSchemaTemplate');
684
- exports.updatePackageJson = task("updatePackageJson");
685
- exports.generateDockerBuildConfig = task("generateDockerBuildConfig");
686
- exports.updateTsConfigJson = task("updateTsConfigJson");
687
- exports.generateEnvironmentJsonFile = task("generateEnvironmentJsonFile");
688
- exports.generateEnvironmentTsFile = task("generateEnvironmentTsFile");
689
-
690
- exports.reset = task("reset");
691
-
692
- exports.init = task("init");
693
- exports.copyRefDirect = series("confirmCopyProjectToRefDirect", series("init", "copyProjectToRefDirect", "updateTsConfigJson"));
694
- exports.updateRefDirect = series('confirmUpdateProjectRefDirectToOriginalProject', series("init", 'updateProjectRefDirectToOriginalProject'));
695
- exports.generateAll = series(
696
- 'loadAngularSchemaTemplate',
697
- 'generateAngularJson',
698
- 'updatePackageJson',
699
- 'generateDockerBuildConfig',
700
- 'updateTsConfigJson',
701
- 'generateEnvironmentJsonFile',
702
- 'generateEnvironmentTsFile'
703
- );