nsgm-cli 2.0.6 → 2.0.7

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 (59) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +161 -161
  3. package/client/layout/index.tsx +248 -245
  4. package/client/redux/reducers.ts +4 -4
  5. package/client/redux/store.ts +50 -50
  6. package/client/redux/template/manage/actions.ts +190 -190
  7. package/client/redux/template/manage/reducers.ts +118 -118
  8. package/client/redux/template/manage/types.ts +24 -24
  9. package/client/service/template/manage.ts +96 -96
  10. package/client/styled/common.ts +30 -26
  11. package/client/styled/layout/index.ts +25 -25
  12. package/client/styled/template/manage.ts +51 -51
  13. package/client/utils/common.ts +89 -86
  14. package/client/utils/cookie.ts +51 -51
  15. package/client/utils/fetch.ts +25 -25
  16. package/client/utils/menu.tsx +27 -27
  17. package/client/utils/sso.ts +205 -0
  18. package/generation/README.md +19 -19
  19. package/generation/app.js +2 -2
  20. package/generation/client/redux/reducers.ts +4 -4
  21. package/generation/client/utils/menu.tsx +27 -27
  22. package/generation/gitignore +4 -4
  23. package/generation/mysql.config.js +12 -13
  24. package/generation/next.config.js +6 -6
  25. package/generation/package.json +21 -26
  26. package/generation/project.config.js +13 -12
  27. package/generation/server/rest.js +23 -20
  28. package/generation/tsconfig.json +30 -30
  29. package/index.js +10 -10
  30. package/lib/args.d.ts +6 -6
  31. package/lib/args.js +53 -53
  32. package/lib/generate.d.ts +3 -3
  33. package/lib/generate.js +751 -736
  34. package/lib/index.d.ts +2 -2
  35. package/lib/index.js +272 -272
  36. package/lib/server/db.d.ts +5 -5
  37. package/lib/server/db.js +110 -110
  38. package/lib/server/graphql.d.ts +7 -7
  39. package/lib/server/graphql.js +119 -119
  40. package/lib/server/plugins/date.d.ts +5 -5
  41. package/lib/server/plugins/date.js +16 -16
  42. package/lib/tsconfig.build.tsbuildinfo +1 -1
  43. package/mysql.config.js +14 -14
  44. package/next-env.d.ts +6 -6
  45. package/next.config.js +2 -2
  46. package/package.json +126 -126
  47. package/pages/_app.tsx +54 -44
  48. package/pages/login.tsx +65 -0
  49. package/pages/template/manage.tsx +278 -278
  50. package/project.config.js +16 -14
  51. package/public/slbhealthcheck.html +9 -9
  52. package/scripts/shutdown.sh +9 -9
  53. package/scripts/startup.sh +34 -34
  54. package/server/apis/sso.js +44 -0
  55. package/server/apis/template.js +17 -17
  56. package/server/modules/template/schema.js +33 -33
  57. package/server/rest.js +24 -20
  58. package/server/sql/template.sql +8 -8
  59. package/generation/.DS_Store +0 -0
package/lib/generate.js CHANGED
@@ -1,736 +1,751 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.deleteFiles = exports.createFiles = exports.initFiles = void 0;
7
- var fs_1 = __importDefault(require("fs"));
8
- var path_1 = __importDefault(require("path"));
9
- var shelljs_1 = __importDefault(require("shelljs"));
10
- var db_1 = __importDefault(require("./server/db"));
11
- var replace_1 = __importDefault(require("replace"));
12
- var replace_in_file_1 = require("replace-in-file");
13
- var resolve = path_1.default.resolve;
14
- var getMysqlConfig = db_1.default.getMysqlConfig;
15
- var mysqlOptions = getMysqlConfig().mysqlOptions;
16
- var mysqlUser = mysqlOptions.user, mysqlPassword = mysqlOptions.password, mysqlHost = mysqlOptions.host, mysqlPort = mysqlOptions.port, mysqlDatabase = mysqlOptions.database;
17
- var mkdirFlag = true;
18
- var copyFileFlag = true;
19
- var replaceFlag = true;
20
- var replaceInFileFlag = true;
21
- var rmdirFlag = true;
22
- var rmfileFlag = true;
23
- var firstUpperCase = function (word) {
24
- return word.substring(0, 1).toUpperCase() + word.substring(1);
25
- };
26
- var mkdirSync = function (dirPath) {
27
- if (mkdirFlag) {
28
- if (!fs_1.default.existsSync(dirPath)) {
29
- fs_1.default.mkdirSync(dirPath);
30
- }
31
- }
32
- };
33
- var rmFileSync = function (filePath) {
34
- if (rmfileFlag) {
35
- if (fs_1.default.existsSync(filePath)) {
36
- fs_1.default.unlinkSync(filePath);
37
- }
38
- }
39
- };
40
- var rmdirSync = function (dirPath) {
41
- if (rmdirFlag) {
42
- if (fs_1.default.existsSync(dirPath)) {
43
- var list = fs_1.default.readdirSync(dirPath);
44
- list.forEach(function (item) {
45
- var resolverPath = resolve(dirPath + '/' + item);
46
- var stat = fs_1.default.statSync(resolverPath);
47
- var isDir = stat.isDirectory();
48
- var isFile = stat.isFile();
49
- if (isDir) {
50
- rmdirSync(resolverPath);
51
- }
52
- else if (isFile) {
53
- rmFileSync(resolverPath);
54
- }
55
- });
56
- fs_1.default.rmdirSync(dirPath);
57
- }
58
- }
59
- };
60
- var copyFileSync = function (source, dest, upgradeFlag) {
61
- if (upgradeFlag === void 0) { upgradeFlag = false; }
62
- if (copyFileFlag) {
63
- if (!upgradeFlag) {
64
- if (!fs_1.default.existsSync(dest) && fs_1.default.existsSync(source)) {
65
- fs_1.default.copyFileSync(source, dest);
66
- }
67
- }
68
- else {
69
- if (fs_1.default.existsSync(source)) {
70
- fs_1.default.copyFileSync(source, dest);
71
- }
72
- }
73
- }
74
- };
75
- var handleReplace = function (_a) {
76
- var regex = _a.regex, replacement = _a.replacement, paths = _a.paths;
77
- if (replaceFlag) {
78
- (0, replace_1.default)({
79
- regex: regex,
80
- replacement: replacement,
81
- paths: paths,
82
- recursive: true,
83
- silent: true
84
- });
85
- }
86
- };
87
- var replaceInFileAll = function (array, index, callback) {
88
- if (index === void 0) { index = 0; }
89
- if (replaceInFileFlag) {
90
- console.log('replaceInFileAll', index);
91
- var arrayLen = array.length;
92
- if (index < arrayLen) {
93
- var item = array[index];
94
- (0, replace_in_file_1.replaceInFile)(item, function (error, changedFiles) {
95
- if (error) {
96
- console.error('Error occurred:', error);
97
- }
98
- console.log('Modified files:', changedFiles);
99
- replaceInFileAll(array, ++index, callback);
100
- });
101
- }
102
- else {
103
- return callback && callback();
104
- }
105
- }
106
- else {
107
- return callback && callback();
108
- }
109
- };
110
- var sourceFolder = __dirname;
111
- var destFolder = process.cwd();
112
- var isLocal = sourceFolder === resolve(destFolder + '/lib');
113
- var generationPath = '../generation';
114
- var clientPathSource = '../client';
115
- var clientPath = './client';
116
- var serverPathSource = '../server';
117
- var serverPath = './server';
118
- var pagesPathSource = '../pages';
119
- var pagesPath = './pages';
120
- var publicPathSource = '../public';
121
- var publicPath = './public';
122
- var scriptsPathSource = '../scripts';
123
- var scriptsPath = './scripts';
124
- var reduxPath = '/redux';
125
- var servicePath = '/service';
126
- var styledPath = '/styled';
127
- var styledLayoutPath = '/layout';
128
- var utilsPath = '/utils';
129
- var layoutPath = '/layout';
130
- var modulesPath = '/modules';
131
- var apisPath = '/apis';
132
- var sqlPath = '/sql';
133
- var utilsMenuPath = '/menu.tsx';
134
- var reduxReducersPath = '/reducers.ts';
135
- var slbHealthCheckPath = '/slbhealthcheck.html';
136
- var packagePath = '/package.json';
137
- var restPath = '/rest.js';
138
- var sourceGenerationPath = path_1.default.join(sourceFolder, generationPath);
139
- var sourceClientPath = path_1.default.join(sourceFolder, clientPathSource);
140
- var sourceClientPathGeneration = path_1.default.join(sourceGenerationPath, clientPath);
141
- var sourceServerPath = path_1.default.join(sourceFolder, serverPathSource);
142
- var sourceServerPathGeneration = path_1.default.join(sourceGenerationPath, serverPath);
143
- var sourcePagesPath = path_1.default.join(sourceFolder, pagesPathSource);
144
- var sourcePublicPath = path_1.default.join(sourceFolder, publicPathSource);
145
- var sourceScriptsPath = path_1.default.join(sourceFolder, scriptsPathSource);
146
- var destClientPath = path_1.default.join(destFolder, clientPath);
147
- var destClientReduxPath = resolve(destClientPath + reduxPath);
148
- var destClientServicePath = resolve(destClientPath + servicePath);
149
- var destClientStyledPath = resolve(destClientPath + styledPath);
150
- var destClientStyledLayoutPath = resolve(destClientStyledPath + styledLayoutPath);
151
- var destClientUtilsPath = resolve(destClientPath + utilsPath);
152
- var destClientLayoutPath = resolve(destClientPath + layoutPath);
153
- var destServerPath = path_1.default.join(destFolder, serverPath);
154
- var destServerModulesPath = resolve(destServerPath + modulesPath);
155
- var destServerApisPath = resolve(destServerPath + apisPath);
156
- var destServerSqlPath = resolve(destServerPath + sqlPath);
157
- var destServerUtilsPath = resolve(destServerPath + utilsPath);
158
- var destPagesPath = path_1.default.join(destFolder, pagesPath);
159
- var destPublicPath = path_1.default.join(destFolder, publicPath);
160
- var destScriptsPath = path_1.default.join(destFolder, scriptsPath);
161
- var destClientUtilsMenuPath = resolve(destClientUtilsPath + utilsMenuPath);
162
- var destClientReduxReducersAllPath = resolve(destClientReduxPath + reduxReducersPath);
163
- var destPublicHealthCheckPath = resolve(destPublicPath + slbHealthCheckPath);
164
- var destPackagePath = resolve(destFolder + packagePath);
165
- var destServerRestPath = resolve(destServerPath + restPath);
166
- var initFiles = function (dictionary, upgradeFlag) {
167
- if (upgradeFlag === void 0) { upgradeFlag = false; }
168
- if (isLocal) {
169
- upgradeFlag = false;
170
- }
171
- var newDestFolder = '';
172
- if (dictionary !== '') {
173
- newDestFolder = resolve(destFolder + '/' + dictionary);
174
- mkdirSync(newDestFolder);
175
- }
176
- console.log('initFiles', dictionary === '' ? '.' : dictionary, upgradeFlag);
177
- var initClientFiles = function () {
178
- var clientReduxPath = reduxPath;
179
- var clientReduxReducersPath = reduxReducersPath;
180
- var clientReduxStorePath = '/store.ts';
181
- var clientStyledPath = styledPath;
182
- var clientStyledCommonPath = '/common.ts';
183
- var clientStyledLayoutPath = styledLayoutPath;
184
- var clientStyledLayoutIndexPath = '/index.ts';
185
- var clientUtilsPath = utilsPath;
186
- var clientUtilsCommonPath = '/common.ts';
187
- var clientUtilsFetchPath = '/fetch.ts';
188
- var clientUtilsCookiePath = '/cookie.ts';
189
- var clientUtilsMenuPath = utilsMenuPath;
190
- var clientLayoutPath = layoutPath;
191
- var clientLayoutIndexPath = '/index.tsx';
192
- // 仍旧使用 generation/client/redux/reducers.ts
193
- var sourceClientReduxReducersAllPath = resolve(sourceClientPathGeneration + clientReduxPath + clientReduxReducersPath);
194
- var sourceClientReduxStorePath = resolve(sourceClientPath + clientReduxPath + clientReduxStorePath);
195
- var sourceClientLayoutIndexPath = resolve(sourceClientPath + clientLayoutPath + clientLayoutIndexPath);
196
- var sourceClientStyledLayoutIndexPath = resolve(sourceClientPath + clientStyledPath + clientStyledLayoutPath + clientStyledLayoutIndexPath);
197
- var sourceClientStyledCommonPath = resolve(sourceClientPath + clientStyledPath + clientStyledCommonPath);
198
- var sourceClientUtilsCommonPath = resolve(sourceClientPath + clientUtilsPath + clientUtilsCommonPath);
199
- var sourceClientUtilsFetchPath = resolve(sourceClientPath + clientUtilsPath + clientUtilsFetchPath);
200
- var sourceClientUtilsCookiePath = resolve(sourceClientPath + clientUtilsPath + clientUtilsCookiePath);
201
- // 仍旧使用 generation/client/utils/menu.tsx
202
- var sourceClientUtilsMenuPath = resolve(sourceClientPathGeneration + clientUtilsPath + clientUtilsMenuPath);
203
- var destClientReduxStorePath = resolve(destClientReduxPath + clientReduxStorePath);
204
- var destClientLayoutIndexPath = resolve(destClientLayoutPath + clientLayoutIndexPath);
205
- var destClientStyledLayoutIndexPath = resolve(destClientStyledLayoutPath + clientStyledLayoutIndexPath);
206
- var destClientStyledCommonPath = resolve(destClientStyledPath + clientStyledCommonPath);
207
- var destClientUtilsCommonPath = resolve(destClientUtilsPath + clientUtilsCommonPath);
208
- var destClientUtilsFetchPath = resolve(destClientUtilsPath + clientUtilsFetchPath);
209
- var destClientUtilsCookiePath = resolve(destClientUtilsPath + clientUtilsCookiePath);
210
- if (dictionary === '') {
211
- mkdirSync(destClientPath);
212
- mkdirSync(destClientReduxPath);
213
- mkdirSync(destClientStyledPath);
214
- mkdirSync(destClientStyledLayoutPath);
215
- mkdirSync(destClientUtilsPath);
216
- mkdirSync(destClientLayoutPath);
217
- }
218
- else {
219
- var newDestClientPath = path_1.default.join(newDestFolder, clientPath);
220
- var newDestClientReduxPath = resolve(newDestClientPath + clientReduxPath);
221
- var newDestClientStyledPath = resolve(newDestClientPath + clientStyledPath);
222
- var newDestClientStyledLayoutPath = resolve(newDestClientStyledPath + clientStyledLayoutPath);
223
- var newDestClientUtilsPath = resolve(newDestClientPath + clientUtilsPath);
224
- var newDestClientLayoutPath = resolve(newDestClientPath + clientLayoutPath);
225
- mkdirSync(newDestClientPath);
226
- mkdirSync(newDestClientReduxPath);
227
- mkdirSync(newDestClientStyledPath);
228
- mkdirSync(newDestClientUtilsPath);
229
- mkdirSync(newDestClientLayoutPath);
230
- mkdirSync(newDestClientStyledLayoutPath);
231
- destClientReduxReducersAllPath = resolve(newDestClientReduxPath + clientReduxReducersPath);
232
- destClientReduxStorePath = resolve(newDestClientReduxPath + clientReduxStorePath);
233
- destClientLayoutIndexPath = resolve(newDestClientLayoutPath + clientLayoutIndexPath);
234
- destClientStyledLayoutIndexPath = resolve(newDestClientStyledLayoutPath + clientStyledLayoutIndexPath);
235
- destClientStyledCommonPath = resolve(newDestClientStyledPath + clientStyledCommonPath);
236
- destClientUtilsCommonPath = resolve(newDestClientUtilsPath + clientUtilsCommonPath);
237
- destClientUtilsFetchPath = resolve(newDestClientUtilsPath + clientUtilsFetchPath);
238
- destClientUtilsCookiePath = resolve(newDestClientUtilsPath + clientUtilsCookiePath);
239
- destClientUtilsMenuPath = resolve(newDestClientUtilsPath + clientUtilsMenuPath);
240
- }
241
- copyFileSync(sourceClientReduxStorePath, destClientReduxStorePath, upgradeFlag);
242
- copyFileSync(sourceClientStyledCommonPath, destClientStyledCommonPath, upgradeFlag);
243
- copyFileSync(sourceClientStyledLayoutIndexPath, destClientStyledLayoutIndexPath, upgradeFlag);
244
- copyFileSync(sourceClientUtilsCookiePath, destClientUtilsCookiePath, upgradeFlag);
245
- copyFileSync(sourceClientUtilsCommonPath, destClientUtilsCommonPath);
246
- copyFileSync(sourceClientUtilsFetchPath, destClientUtilsFetchPath);
247
- copyFileSync(sourceClientLayoutIndexPath, destClientLayoutIndexPath);
248
- copyFileSync(sourceClientReduxReducersAllPath, destClientReduxReducersAllPath);
249
- copyFileSync(sourceClientUtilsMenuPath, destClientUtilsMenuPath);
250
- };
251
- var initPagesFiles = function () {
252
- var pageIndexPath = '/index.tsx';
253
- var pageAppPath = '/_app.tsx';
254
- var pageDocumentPath = '/_document.tsx';
255
- var sourcePagesIndexPath = resolve(sourcePagesPath + pageIndexPath);
256
- var sourcePagesAppPath = resolve(sourcePagesPath + pageAppPath);
257
- var sourcePagesDocumentPath = resolve(sourcePagesPath + pageDocumentPath);
258
- var destPagesIndexPath = resolve(destPagesPath + pageIndexPath);
259
- var destPagesAppPath = resolve(destPagesPath + pageAppPath);
260
- var destPagesDocumentPath = resolve(destPagesPath + pageDocumentPath);
261
- if (dictionary === '') {
262
- mkdirSync(destPagesPath);
263
- }
264
- else {
265
- var newDestPagesPath = path_1.default.join(newDestFolder, pagesPath);
266
- mkdirSync(newDestPagesPath);
267
- destPagesIndexPath = resolve(newDestPagesPath + pageIndexPath);
268
- destPagesAppPath = resolve(newDestPagesPath + pageAppPath);
269
- destPagesDocumentPath = resolve(newDestPagesPath + pageDocumentPath);
270
- }
271
- copyFileSync(sourcePagesIndexPath, destPagesIndexPath);
272
- copyFileSync(sourcePagesAppPath, destPagesAppPath, upgradeFlag);
273
- copyFileSync(sourcePagesDocumentPath, destPagesDocumentPath, upgradeFlag);
274
- };
275
- var initServerFiles = function () {
276
- var serverRestPath = restPath;
277
- var serverApisPath = apisPath;
278
- var serverUtilsPath = utilsPath;
279
- var serverUtilsCommonPath = '/common.js';
280
- // 仍旧使用 generation/server/rest.js
281
- var sourceServerRestPath = resolve(sourceServerPathGeneration + serverRestPath);
282
- // 仍旧使用 generation/server/utils/common.js
283
- var sourceServerUtilsCommonPath = resolve(sourceServerPathGeneration + serverUtilsPath + serverUtilsCommonPath);
284
- var destServerUtilsCommonPath = resolve(destServerUtilsPath + serverUtilsCommonPath);
285
- if (dictionary === '') {
286
- mkdirSync(destServerPath);
287
- mkdirSync(destServerApisPath);
288
- mkdirSync(destServerUtilsPath);
289
- }
290
- else {
291
- var newDestServerPath = path_1.default.join(newDestFolder, serverPath);
292
- var newDestServerApisPath = resolve(newDestServerPath + serverApisPath);
293
- var newDestServerUtilsPath = resolve(newDestServerPath + serverUtilsPath);
294
- mkdirSync(newDestServerPath);
295
- mkdirSync(newDestServerApisPath);
296
- mkdirSync(newDestServerUtilsPath);
297
- destServerRestPath = resolve(newDestServerPath + serverRestPath);
298
- destServerUtilsCommonPath = resolve(newDestServerUtilsPath + serverUtilsCommonPath);
299
- }
300
- copyFileSync(sourceServerRestPath, destServerRestPath);
301
- copyFileSync(sourceServerUtilsCommonPath, destServerUtilsCommonPath, upgradeFlag);
302
- };
303
- var initPublicFiles = function () {
304
- var publicImagesPath = '/images';
305
- var publicImagesZhizuotuPath = '/zhizuotu_1.png';
306
- var publicSlbHealthcheckPath = slbHealthCheckPath;
307
- var destPublicImagesPath = resolve(destPublicPath + publicImagesPath);
308
- var sourcePublicImages1Path = resolve(sourcePublicPath + publicImagesPath + publicImagesZhizuotuPath);
309
- var sourcePublicHealthCheckPath = resolve(sourcePublicPath + publicSlbHealthcheckPath);
310
- var destPublicImages1Path = resolve(destPublicImagesPath + publicImagesZhizuotuPath);
311
- if (dictionary === '') {
312
- mkdirSync(destPublicPath);
313
- mkdirSync(destPublicImagesPath);
314
- }
315
- else {
316
- var newDestPublicPath = path_1.default.join(newDestFolder, publicPath);
317
- var newDestPublicImagesPath = resolve(newDestPublicPath + publicImagesPath);
318
- mkdirSync(newDestPublicPath);
319
- mkdirSync(newDestPublicImagesPath);
320
- destPublicHealthCheckPath = resolve(newDestPublicPath + publicSlbHealthcheckPath);
321
- destPublicImages1Path = resolve(newDestPublicImagesPath + publicImagesZhizuotuPath);
322
- }
323
- copyFileSync(sourcePublicHealthCheckPath, destPublicHealthCheckPath);
324
- copyFileSync(sourcePublicImages1Path, destPublicImages1Path, upgradeFlag);
325
- };
326
- var initScriptsFiles = function () {
327
- var scriptsStartupPath = '/startup.sh';
328
- var scriptsShutdownPath = '/shutdown.sh';
329
- var sourceScriptsStartupPath = resolve(sourceScriptsPath + scriptsStartupPath);
330
- var sourceScriptsShutdownPath = resolve(sourceScriptsPath + scriptsShutdownPath);
331
- var destScriptsStartupPath = resolve(destScriptsPath + scriptsStartupPath);
332
- var destScriptsShutdownPath = resolve(destScriptsPath + scriptsShutdownPath);
333
- if (dictionary === '') {
334
- mkdirSync(destScriptsPath);
335
- }
336
- else {
337
- var newDestScriptsPath = path_1.default.join(newDestFolder, scriptsPath);
338
- mkdirSync(newDestScriptsPath);
339
- destScriptsStartupPath = resolve(newDestScriptsPath + scriptsStartupPath);
340
- destScriptsShutdownPath = resolve(newDestScriptsPath + scriptsShutdownPath);
341
- }
342
- copyFileSync(sourceScriptsStartupPath, destScriptsStartupPath);
343
- copyFileSync(sourceScriptsShutdownPath, destScriptsShutdownPath);
344
- };
345
- var initRootFiles = function () {
346
- var rootNextConfigPath = '/next.config.js';
347
- var rootMysqlConfigPath = '/mysql.config.js';
348
- var rootProjectConfigPath = '/project.config.js';
349
- var rootPackagePath = packagePath;
350
- var rootTsconfigPath = '/tsconfig.json';
351
- var rootBabelrcPath = '/.babelrc';
352
- var rootGitignorePathSource = '/gitignore';
353
- var rootGitignorePath = '/.gitignore';
354
- var rootNextEnvPathSource = '../next-env.d.ts';
355
- var rootNextEnvPath = '/next-env.d.ts';
356
- var rootReadmePath = '/README.md';
357
- var rootAppConfigPathSource = '../app.config.js';
358
- var rootAppConfigPath = '/app.config.js';
359
- var rootAppPath = '/app.js';
360
- var sourceNextConfigPath = resolve(sourceGenerationPath + rootNextConfigPath);
361
- var sourceMysqlConfigPath = resolve(sourceGenerationPath + rootMysqlConfigPath);
362
- var sourceProjectConfigPath = resolve(sourceGenerationPath + rootProjectConfigPath);
363
- var sourceTsConfigPath = resolve(sourceGenerationPath + rootTsconfigPath);
364
- var sourceBabelrcPath = path_1.default.join(sourceGenerationPath, rootBabelrcPath);
365
- var sourceGitignorePath = resolve(sourceGenerationPath + rootGitignorePathSource);
366
- var sourceNextEnvPath = path_1.default.join(sourceFolder, rootNextEnvPathSource);
367
- var sourceReadmePath = resolve(sourceGenerationPath + rootReadmePath);
368
- var sourceAppConfigPath = path_1.default.join(sourceFolder, rootAppConfigPathSource);
369
- var sourceAppath = resolve(sourceGenerationPath + rootAppPath);
370
- var sourcePackagePath = resolve(sourceGenerationPath + rootPackagePath);
371
- var destNextConfigPath = resolve(destFolder + rootNextConfigPath);
372
- var destMysqlConfigPath = resolve(destFolder + rootMysqlConfigPath);
373
- var destProjectConfigPath = resolve(destFolder + rootProjectConfigPath);
374
- var destTsConfigPath = resolve(destFolder + rootTsconfigPath);
375
- var destBabelrcPath = resolve(destFolder + rootBabelrcPath);
376
- var destGitignorePath = resolve(destFolder + rootGitignorePath);
377
- var destNextEnvPath = resolve(destFolder + rootNextEnvPath);
378
- var destReadmePath = resolve(destFolder + rootReadmePath);
379
- var destAppConfigPath = resolve(destFolder + rootAppConfigPath);
380
- var destAppath = resolve(destFolder + rootAppPath);
381
- if (dictionary !== '') {
382
- destNextConfigPath = resolve(newDestFolder + rootNextConfigPath);
383
- destMysqlConfigPath = resolve(newDestFolder + rootMysqlConfigPath);
384
- destProjectConfigPath = resolve(newDestFolder + rootProjectConfigPath);
385
- destTsConfigPath = resolve(newDestFolder + rootTsconfigPath);
386
- destBabelrcPath = resolve(newDestFolder + rootBabelrcPath);
387
- destGitignorePath = resolve(newDestFolder + rootGitignorePath);
388
- destNextEnvPath = resolve(newDestFolder + rootNextEnvPath);
389
- destReadmePath = resolve(newDestFolder + rootReadmePath);
390
- destAppConfigPath = resolve(newDestFolder + rootAppConfigPath);
391
- destAppath = resolve(newDestFolder + rootAppPath);
392
- destPackagePath = resolve(newDestFolder + rootPackagePath);
393
- }
394
- copyFileSync(sourceNextConfigPath, destNextConfigPath);
395
- copyFileSync(sourceMysqlConfigPath, destMysqlConfigPath);
396
- copyFileSync(sourceProjectConfigPath, destProjectConfigPath);
397
- copyFileSync(sourcePackagePath, destPackagePath);
398
- copyFileSync(sourceTsConfigPath, destTsConfigPath);
399
- copyFileSync(sourceBabelrcPath, destBabelrcPath);
400
- copyFileSync(sourceGitignorePath, destGitignorePath);
401
- copyFileSync(sourceNextEnvPath, destNextEnvPath);
402
- copyFileSync(sourceReadmePath, destReadmePath);
403
- copyFileSync(sourceAppConfigPath, destAppConfigPath);
404
- copyFileSync(sourceAppath, destAppath);
405
- };
406
- initClientFiles();
407
- initPagesFiles();
408
- initServerFiles();
409
- initPublicFiles();
410
- initScriptsFiles();
411
- initRootFiles();
412
- if (!isLocal && !upgradeFlag) {
413
- if (dictionary !== '') {
414
- shelljs_1.default.sed('-i', eval('/nsgm-cli-project/'), dictionary + '-project', destPackagePath);
415
- shelljs_1.default.sed('-i', eval('/NSGM-CLI/'), dictionary, destPublicHealthCheckPath);
416
- shelljs_1.default.exec('cd ' + dictionary + ' && npm install --save nsgm-cli');
417
- shelljs_1.default.exec('cd ' + dictionary + ' && npm install --save-dev @types/node');
418
- shelljs_1.default.exec('cd ' + dictionary + ' && npm install --save-dev @types/react@18.0.1');
419
- shelljs_1.default.exec('cd ' + dictionary + ' && npm install --save-dev @types/lodash');
420
- }
421
- else {
422
- shelljs_1.default.sed('-i', eval('/nsgm-cli-project/'), path_1.default.basename(destFolder) + '-project', destPackagePath);
423
- shelljs_1.default.sed('-i', eval('/NSGM-CLI/'), path_1.default.basename(destFolder), destPublicHealthCheckPath);
424
- shelljs_1.default.exec('npm install --save nsgm-cli');
425
- shelljs_1.default.exec('npm install --save-dev @types/node');
426
- shelljs_1.default.exec('npm install --save-dev @types/react@18.0.1');
427
- shelljs_1.default.exec('npm install --save-dev @types/lodash');
428
- }
429
- }
430
- console.log('initFiles finished');
431
- };
432
- exports.initFiles = initFiles;
433
- var createFiles = function (controller, action) {
434
- console.log('createFiles', sourceFolder, destFolder, isLocal, controller, action);
435
- mkdirSync(destClientPath);
436
- mkdirSync(destServerPath);
437
- mkdirSync(destPagesPath);
438
- // pages
439
- var sourcePagesActionPath = resolve(sourcePagesPath + '/template/manage.tsx');
440
- var destPagesControllerPath = resolve(destPagesPath + '/' + controller);
441
- var destPagesActionPath = resolve(destPagesControllerPath + '/' + action + '.tsx');
442
- mkdirSync(destPagesControllerPath);
443
- copyFileSync(sourcePagesActionPath, destPagesActionPath);
444
- console.log('pages finished');
445
- // client redux
446
- var destClientReduxControllerPath = resolve(destClientReduxPath + '/' + controller);
447
- var destClientReduxControllerActionPath = resolve(destClientReduxControllerPath + '/' + action);
448
- mkdirSync(destClientReduxPath);
449
- mkdirSync(destClientReduxControllerPath);
450
- mkdirSync(destClientReduxControllerActionPath);
451
- var sourceClientReduxActionsPath = resolve(sourceClientPath + '/redux/template/manage/actions.ts');
452
- var sourceClientReduxReducersPath = resolve(sourceClientPath + '/redux/template/manage/reducers.ts');
453
- var sourceClientReduxTypesPath = resolve(sourceClientPath + '/redux/template/manage/types.ts');
454
- var destClientReduxActionsPath = resolve(destClientReduxControllerActionPath + '/actions.ts');
455
- var destClientReduxReducersPath = resolve(destClientReduxControllerActionPath + '/reducers.ts');
456
- var destClientReduxTypesPath = resolve(destClientReduxControllerActionPath + '/types.ts');
457
- copyFileSync(sourceClientReduxActionsPath, destClientReduxActionsPath);
458
- copyFileSync(sourceClientReduxReducersPath, destClientReduxReducersPath);
459
- copyFileSync(sourceClientReduxTypesPath, destClientReduxTypesPath);
460
- console.log('client redux finished');
461
- // client service
462
- var sourceClientActionPath = resolve(sourceClientPath + '/service/template/manage.ts');
463
- var destClientServiceControllerPath = resolve(destClientServicePath + '/' + controller);
464
- var destClientActionPath = resolve(destClientServiceControllerPath + '/' + action + '.ts');
465
- mkdirSync(destClientServicePath);
466
- mkdirSync(destClientServiceControllerPath);
467
- copyFileSync(sourceClientActionPath, destClientActionPath);
468
- console.log('client service finished');
469
- // client styled
470
- var sourceClientStyledActionPath = resolve(sourceClientPath + '/styled/template/manage.ts');
471
- var destClientStyledControllerPath = resolve(destClientStyledPath + '/' + controller);
472
- mkdirSync(destClientStyledPath);
473
- mkdirSync(destClientStyledControllerPath);
474
- var destClientStyledActionPath = resolve(destClientStyledControllerPath + '/' + action + '.ts');
475
- copyFileSync(sourceClientStyledActionPath, destClientStyledActionPath);
476
- console.log('client styled finished');
477
- // server modules
478
- var sourceServerModulesResolverPath = resolve(sourceServerPath + '/modules/template/resolver.js');
479
- var sourceServerModulesSchemaPath = resolve(sourceServerPath + '/modules/template/schema.js');
480
- var destServerModulesControllerPath = resolve(destServerModulesPath + '/' + controller);
481
- mkdirSync(destServerModulesPath);
482
- mkdirSync(destServerModulesControllerPath);
483
- var destServerModulesResolverPath = resolve(destServerModulesControllerPath + '/resolver.js');
484
- var destServerModulesSchemaPath = resolve(destServerModulesControllerPath + '/schema.js');
485
- copyFileSync(sourceServerModulesResolverPath, destServerModulesResolverPath);
486
- copyFileSync(sourceServerModulesSchemaPath, destServerModulesSchemaPath);
487
- console.log('server modules finished');
488
- // server apis
489
- var sourceServerApisControllerPath = resolve(sourceServerPath + '/apis/template.js');
490
- mkdirSync(destServerApisPath);
491
- var destServerApisControllerPath = resolve(destServerApisPath + '/' + controller + '.js');
492
- copyFileSync(sourceServerApisControllerPath, destServerApisControllerPath);
493
- console.log('server apis finished');
494
- // server sql
495
- var sourceServerSqlControllerPath = resolve(sourceServerPath + '/sql/template.sql');
496
- mkdirSync(destServerSqlPath);
497
- var destServerSqlControllerPath = resolve(destServerSqlPath + '/' + controller + '.sql');
498
- copyFileSync(sourceServerSqlControllerPath, destServerSqlControllerPath);
499
- console.log('server sql finished');
500
- // replace dest files
501
- handleReplace({
502
- regex: 'template',
503
- replacement: controller,
504
- paths: [
505
- destPagesActionPath,
506
- destClientActionPath,
507
- destClientReduxActionsPath,
508
- destClientReduxReducersPath,
509
- destServerModulesResolverPath,
510
- destServerModulesSchemaPath,
511
- destServerApisControllerPath
512
- ]
513
- });
514
- handleReplace({
515
- regex: 'Template',
516
- replacement: firstUpperCase(controller),
517
- paths: [
518
- destPagesActionPath,
519
- destClientActionPath,
520
- destClientReduxActionsPath,
521
- destServerModulesSchemaPath,
522
- destServerApisControllerPath
523
- ]
524
- });
525
- handleReplace({
526
- regex: 'TEMPLATE',
527
- replacement: controller.toUpperCase(),
528
- paths: [destClientReduxActionsPath, destClientReduxReducersPath, destClientReduxTypesPath]
529
- });
530
- handleReplace({
531
- regex: 'manage',
532
- replacement: action,
533
- paths: [destPagesActionPath, destClientReduxActionsPath]
534
- });
535
- handleReplace({
536
- regex: 'Manage',
537
- replacement: firstUpperCase(action),
538
- paths: [destPagesActionPath, destClientReduxReducersPath]
539
- });
540
- console.log('replace dest files finished');
541
- // special replace dest files
542
- var optionsArr = [
543
- {
544
- from: /\n\s*\n/,
545
- to: '\nimport { ' +
546
- controller +
547
- firstUpperCase(action) +
548
- "Reducer } from './" +
549
- controller +
550
- '/' +
551
- action +
552
- "/reducers'\n\n",
553
- files: [destClientReduxReducersAllPath]
554
- },
555
- {
556
- from: /Reducer,\s*\n/,
557
- to: 'Reducer,\n ' +
558
- controller +
559
- firstUpperCase(action) +
560
- ': ' +
561
- controller +
562
- firstUpperCase(action) +
563
- 'Reducer,\n',
564
- files: [destClientReduxReducersAllPath]
565
- },
566
- {
567
- from: /'(.\/apis\/template.*?)'\)\s*\n/,
568
- to: "'./apis/template')\nconst " + controller + " = require('./apis/" + controller + "')\n",
569
- files: [destServerRestPath]
570
- },
571
- {
572
- from: /template\)\s*\n/,
573
- to: "template)\nrouter.use('/" + controller + "', " + controller + ')\n',
574
- files: [destServerRestPath]
575
- },
576
- {
577
- from: /null\s*\n/,
578
- to: 'null\n },\n {\n // ' +
579
- controller +
580
- '_' +
581
- action +
582
- "_start\n key: (++key).toString(),\n text: '" +
583
- controller +
584
- "',\n url: '/" +
585
- controller +
586
- '/' +
587
- action +
588
- "',\n icon: <SolutionOutlined rev={undefined} />,\n " +
589
- "subMenus: [\n {\n key: key + '_1',\n text: '" +
590
- action +
591
- "',\n url: '/" +
592
- controller +
593
- '/' +
594
- action +
595
- "'\n }\n ]\n // " +
596
- controller +
597
- '_' +
598
- action +
599
- '_end\n',
600
- files: [destClientUtilsMenuPath]
601
- }
602
- ];
603
- if (isLocal) {
604
- optionsArr.push({
605
- from: /'nsgm-cli'\)/,
606
- to: "'../../../index')",
607
- files: [destServerModulesResolverPath]
608
- });
609
- }
610
- shelljs_1.default.sed('-i', eval('/.*' + controller + firstUpperCase(action) + 'Reducer.*/'), '', destClientReduxReducersAllPath);
611
- shelljs_1.default.sed('-i', eval('/.*' + controller + '.*/'), '', destServerRestPath);
612
- shelljs_1.default.sed('-i', eval('/template/'), controller, destServerSqlControllerPath);
613
- shelljs_1.default.sed('-i', eval('/crm_demo/'), mysqlDatabase, destServerSqlControllerPath);
614
- shelljs_1.default.exec('mysql -u' +
615
- mysqlUser +
616
- ' -p' +
617
- mysqlPassword +
618
- ' -h' +
619
- mysqlHost +
620
- ' -P' +
621
- mysqlPort +
622
- ' < ' +
623
- destServerSqlControllerPath);
624
- setTimeout(function () {
625
- replaceInFileAll(optionsArr, 0, function () {
626
- console.log('special replace dest files finished');
627
- });
628
- }, 1000);
629
- };
630
- exports.createFiles = createFiles;
631
- var deleteFiles = function (controller, action, deleteDBFlag) {
632
- if (deleteDBFlag === void 0) { deleteDBFlag = false; }
633
- console.log('deleteFiles', sourceFolder, destFolder, isLocal, controller, action, deleteDBFlag);
634
- // pages
635
- var destPagesControllerPath = resolve(destPagesPath + '/' + controller);
636
- // client redux
637
- var destClientReduxControllerPath = resolve(destClientReduxPath + '/' + controller);
638
- // client service
639
- var destClientServiceControllerPath = resolve(destClientServicePath + '/' + controller);
640
- // client styled
641
- var destClientStyledControllerPath = resolve(destClientStyledPath + '/' + controller);
642
- // server modules
643
- var destServerModulesControllerPath = resolve(destServerModulesPath + '/' + controller);
644
- // server apis
645
- var destServerApisControllerPath = resolve(destServerApisPath + '/' + controller + '.js');
646
- // server sql
647
- var destServerSqlControllerPath = resolve(destServerSqlPath + '/' + controller + '.sql');
648
- if (action === 'all') {
649
- rmdirSync(destPagesControllerPath);
650
- rmdirSync(destClientReduxControllerPath);
651
- rmdirSync(destClientServiceControllerPath);
652
- rmdirSync(destClientStyledControllerPath);
653
- rmdirSync(destServerModulesControllerPath);
654
- rmFileSync(destServerApisControllerPath);
655
- shelljs_1.default.sed('-i', eval('/.*' + controller + '.*' + 'Reducer.*/'), '', destClientReduxReducersAllPath);
656
- shelljs_1.default.sed('-i', eval('/.*' + controller + '.*/'), '', destServerRestPath);
657
- shelljs_1.default.sed('-i', eval('/.*' + controller + '_.*_start.*/'), ' /*', destClientUtilsMenuPath);
658
- shelljs_1.default.sed('-i', eval('/.*' + controller + '_.*_end.*/'), ' */', destClientUtilsMenuPath);
659
- if (deleteDBFlag) {
660
- shelljs_1.default.sed('-i', eval('/' + mysqlDatabase + ';/'), mysqlDatabase + ';\nDROP TABLE `' + controller + '`;\n/*', destServerSqlControllerPath);
661
- shelljs_1.default.sed('-i', eval('/utf8mb4;/'), 'utf8mb4;\n*/', destServerSqlControllerPath);
662
- shelljs_1.default.exec('mysql -u' +
663
- mysqlUser +
664
- ' -p' +
665
- mysqlPassword +
666
- ' -h' +
667
- mysqlHost +
668
- ' -P' +
669
- mysqlPort +
670
- ' < ' +
671
- destServerSqlControllerPath);
672
- }
673
- rmFileSync(destServerSqlControllerPath);
674
- var optionsArr_1 = [
675
- {
676
- from: /\n\s*\n/,
677
- to: '\n\n',
678
- files: [destClientReduxReducersAllPath]
679
- },
680
- {
681
- from: /Reducer,\s*\n/,
682
- to: 'Reducer,\n',
683
- files: [destClientReduxReducersAllPath]
684
- },
685
- {
686
- from: /'(.\/apis\/template.*?)'\)\s*\n/,
687
- to: "'./apis/template')\n\n",
688
- files: [destServerRestPath]
689
- },
690
- {
691
- from: /template\)\s*\n/,
692
- to: 'template)\n\n',
693
- files: [destServerRestPath]
694
- }
695
- ];
696
- setTimeout(function () {
697
- replaceInFileAll(optionsArr_1, 0, function () {
698
- console.log('special replace dest files finished');
699
- });
700
- }, 1000);
701
- }
702
- else {
703
- // pages
704
- var destPagesActionPath = resolve(destPagesControllerPath + '/' + action + '.tsx');
705
- // client redux
706
- var destClientReduxControllerActionPath = resolve(destClientReduxControllerPath + '/' + action);
707
- // client service
708
- var destClientActionPath = resolve(destClientServiceControllerPath + '/' + action + '.ts');
709
- // client styled
710
- var destClientStyledActionPath = resolve(destClientStyledControllerPath + '/' + action + '.ts');
711
- rmFileSync(destPagesActionPath);
712
- rmdirSync(destClientReduxControllerActionPath);
713
- rmFileSync(destClientActionPath);
714
- rmFileSync(destClientStyledActionPath);
715
- shelljs_1.default.sed('-i', eval('/.*' + controller + firstUpperCase(action) + 'Reducer.*/'), '', destClientReduxReducersAllPath);
716
- var optionsArr_2 = [
717
- {
718
- from: /\n\s*\n/,
719
- to: '\n\n',
720
- files: [destClientReduxReducersAllPath]
721
- },
722
- {
723
- from: /Reducer,\s*\n/,
724
- to: 'Reducer,\n',
725
- files: [destClientReduxReducersAllPath]
726
- }
727
- ];
728
- setTimeout(function () {
729
- replaceInFileAll(optionsArr_2, 0, function () {
730
- console.log('special replace dest files finished');
731
- });
732
- }, 1000);
733
- }
734
- console.log('delFiles finished');
735
- };
736
- exports.deleteFiles = deleteFiles;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.deleteFiles = exports.createFiles = exports.initFiles = void 0;
7
+ var fs_1 = __importDefault(require("fs"));
8
+ var path_1 = __importDefault(require("path"));
9
+ var shelljs_1 = __importDefault(require("shelljs"));
10
+ var db_1 = __importDefault(require("./server/db"));
11
+ var replace_1 = __importDefault(require("replace"));
12
+ var replace_in_file_1 = require("replace-in-file");
13
+ var resolve = path_1.default.resolve;
14
+ var getMysqlConfig = db_1.default.getMysqlConfig;
15
+ var mysqlOptions = getMysqlConfig().mysqlOptions;
16
+ var mysqlUser = mysqlOptions.user, mysqlPassword = mysqlOptions.password, mysqlHost = mysqlOptions.host, mysqlPort = mysqlOptions.port, mysqlDatabase = mysqlOptions.database;
17
+ var mkdirFlag = true;
18
+ var copyFileFlag = true;
19
+ var replaceFlag = true;
20
+ var replaceInFileFlag = true;
21
+ var rmdirFlag = true;
22
+ var rmfileFlag = true;
23
+ var firstUpperCase = function (word) {
24
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
25
+ };
26
+ var mkdirSync = function (dirPath) {
27
+ if (mkdirFlag) {
28
+ if (!fs_1.default.existsSync(dirPath)) {
29
+ fs_1.default.mkdirSync(dirPath);
30
+ }
31
+ }
32
+ };
33
+ var rmFileSync = function (filePath) {
34
+ if (rmfileFlag) {
35
+ if (fs_1.default.existsSync(filePath)) {
36
+ fs_1.default.unlinkSync(filePath);
37
+ }
38
+ }
39
+ };
40
+ var rmdirSync = function (dirPath) {
41
+ if (rmdirFlag) {
42
+ if (fs_1.default.existsSync(dirPath)) {
43
+ var list = fs_1.default.readdirSync(dirPath);
44
+ list.forEach(function (item) {
45
+ var resolverPath = resolve(dirPath + '/' + item);
46
+ var stat = fs_1.default.statSync(resolverPath);
47
+ var isDir = stat.isDirectory();
48
+ var isFile = stat.isFile();
49
+ if (isDir) {
50
+ rmdirSync(resolverPath);
51
+ }
52
+ else if (isFile) {
53
+ rmFileSync(resolverPath);
54
+ }
55
+ });
56
+ fs_1.default.rmdirSync(dirPath);
57
+ }
58
+ }
59
+ };
60
+ var copyFileSync = function (source, dest, upgradeFlag) {
61
+ if (upgradeFlag === void 0) { upgradeFlag = false; }
62
+ if (copyFileFlag) {
63
+ if (!upgradeFlag) {
64
+ if (!fs_1.default.existsSync(dest) && fs_1.default.existsSync(source)) {
65
+ fs_1.default.copyFileSync(source, dest);
66
+ }
67
+ }
68
+ else {
69
+ if (fs_1.default.existsSync(source)) {
70
+ fs_1.default.copyFileSync(source, dest);
71
+ }
72
+ }
73
+ }
74
+ };
75
+ var handleReplace = function (_a) {
76
+ var regex = _a.regex, replacement = _a.replacement, paths = _a.paths;
77
+ if (replaceFlag) {
78
+ (0, replace_1.default)({
79
+ regex: regex,
80
+ replacement: replacement,
81
+ paths: paths,
82
+ recursive: true,
83
+ silent: true
84
+ });
85
+ }
86
+ };
87
+ var replaceInFileAll = function (array, index, callback) {
88
+ if (index === void 0) { index = 0; }
89
+ if (replaceInFileFlag) {
90
+ console.log('replaceInFileAll', index);
91
+ var arrayLen = array.length;
92
+ if (index < arrayLen) {
93
+ var item = array[index];
94
+ (0, replace_in_file_1.replaceInFile)(item, function (error, changedFiles) {
95
+ if (error) {
96
+ console.error('Error occurred:', error);
97
+ }
98
+ console.log('Modified files:', changedFiles);
99
+ replaceInFileAll(array, ++index, callback);
100
+ });
101
+ }
102
+ else {
103
+ return callback && callback();
104
+ }
105
+ }
106
+ else {
107
+ return callback && callback();
108
+ }
109
+ };
110
+ var sourceFolder = __dirname;
111
+ var destFolder = process.cwd();
112
+ var isLocal = sourceFolder === resolve(destFolder + '/lib');
113
+ var generationPath = '../generation';
114
+ var clientPathSource = '../client';
115
+ var clientPath = './client';
116
+ var serverPathSource = '../server';
117
+ var serverPath = './server';
118
+ var pagesPathSource = '../pages';
119
+ var pagesPath = './pages';
120
+ var publicPathSource = '../public';
121
+ var publicPath = './public';
122
+ var scriptsPathSource = '../scripts';
123
+ var scriptsPath = './scripts';
124
+ var reduxPath = '/redux';
125
+ var servicePath = '/service';
126
+ var styledPath = '/styled';
127
+ var styledLayoutPath = '/layout';
128
+ var utilsPath = '/utils';
129
+ var layoutPath = '/layout';
130
+ var modulesPath = '/modules';
131
+ var apisPath = '/apis';
132
+ var sqlPath = '/sql';
133
+ var utilsMenuPath = '/menu.tsx';
134
+ var reduxReducersPath = '/reducers.ts';
135
+ var slbHealthCheckPath = '/slbhealthcheck.html';
136
+ var packagePath = '/package.json';
137
+ var restPath = '/rest.js';
138
+ var sourceGenerationPath = path_1.default.join(sourceFolder, generationPath);
139
+ var sourceClientPath = path_1.default.join(sourceFolder, clientPathSource);
140
+ var sourceClientPathGeneration = path_1.default.join(sourceGenerationPath, clientPath);
141
+ var sourceServerPath = path_1.default.join(sourceFolder, serverPathSource);
142
+ var sourceServerPathGeneration = path_1.default.join(sourceGenerationPath, serverPath);
143
+ var sourcePagesPath = path_1.default.join(sourceFolder, pagesPathSource);
144
+ var sourcePublicPath = path_1.default.join(sourceFolder, publicPathSource);
145
+ var sourceScriptsPath = path_1.default.join(sourceFolder, scriptsPathSource);
146
+ var destClientPath = path_1.default.join(destFolder, clientPath);
147
+ var destClientReduxPath = resolve(destClientPath + reduxPath);
148
+ var destClientServicePath = resolve(destClientPath + servicePath);
149
+ var destClientStyledPath = resolve(destClientPath + styledPath);
150
+ var destClientStyledLayoutPath = resolve(destClientStyledPath + styledLayoutPath);
151
+ var destClientUtilsPath = resolve(destClientPath + utilsPath);
152
+ var destClientLayoutPath = resolve(destClientPath + layoutPath);
153
+ var destServerPath = path_1.default.join(destFolder, serverPath);
154
+ var destServerModulesPath = resolve(destServerPath + modulesPath);
155
+ var destServerApisPath = resolve(destServerPath + apisPath);
156
+ var destServerSqlPath = resolve(destServerPath + sqlPath);
157
+ var destServerUtilsPath = resolve(destServerPath + utilsPath);
158
+ var destPagesPath = path_1.default.join(destFolder, pagesPath);
159
+ var destPublicPath = path_1.default.join(destFolder, publicPath);
160
+ var destScriptsPath = path_1.default.join(destFolder, scriptsPath);
161
+ var destClientUtilsMenuPath = resolve(destClientUtilsPath + utilsMenuPath);
162
+ var destClientReduxReducersAllPath = resolve(destClientReduxPath + reduxReducersPath);
163
+ var destPublicHealthCheckPath = resolve(destPublicPath + slbHealthCheckPath);
164
+ var destPackagePath = resolve(destFolder + packagePath);
165
+ var destServerRestPath = resolve(destServerPath + restPath);
166
+ var initFiles = function (dictionary, upgradeFlag) {
167
+ if (upgradeFlag === void 0) { upgradeFlag = false; }
168
+ if (isLocal) {
169
+ upgradeFlag = false;
170
+ }
171
+ var newDestFolder = '';
172
+ if (dictionary !== '') {
173
+ newDestFolder = resolve(destFolder + '/' + dictionary);
174
+ mkdirSync(newDestFolder);
175
+ }
176
+ console.log('initFiles', dictionary === '' ? '.' : dictionary, upgradeFlag);
177
+ var initClientFiles = function () {
178
+ var clientReduxPath = reduxPath;
179
+ var clientReduxReducersPath = reduxReducersPath;
180
+ var clientReduxStorePath = '/store.ts';
181
+ var clientStyledPath = styledPath;
182
+ var clientStyledCommonPath = '/common.ts';
183
+ var clientStyledLayoutPath = styledLayoutPath;
184
+ var clientStyledLayoutIndexPath = '/index.ts';
185
+ var clientUtilsPath = utilsPath;
186
+ var clientUtilsCommonPath = '/common.ts';
187
+ var clientUtilsFetchPath = '/fetch.ts';
188
+ var clientUtilsCookiePath = '/cookie.ts';
189
+ var clientUtilsSsoPath = '/sso.ts';
190
+ var clientUtilsMenuPath = utilsMenuPath;
191
+ var clientLayoutPath = layoutPath;
192
+ var clientLayoutIndexPath = '/index.tsx';
193
+ // 仍旧使用 generation/client/redux/reducers.ts
194
+ var sourceClientReduxReducersAllPath = resolve(sourceClientPathGeneration + clientReduxPath + clientReduxReducersPath);
195
+ var sourceClientReduxStorePath = resolve(sourceClientPath + clientReduxPath + clientReduxStorePath);
196
+ var sourceClientLayoutIndexPath = resolve(sourceClientPath + clientLayoutPath + clientLayoutIndexPath);
197
+ var sourceClientStyledLayoutIndexPath = resolve(sourceClientPath + clientStyledPath + clientStyledLayoutPath + clientStyledLayoutIndexPath);
198
+ var sourceClientStyledCommonPath = resolve(sourceClientPath + clientStyledPath + clientStyledCommonPath);
199
+ var sourceClientUtilsCommonPath = resolve(sourceClientPath + clientUtilsPath + clientUtilsCommonPath);
200
+ var sourceClientUtilsFetchPath = resolve(sourceClientPath + clientUtilsPath + clientUtilsFetchPath);
201
+ var sourceClientUtilsCookiePath = resolve(sourceClientPath + clientUtilsPath + clientUtilsCookiePath);
202
+ var sourceClientUtilsSsoPath = resolve(sourceClientPath + clientUtilsPath + clientUtilsSsoPath);
203
+ // 仍旧使用 generation/client/utils/menu.tsx
204
+ var sourceClientUtilsMenuPath = resolve(sourceClientPathGeneration + clientUtilsPath + clientUtilsMenuPath);
205
+ var destClientReduxStorePath = resolve(destClientReduxPath + clientReduxStorePath);
206
+ var destClientLayoutIndexPath = resolve(destClientLayoutPath + clientLayoutIndexPath);
207
+ var destClientStyledLayoutIndexPath = resolve(destClientStyledLayoutPath + clientStyledLayoutIndexPath);
208
+ var destClientStyledCommonPath = resolve(destClientStyledPath + clientStyledCommonPath);
209
+ var destClientUtilsCommonPath = resolve(destClientUtilsPath + clientUtilsCommonPath);
210
+ var destClientUtilsFetchPath = resolve(destClientUtilsPath + clientUtilsFetchPath);
211
+ var destClientUtilsCookiePath = resolve(destClientUtilsPath + clientUtilsCookiePath);
212
+ var destClientUtilsSsoPath = resolve(destClientUtilsPath + clientUtilsSsoPath);
213
+ if (dictionary === '') {
214
+ mkdirSync(destClientPath);
215
+ mkdirSync(destClientReduxPath);
216
+ mkdirSync(destClientStyledPath);
217
+ mkdirSync(destClientStyledLayoutPath);
218
+ mkdirSync(destClientUtilsPath);
219
+ mkdirSync(destClientLayoutPath);
220
+ }
221
+ else {
222
+ var newDestClientPath = path_1.default.join(newDestFolder, clientPath);
223
+ var newDestClientReduxPath = resolve(newDestClientPath + clientReduxPath);
224
+ var newDestClientStyledPath = resolve(newDestClientPath + clientStyledPath);
225
+ var newDestClientStyledLayoutPath = resolve(newDestClientStyledPath + clientStyledLayoutPath);
226
+ var newDestClientUtilsPath = resolve(newDestClientPath + clientUtilsPath);
227
+ var newDestClientLayoutPath = resolve(newDestClientPath + clientLayoutPath);
228
+ mkdirSync(newDestClientPath);
229
+ mkdirSync(newDestClientReduxPath);
230
+ mkdirSync(newDestClientStyledPath);
231
+ mkdirSync(newDestClientUtilsPath);
232
+ mkdirSync(newDestClientLayoutPath);
233
+ mkdirSync(newDestClientStyledLayoutPath);
234
+ destClientReduxReducersAllPath = resolve(newDestClientReduxPath + clientReduxReducersPath);
235
+ destClientReduxStorePath = resolve(newDestClientReduxPath + clientReduxStorePath);
236
+ destClientLayoutIndexPath = resolve(newDestClientLayoutPath + clientLayoutIndexPath);
237
+ destClientStyledLayoutIndexPath = resolve(newDestClientStyledLayoutPath + clientStyledLayoutIndexPath);
238
+ destClientStyledCommonPath = resolve(newDestClientStyledPath + clientStyledCommonPath);
239
+ destClientUtilsCommonPath = resolve(newDestClientUtilsPath + clientUtilsCommonPath);
240
+ destClientUtilsFetchPath = resolve(newDestClientUtilsPath + clientUtilsFetchPath);
241
+ destClientUtilsCookiePath = resolve(newDestClientUtilsPath + clientUtilsCookiePath);
242
+ destClientUtilsSsoPath = resolve(newDestClientUtilsPath + clientUtilsSsoPath);
243
+ destClientUtilsMenuPath = resolve(newDestClientUtilsPath + clientUtilsMenuPath);
244
+ }
245
+ copyFileSync(sourceClientReduxStorePath, destClientReduxStorePath, upgradeFlag);
246
+ copyFileSync(sourceClientStyledCommonPath, destClientStyledCommonPath, upgradeFlag);
247
+ copyFileSync(sourceClientStyledLayoutIndexPath, destClientStyledLayoutIndexPath, upgradeFlag);
248
+ copyFileSync(sourceClientUtilsCookiePath, destClientUtilsCookiePath, upgradeFlag);
249
+ copyFileSync(sourceClientUtilsSsoPath, destClientUtilsSsoPath, upgradeFlag);
250
+ copyFileSync(sourceClientUtilsCommonPath, destClientUtilsCommonPath, upgradeFlag);
251
+ copyFileSync(sourceClientUtilsFetchPath, destClientUtilsFetchPath, upgradeFlag);
252
+ copyFileSync(sourceClientLayoutIndexPath, destClientLayoutIndexPath, upgradeFlag);
253
+ copyFileSync(sourceClientReduxReducersAllPath, destClientReduxReducersAllPath);
254
+ copyFileSync(sourceClientUtilsMenuPath, destClientUtilsMenuPath);
255
+ };
256
+ var initPagesFiles = function () {
257
+ var pageIndexPath = '/index.tsx';
258
+ var pageAppPath = '/_app.tsx';
259
+ var pageDocumentPath = '/_document.tsx';
260
+ var pageLoginPath = '/login.tsx';
261
+ var sourcePagesIndexPath = resolve(sourcePagesPath + pageIndexPath);
262
+ var sourcePagesAppPath = resolve(sourcePagesPath + pageAppPath);
263
+ var sourcePagesDocumentPath = resolve(sourcePagesPath + pageDocumentPath);
264
+ var sourcePagesLoginPath = resolve(sourcePagesPath + pageLoginPath);
265
+ var destPagesIndexPath = resolve(destPagesPath + pageIndexPath);
266
+ var destPagesAppPath = resolve(destPagesPath + pageAppPath);
267
+ var destPagesDocumentPath = resolve(destPagesPath + pageDocumentPath);
268
+ var destPagesLoginPath = resolve(destPagesPath + pageLoginPath);
269
+ if (dictionary === '') {
270
+ mkdirSync(destPagesPath);
271
+ }
272
+ else {
273
+ var newDestPagesPath = path_1.default.join(newDestFolder, pagesPath);
274
+ mkdirSync(newDestPagesPath);
275
+ destPagesIndexPath = resolve(newDestPagesPath + pageIndexPath);
276
+ destPagesAppPath = resolve(newDestPagesPath + pageAppPath);
277
+ destPagesDocumentPath = resolve(newDestPagesPath + pageDocumentPath);
278
+ destPagesLoginPath = resolve(newDestPagesPath + pageLoginPath);
279
+ }
280
+ copyFileSync(sourcePagesIndexPath, destPagesIndexPath, upgradeFlag);
281
+ copyFileSync(sourcePagesAppPath, destPagesAppPath, upgradeFlag);
282
+ copyFileSync(sourcePagesDocumentPath, destPagesDocumentPath, upgradeFlag);
283
+ copyFileSync(sourcePagesLoginPath, destPagesLoginPath, upgradeFlag);
284
+ };
285
+ var initServerFiles = function () {
286
+ var serverRestPath = restPath;
287
+ var serverApisPath = apisPath;
288
+ var serverApisSsoPath = '/sso.js';
289
+ var serverUtilsPath = utilsPath;
290
+ var serverUtilsCommonPath = '/common.js';
291
+ // 仍旧使用 generation/server/rest.js
292
+ var sourceServerRestPath = resolve(sourceServerPathGeneration + serverRestPath);
293
+ // 仍旧使用 generation/server/utils/common.js
294
+ var sourceServerUtilsCommonPath = resolve(sourceServerPathGeneration + serverUtilsPath + serverUtilsCommonPath);
295
+ var sourceServerApisSsoPath = resolve(sourceServerPath + serverApisPath + serverApisSsoPath);
296
+ var destServerApisSsoPath = resolve(destServerApisPath + serverApisSsoPath);
297
+ var destServerUtilsCommonPath = resolve(destServerUtilsPath + serverUtilsCommonPath);
298
+ if (dictionary === '') {
299
+ mkdirSync(destServerPath);
300
+ mkdirSync(destServerApisPath);
301
+ mkdirSync(destServerUtilsPath);
302
+ }
303
+ else {
304
+ var newDestServerPath = path_1.default.join(newDestFolder, serverPath);
305
+ var newDestServerApisPath = resolve(newDestServerPath + serverApisPath);
306
+ var newDestServerUtilsPath = resolve(newDestServerPath + serverUtilsPath);
307
+ mkdirSync(newDestServerPath);
308
+ mkdirSync(newDestServerApisPath);
309
+ mkdirSync(newDestServerUtilsPath);
310
+ destServerRestPath = resolve(newDestServerPath + serverRestPath);
311
+ destServerApisSsoPath = resolve(newDestServerApisPath + serverApisSsoPath);
312
+ destServerUtilsCommonPath = resolve(newDestServerUtilsPath + serverUtilsCommonPath);
313
+ }
314
+ copyFileSync(sourceServerApisSsoPath, destServerApisSsoPath, upgradeFlag);
315
+ copyFileSync(sourceServerUtilsCommonPath, destServerUtilsCommonPath, upgradeFlag);
316
+ copyFileSync(sourceServerRestPath, destServerRestPath);
317
+ };
318
+ var initPublicFiles = function () {
319
+ var publicImagesPath = '/images';
320
+ var publicImagesZhizuotuPath = '/zhizuotu_1.png';
321
+ var publicSlbHealthcheckPath = slbHealthCheckPath;
322
+ var destPublicImagesPath = resolve(destPublicPath + publicImagesPath);
323
+ var sourcePublicImages1Path = resolve(sourcePublicPath + publicImagesPath + publicImagesZhizuotuPath);
324
+ var sourcePublicHealthCheckPath = resolve(sourcePublicPath + publicSlbHealthcheckPath);
325
+ var destPublicImages1Path = resolve(destPublicImagesPath + publicImagesZhizuotuPath);
326
+ if (dictionary === '') {
327
+ mkdirSync(destPublicPath);
328
+ mkdirSync(destPublicImagesPath);
329
+ }
330
+ else {
331
+ var newDestPublicPath = path_1.default.join(newDestFolder, publicPath);
332
+ var newDestPublicImagesPath = resolve(newDestPublicPath + publicImagesPath);
333
+ mkdirSync(newDestPublicPath);
334
+ mkdirSync(newDestPublicImagesPath);
335
+ destPublicHealthCheckPath = resolve(newDestPublicPath + publicSlbHealthcheckPath);
336
+ destPublicImages1Path = resolve(newDestPublicImagesPath + publicImagesZhizuotuPath);
337
+ }
338
+ copyFileSync(sourcePublicHealthCheckPath, destPublicHealthCheckPath, upgradeFlag);
339
+ copyFileSync(sourcePublicImages1Path, destPublicImages1Path, upgradeFlag);
340
+ };
341
+ var initScriptsFiles = function () {
342
+ var scriptsStartupPath = '/startup.sh';
343
+ var scriptsShutdownPath = '/shutdown.sh';
344
+ var sourceScriptsStartupPath = resolve(sourceScriptsPath + scriptsStartupPath);
345
+ var sourceScriptsShutdownPath = resolve(sourceScriptsPath + scriptsShutdownPath);
346
+ var destScriptsStartupPath = resolve(destScriptsPath + scriptsStartupPath);
347
+ var destScriptsShutdownPath = resolve(destScriptsPath + scriptsShutdownPath);
348
+ if (dictionary === '') {
349
+ mkdirSync(destScriptsPath);
350
+ }
351
+ else {
352
+ var newDestScriptsPath = path_1.default.join(newDestFolder, scriptsPath);
353
+ mkdirSync(newDestScriptsPath);
354
+ destScriptsStartupPath = resolve(newDestScriptsPath + scriptsStartupPath);
355
+ destScriptsShutdownPath = resolve(newDestScriptsPath + scriptsShutdownPath);
356
+ }
357
+ copyFileSync(sourceScriptsStartupPath, destScriptsStartupPath);
358
+ copyFileSync(sourceScriptsShutdownPath, destScriptsShutdownPath);
359
+ };
360
+ var initRootFiles = function () {
361
+ var rootNextConfigPath = '/next.config.js';
362
+ var rootMysqlConfigPath = '/mysql.config.js';
363
+ var rootProjectConfigPath = '/project.config.js';
364
+ var rootPackagePath = packagePath;
365
+ var rootTsconfigPath = '/tsconfig.json';
366
+ var rootBabelrcPath = '/.babelrc';
367
+ var rootGitignorePathSource = '/gitignore';
368
+ var rootGitignorePath = '/.gitignore';
369
+ var rootNextEnvPathSource = '../next-env.d.ts';
370
+ var rootNextEnvPath = '/next-env.d.ts';
371
+ var rootReadmePath = '/README.md';
372
+ var rootAppConfigPathSource = '../app.config.js';
373
+ var rootAppConfigPath = '/app.config.js';
374
+ var rootAppPath = '/app.js';
375
+ var sourceNextConfigPath = resolve(sourceGenerationPath + rootNextConfigPath);
376
+ var sourceMysqlConfigPath = resolve(sourceGenerationPath + rootMysqlConfigPath);
377
+ var sourceProjectConfigPath = resolve(sourceGenerationPath + rootProjectConfigPath);
378
+ var sourceTsConfigPath = resolve(sourceGenerationPath + rootTsconfigPath);
379
+ var sourceBabelrcPath = path_1.default.join(sourceGenerationPath, rootBabelrcPath);
380
+ var sourceGitignorePath = resolve(sourceGenerationPath + rootGitignorePathSource);
381
+ var sourceNextEnvPath = path_1.default.join(sourceFolder, rootNextEnvPathSource);
382
+ var sourceReadmePath = resolve(sourceGenerationPath + rootReadmePath);
383
+ var sourceAppConfigPath = path_1.default.join(sourceFolder, rootAppConfigPathSource);
384
+ var sourceAppath = resolve(sourceGenerationPath + rootAppPath);
385
+ var sourcePackagePath = resolve(sourceGenerationPath + rootPackagePath);
386
+ var destNextConfigPath = resolve(destFolder + rootNextConfigPath);
387
+ var destMysqlConfigPath = resolve(destFolder + rootMysqlConfigPath);
388
+ var destProjectConfigPath = resolve(destFolder + rootProjectConfigPath);
389
+ var destTsConfigPath = resolve(destFolder + rootTsconfigPath);
390
+ var destBabelrcPath = resolve(destFolder + rootBabelrcPath);
391
+ var destGitignorePath = resolve(destFolder + rootGitignorePath);
392
+ var destNextEnvPath = resolve(destFolder + rootNextEnvPath);
393
+ var destReadmePath = resolve(destFolder + rootReadmePath);
394
+ var destAppConfigPath = resolve(destFolder + rootAppConfigPath);
395
+ var destAppath = resolve(destFolder + rootAppPath);
396
+ if (dictionary !== '') {
397
+ destNextConfigPath = resolve(newDestFolder + rootNextConfigPath);
398
+ destMysqlConfigPath = resolve(newDestFolder + rootMysqlConfigPath);
399
+ destProjectConfigPath = resolve(newDestFolder + rootProjectConfigPath);
400
+ destTsConfigPath = resolve(newDestFolder + rootTsconfigPath);
401
+ destBabelrcPath = resolve(newDestFolder + rootBabelrcPath);
402
+ destGitignorePath = resolve(newDestFolder + rootGitignorePath);
403
+ destNextEnvPath = resolve(newDestFolder + rootNextEnvPath);
404
+ destReadmePath = resolve(newDestFolder + rootReadmePath);
405
+ destAppConfigPath = resolve(newDestFolder + rootAppConfigPath);
406
+ destAppath = resolve(newDestFolder + rootAppPath);
407
+ destPackagePath = resolve(newDestFolder + rootPackagePath);
408
+ }
409
+ copyFileSync(sourceNextConfigPath, destNextConfigPath, upgradeFlag);
410
+ copyFileSync(sourceMysqlConfigPath, destMysqlConfigPath, upgradeFlag);
411
+ copyFileSync(sourceProjectConfigPath, destProjectConfigPath, upgradeFlag);
412
+ copyFileSync(sourcePackagePath, destPackagePath, upgradeFlag);
413
+ copyFileSync(sourceTsConfigPath, destTsConfigPath);
414
+ copyFileSync(sourceBabelrcPath, destBabelrcPath);
415
+ copyFileSync(sourceGitignorePath, destGitignorePath);
416
+ copyFileSync(sourceNextEnvPath, destNextEnvPath);
417
+ copyFileSync(sourceReadmePath, destReadmePath);
418
+ copyFileSync(sourceAppConfigPath, destAppConfigPath);
419
+ copyFileSync(sourceAppath, destAppath);
420
+ };
421
+ initClientFiles();
422
+ initPagesFiles();
423
+ initServerFiles();
424
+ initPublicFiles();
425
+ initScriptsFiles();
426
+ initRootFiles();
427
+ if (!isLocal && !upgradeFlag) {
428
+ if (dictionary !== '') {
429
+ shelljs_1.default.sed('-i', eval('/nsgm-cli-project/'), dictionary + '-project', destPackagePath);
430
+ shelljs_1.default.sed('-i', eval('/NSGM-CLI/'), dictionary, destPublicHealthCheckPath);
431
+ shelljs_1.default.exec('cd ' + dictionary + ' && npm install --save nsgm-cli');
432
+ shelljs_1.default.exec('cd ' + dictionary + ' && npm install --save-dev @types/node');
433
+ shelljs_1.default.exec('cd ' + dictionary + ' && npm install --save-dev @types/react@18.0.1');
434
+ shelljs_1.default.exec('cd ' + dictionary + ' && npm install --save-dev @types/lodash');
435
+ }
436
+ else {
437
+ shelljs_1.default.sed('-i', eval('/nsgm-cli-project/'), path_1.default.basename(destFolder) + '-project', destPackagePath);
438
+ shelljs_1.default.sed('-i', eval('/NSGM-CLI/'), path_1.default.basename(destFolder), destPublicHealthCheckPath);
439
+ shelljs_1.default.exec('npm install --save nsgm-cli');
440
+ shelljs_1.default.exec('npm install --save-dev @types/node');
441
+ shelljs_1.default.exec('npm install --save-dev @types/react@18.0.1');
442
+ shelljs_1.default.exec('npm install --save-dev @types/lodash');
443
+ }
444
+ }
445
+ console.log('initFiles finished');
446
+ };
447
+ exports.initFiles = initFiles;
448
+ var createFiles = function (controller, action) {
449
+ console.log('createFiles', sourceFolder, destFolder, isLocal, controller, action);
450
+ mkdirSync(destClientPath);
451
+ mkdirSync(destServerPath);
452
+ mkdirSync(destPagesPath);
453
+ // pages
454
+ var sourcePagesActionPath = resolve(sourcePagesPath + '/template/manage.tsx');
455
+ var destPagesControllerPath = resolve(destPagesPath + '/' + controller);
456
+ var destPagesActionPath = resolve(destPagesControllerPath + '/' + action + '.tsx');
457
+ mkdirSync(destPagesControllerPath);
458
+ copyFileSync(sourcePagesActionPath, destPagesActionPath);
459
+ console.log('pages finished');
460
+ // client redux
461
+ var destClientReduxControllerPath = resolve(destClientReduxPath + '/' + controller);
462
+ var destClientReduxControllerActionPath = resolve(destClientReduxControllerPath + '/' + action);
463
+ mkdirSync(destClientReduxPath);
464
+ mkdirSync(destClientReduxControllerPath);
465
+ mkdirSync(destClientReduxControllerActionPath);
466
+ var sourceClientReduxActionsPath = resolve(sourceClientPath + '/redux/template/manage/actions.ts');
467
+ var sourceClientReduxReducersPath = resolve(sourceClientPath + '/redux/template/manage/reducers.ts');
468
+ var sourceClientReduxTypesPath = resolve(sourceClientPath + '/redux/template/manage/types.ts');
469
+ var destClientReduxActionsPath = resolve(destClientReduxControllerActionPath + '/actions.ts');
470
+ var destClientReduxReducersPath = resolve(destClientReduxControllerActionPath + '/reducers.ts');
471
+ var destClientReduxTypesPath = resolve(destClientReduxControllerActionPath + '/types.ts');
472
+ copyFileSync(sourceClientReduxActionsPath, destClientReduxActionsPath);
473
+ copyFileSync(sourceClientReduxReducersPath, destClientReduxReducersPath);
474
+ copyFileSync(sourceClientReduxTypesPath, destClientReduxTypesPath);
475
+ console.log('client redux finished');
476
+ // client service
477
+ var sourceClientActionPath = resolve(sourceClientPath + '/service/template/manage.ts');
478
+ var destClientServiceControllerPath = resolve(destClientServicePath + '/' + controller);
479
+ var destClientActionPath = resolve(destClientServiceControllerPath + '/' + action + '.ts');
480
+ mkdirSync(destClientServicePath);
481
+ mkdirSync(destClientServiceControllerPath);
482
+ copyFileSync(sourceClientActionPath, destClientActionPath);
483
+ console.log('client service finished');
484
+ // client styled
485
+ var sourceClientStyledActionPath = resolve(sourceClientPath + '/styled/template/manage.ts');
486
+ var destClientStyledControllerPath = resolve(destClientStyledPath + '/' + controller);
487
+ mkdirSync(destClientStyledPath);
488
+ mkdirSync(destClientStyledControllerPath);
489
+ var destClientStyledActionPath = resolve(destClientStyledControllerPath + '/' + action + '.ts');
490
+ copyFileSync(sourceClientStyledActionPath, destClientStyledActionPath);
491
+ console.log('client styled finished');
492
+ // server modules
493
+ var sourceServerModulesResolverPath = resolve(sourceServerPath + '/modules/template/resolver.js');
494
+ var sourceServerModulesSchemaPath = resolve(sourceServerPath + '/modules/template/schema.js');
495
+ var destServerModulesControllerPath = resolve(destServerModulesPath + '/' + controller);
496
+ mkdirSync(destServerModulesPath);
497
+ mkdirSync(destServerModulesControllerPath);
498
+ var destServerModulesResolverPath = resolve(destServerModulesControllerPath + '/resolver.js');
499
+ var destServerModulesSchemaPath = resolve(destServerModulesControllerPath + '/schema.js');
500
+ copyFileSync(sourceServerModulesResolverPath, destServerModulesResolverPath);
501
+ copyFileSync(sourceServerModulesSchemaPath, destServerModulesSchemaPath);
502
+ console.log('server modules finished');
503
+ // server apis
504
+ var sourceServerApisControllerPath = resolve(sourceServerPath + '/apis/template.js');
505
+ mkdirSync(destServerApisPath);
506
+ var destServerApisControllerPath = resolve(destServerApisPath + '/' + controller + '.js');
507
+ copyFileSync(sourceServerApisControllerPath, destServerApisControllerPath);
508
+ console.log('server apis finished');
509
+ // server sql
510
+ var sourceServerSqlControllerPath = resolve(sourceServerPath + '/sql/template.sql');
511
+ mkdirSync(destServerSqlPath);
512
+ var destServerSqlControllerPath = resolve(destServerSqlPath + '/' + controller + '.sql');
513
+ copyFileSync(sourceServerSqlControllerPath, destServerSqlControllerPath);
514
+ console.log('server sql finished');
515
+ // replace dest files
516
+ handleReplace({
517
+ regex: 'template',
518
+ replacement: controller,
519
+ paths: [
520
+ destPagesActionPath,
521
+ destClientActionPath,
522
+ destClientReduxActionsPath,
523
+ destClientReduxReducersPath,
524
+ destServerModulesResolverPath,
525
+ destServerModulesSchemaPath,
526
+ destServerApisControllerPath
527
+ ]
528
+ });
529
+ handleReplace({
530
+ regex: 'Template',
531
+ replacement: firstUpperCase(controller),
532
+ paths: [
533
+ destPagesActionPath,
534
+ destClientActionPath,
535
+ destClientReduxActionsPath,
536
+ destServerModulesSchemaPath,
537
+ destServerApisControllerPath
538
+ ]
539
+ });
540
+ handleReplace({
541
+ regex: 'TEMPLATE',
542
+ replacement: controller.toUpperCase(),
543
+ paths: [destClientReduxActionsPath, destClientReduxReducersPath, destClientReduxTypesPath]
544
+ });
545
+ handleReplace({
546
+ regex: 'manage',
547
+ replacement: action,
548
+ paths: [destPagesActionPath, destClientReduxActionsPath]
549
+ });
550
+ handleReplace({
551
+ regex: 'Manage',
552
+ replacement: firstUpperCase(action),
553
+ paths: [destPagesActionPath, destClientReduxReducersPath]
554
+ });
555
+ console.log('replace dest files finished');
556
+ // special replace dest files
557
+ var optionsArr = [
558
+ {
559
+ from: /\n\s*\n/,
560
+ to: '\nimport { ' +
561
+ controller +
562
+ firstUpperCase(action) +
563
+ "Reducer } from './" +
564
+ controller +
565
+ '/' +
566
+ action +
567
+ "/reducers'\n\n",
568
+ files: [destClientReduxReducersAllPath]
569
+ },
570
+ {
571
+ from: /Reducer,\s*\n/,
572
+ to: 'Reducer,\n ' +
573
+ controller +
574
+ firstUpperCase(action) +
575
+ ': ' +
576
+ controller +
577
+ firstUpperCase(action) +
578
+ 'Reducer,\n',
579
+ files: [destClientReduxReducersAllPath]
580
+ },
581
+ {
582
+ from: /'(.\/apis\/template.*?)'\)\s*\n/,
583
+ to: "'./apis/template')\nconst " + controller + " = require('./apis/" + controller + "')\n",
584
+ files: [destServerRestPath]
585
+ },
586
+ {
587
+ from: /template\)\s*\n/,
588
+ to: "template)\nrouter.use('/" + controller + "', " + controller + ')\n',
589
+ files: [destServerRestPath]
590
+ },
591
+ {
592
+ from: /null\s*\n/,
593
+ to: 'null\n },\n {\n // ' +
594
+ controller +
595
+ '_' +
596
+ action +
597
+ "_start\n key: (++key).toString(),\n text: '" +
598
+ controller +
599
+ "',\n url: '/" +
600
+ controller +
601
+ '/' +
602
+ action +
603
+ "',\n icon: <SolutionOutlined rev={undefined} />,\n " +
604
+ "subMenus: [\n {\n key: key + '_1',\n text: '" +
605
+ action +
606
+ "',\n url: '/" +
607
+ controller +
608
+ '/' +
609
+ action +
610
+ "'\n }\n ]\n // " +
611
+ controller +
612
+ '_' +
613
+ action +
614
+ '_end\n',
615
+ files: [destClientUtilsMenuPath]
616
+ }
617
+ ];
618
+ if (isLocal) {
619
+ optionsArr.push({
620
+ from: /'nsgm-cli'\)/,
621
+ to: "'../../../index')",
622
+ files: [destServerModulesResolverPath]
623
+ });
624
+ }
625
+ shelljs_1.default.sed('-i', eval('/.*' + controller + firstUpperCase(action) + 'Reducer.*/'), '', destClientReduxReducersAllPath);
626
+ shelljs_1.default.sed('-i', eval('/.*' + controller + '.*/'), '', destServerRestPath);
627
+ shelljs_1.default.sed('-i', eval('/template/'), controller, destServerSqlControllerPath);
628
+ shelljs_1.default.sed('-i', eval('/crm_demo/'), mysqlDatabase, destServerSqlControllerPath);
629
+ shelljs_1.default.exec('mysql -u' +
630
+ mysqlUser +
631
+ ' -p' +
632
+ mysqlPassword +
633
+ ' -h' +
634
+ mysqlHost +
635
+ ' -P' +
636
+ mysqlPort +
637
+ ' < ' +
638
+ destServerSqlControllerPath);
639
+ setTimeout(function () {
640
+ replaceInFileAll(optionsArr, 0, function () {
641
+ console.log('special replace dest files finished');
642
+ });
643
+ }, 1000);
644
+ };
645
+ exports.createFiles = createFiles;
646
+ var deleteFiles = function (controller, action, deleteDBFlag) {
647
+ if (deleteDBFlag === void 0) { deleteDBFlag = false; }
648
+ console.log('deleteFiles', sourceFolder, destFolder, isLocal, controller, action, deleteDBFlag);
649
+ // pages
650
+ var destPagesControllerPath = resolve(destPagesPath + '/' + controller);
651
+ // client redux
652
+ var destClientReduxControllerPath = resolve(destClientReduxPath + '/' + controller);
653
+ // client service
654
+ var destClientServiceControllerPath = resolve(destClientServicePath + '/' + controller);
655
+ // client styled
656
+ var destClientStyledControllerPath = resolve(destClientStyledPath + '/' + controller);
657
+ // server modules
658
+ var destServerModulesControllerPath = resolve(destServerModulesPath + '/' + controller);
659
+ // server apis
660
+ var destServerApisControllerPath = resolve(destServerApisPath + '/' + controller + '.js');
661
+ // server sql
662
+ var destServerSqlControllerPath = resolve(destServerSqlPath + '/' + controller + '.sql');
663
+ if (action === 'all') {
664
+ rmdirSync(destPagesControllerPath);
665
+ rmdirSync(destClientReduxControllerPath);
666
+ rmdirSync(destClientServiceControllerPath);
667
+ rmdirSync(destClientStyledControllerPath);
668
+ rmdirSync(destServerModulesControllerPath);
669
+ rmFileSync(destServerApisControllerPath);
670
+ shelljs_1.default.sed('-i', eval('/.*' + controller + '.*' + 'Reducer.*/'), '', destClientReduxReducersAllPath);
671
+ shelljs_1.default.sed('-i', eval('/.*' + controller + '.*/'), '', destServerRestPath);
672
+ shelljs_1.default.sed('-i', eval('/.*' + controller + '_.*_start.*/'), ' /*', destClientUtilsMenuPath);
673
+ shelljs_1.default.sed('-i', eval('/.*' + controller + '_.*_end.*/'), ' */', destClientUtilsMenuPath);
674
+ if (deleteDBFlag) {
675
+ shelljs_1.default.sed('-i', eval('/' + mysqlDatabase + ';/'), mysqlDatabase + ';\nDROP TABLE `' + controller + '`;\n/*', destServerSqlControllerPath);
676
+ shelljs_1.default.sed('-i', eval('/utf8mb4;/'), 'utf8mb4;\n*/', destServerSqlControllerPath);
677
+ shelljs_1.default.exec('mysql -u' +
678
+ mysqlUser +
679
+ ' -p' +
680
+ mysqlPassword +
681
+ ' -h' +
682
+ mysqlHost +
683
+ ' -P' +
684
+ mysqlPort +
685
+ ' < ' +
686
+ destServerSqlControllerPath);
687
+ }
688
+ rmFileSync(destServerSqlControllerPath);
689
+ var optionsArr_1 = [
690
+ {
691
+ from: /\n\s*\n/,
692
+ to: '\n\n',
693
+ files: [destClientReduxReducersAllPath]
694
+ },
695
+ {
696
+ from: /Reducer,\s*\n/,
697
+ to: 'Reducer,\n',
698
+ files: [destClientReduxReducersAllPath]
699
+ },
700
+ {
701
+ from: /'(.\/apis\/template.*?)'\)\s*\n/,
702
+ to: "'./apis/template')\n\n",
703
+ files: [destServerRestPath]
704
+ },
705
+ {
706
+ from: /template\)\s*\n/,
707
+ to: 'template)\n\n',
708
+ files: [destServerRestPath]
709
+ }
710
+ ];
711
+ setTimeout(function () {
712
+ replaceInFileAll(optionsArr_1, 0, function () {
713
+ console.log('special replace dest files finished');
714
+ });
715
+ }, 1000);
716
+ }
717
+ else {
718
+ // pages
719
+ var destPagesActionPath = resolve(destPagesControllerPath + '/' + action + '.tsx');
720
+ // client redux
721
+ var destClientReduxControllerActionPath = resolve(destClientReduxControllerPath + '/' + action);
722
+ // client service
723
+ var destClientActionPath = resolve(destClientServiceControllerPath + '/' + action + '.ts');
724
+ // client styled
725
+ var destClientStyledActionPath = resolve(destClientStyledControllerPath + '/' + action + '.ts');
726
+ rmFileSync(destPagesActionPath);
727
+ rmdirSync(destClientReduxControllerActionPath);
728
+ rmFileSync(destClientActionPath);
729
+ rmFileSync(destClientStyledActionPath);
730
+ shelljs_1.default.sed('-i', eval('/.*' + controller + firstUpperCase(action) + 'Reducer.*/'), '', destClientReduxReducersAllPath);
731
+ var optionsArr_2 = [
732
+ {
733
+ from: /\n\s*\n/,
734
+ to: '\n\n',
735
+ files: [destClientReduxReducersAllPath]
736
+ },
737
+ {
738
+ from: /Reducer,\s*\n/,
739
+ to: 'Reducer,\n',
740
+ files: [destClientReduxReducersAllPath]
741
+ }
742
+ ];
743
+ setTimeout(function () {
744
+ replaceInFileAll(optionsArr_2, 0, function () {
745
+ console.log('special replace dest files finished');
746
+ });
747
+ }, 1000);
748
+ }
749
+ console.log('delFiles finished');
750
+ };
751
+ exports.deleteFiles = deleteFiles;