nsgm-cli 2.1.13 → 2.1.14

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 (113) hide show
  1. package/README.md +370 -155
  2. package/client/components/Button.tsx +3 -5
  3. package/client/components/__tests__/Button.test.tsx +10 -10
  4. package/client/layout/index.tsx +149 -137
  5. package/client/redux/reducers.ts +1 -1
  6. package/client/redux/store.ts +2 -1
  7. package/client/redux/template/manage/actions.ts +77 -88
  8. package/client/redux/template/manage/reducers.ts +25 -37
  9. package/client/redux/template/manage/types.ts +1 -1
  10. package/client/service/template/manage.ts +20 -21
  11. package/client/styled/common.ts +12 -13
  12. package/client/styled/layout/index.ts +19 -19
  13. package/client/styled/template/manage.ts +14 -13
  14. package/client/utils/common.ts +23 -21
  15. package/client/utils/cookie.ts +18 -19
  16. package/client/utils/fetch.ts +64 -100
  17. package/client/utils/menu.tsx +16 -3
  18. package/client/utils/sso.ts +74 -84
  19. package/eslint.config.js +38 -1
  20. package/generation/README.md +25 -6
  21. package/generation/__tests__/example.test.js +41 -0
  22. package/generation/client/utils/menu.tsx +9 -2
  23. package/generation/env.example +3 -0
  24. package/generation/eslint.config.js +112 -0
  25. package/generation/gitignore +6 -1
  26. package/generation/jest.config.js +40 -0
  27. package/generation/package.json +24 -3
  28. package/jest.config.js +23 -6
  29. package/lib/args.js +9 -1
  30. package/lib/cli/app.d.ts +28 -0
  31. package/lib/cli/app.js +99 -0
  32. package/lib/cli/commands/build.d.ts +2 -0
  33. package/lib/cli/commands/build.js +29 -0
  34. package/lib/cli/commands/create.d.ts +2 -0
  35. package/lib/cli/commands/create.js +113 -0
  36. package/lib/cli/commands/delete.d.ts +3 -0
  37. package/lib/cli/commands/delete.js +151 -0
  38. package/lib/cli/commands/export.d.ts +2 -0
  39. package/lib/cli/commands/export.js +42 -0
  40. package/lib/cli/commands/help.d.ts +2 -0
  41. package/lib/cli/commands/help.js +42 -0
  42. package/lib/cli/commands/init.d.ts +2 -0
  43. package/lib/cli/commands/init.js +115 -0
  44. package/lib/cli/commands/server.d.ts +3 -0
  45. package/lib/cli/commands/server.js +26 -0
  46. package/lib/cli/commands/upgrade.d.ts +2 -0
  47. package/lib/cli/commands/upgrade.js +38 -0
  48. package/lib/cli/commands/version.d.ts +2 -0
  49. package/lib/cli/commands/version.js +24 -0
  50. package/lib/cli/index.d.ts +16 -0
  51. package/lib/cli/index.js +33 -0
  52. package/lib/cli/parser.d.ts +22 -0
  53. package/lib/cli/parser.js +115 -0
  54. package/lib/cli/registry.d.ts +33 -0
  55. package/lib/cli/registry.js +81 -0
  56. package/lib/cli/types/project.d.ts +10 -0
  57. package/lib/cli/types/project.js +2 -0
  58. package/lib/cli/types.d.ts +31 -0
  59. package/lib/cli/types.js +20 -0
  60. package/lib/cli/utils/console.d.ts +62 -0
  61. package/lib/cli/utils/console.js +148 -0
  62. package/lib/cli/utils/index.d.ts +2 -0
  63. package/lib/cli/utils/index.js +7 -0
  64. package/lib/cli/utils/prompt.d.ts +83 -0
  65. package/lib/cli/utils/prompt.js +368 -0
  66. package/lib/constants.d.ts +58 -0
  67. package/lib/constants.js +162 -0
  68. package/lib/generate.d.ts +25 -3
  69. package/lib/generate.js +97 -621
  70. package/lib/generate_create.d.ts +9 -0
  71. package/lib/generate_create.js +326 -0
  72. package/lib/generate_delete.d.ts +8 -0
  73. package/lib/generate_delete.js +156 -0
  74. package/lib/generate_init.d.ts +50 -0
  75. package/lib/generate_init.js +492 -0
  76. package/lib/generators/base-generator.d.ts +47 -0
  77. package/lib/generators/base-generator.js +92 -0
  78. package/lib/generators/generator-factory.d.ts +20 -0
  79. package/lib/generators/generator-factory.js +25 -0
  80. package/lib/generators/page-generator.d.ts +41 -0
  81. package/lib/generators/page-generator.js +552 -0
  82. package/lib/generators/resolver-generator.d.ts +12 -0
  83. package/lib/generators/resolver-generator.js +303 -0
  84. package/lib/generators/schema-generator.d.ts +7 -0
  85. package/lib/generators/schema-generator.js +57 -0
  86. package/lib/generators/service-generator.d.ts +7 -0
  87. package/lib/generators/service-generator.js +119 -0
  88. package/lib/generators/sql-generator.d.ts +8 -0
  89. package/lib/generators/sql-generator.js +52 -0
  90. package/lib/index.d.ts +1 -1
  91. package/lib/index.js +14 -173
  92. package/lib/server/csrf.js +9 -16
  93. package/lib/server/db.js +6 -7
  94. package/lib/server/graphql.js +5 -6
  95. package/lib/server/plugins/date.js +1 -1
  96. package/lib/server/utils/graphql-cache.js +3 -3
  97. package/lib/tsconfig.build.tsbuildinfo +1 -1
  98. package/lib/utils/project-config.d.ts +5 -0
  99. package/lib/utils/project-config.js +145 -0
  100. package/lib/utils.js +1 -1
  101. package/next.config.js +12 -8
  102. package/package.json +10 -7
  103. package/pages/_app.tsx +23 -28
  104. package/pages/_document.tsx +39 -19
  105. package/pages/index.tsx +84 -39
  106. package/pages/login.tsx +21 -21
  107. package/pages/template/manage.tsx +114 -89
  108. package/public/fonts/font-awesome.min.css +4 -0
  109. package/public/fonts/fontawesome-webfont.woff +0 -0
  110. package/public/fonts/fontawesome-webfont.woff2 +0 -0
  111. package/public/slbhealthcheck.html +1 -1
  112. package/server/apis/template.js +0 -2
  113. package/generation/eslintrc.js +0 -16
package/lib/generate.js CHANGED
@@ -1,642 +1,118 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.deleteFiles = exports.createFiles = exports.initFiles = void 0;
40
- const path_1 = __importStar(require("path"));
7
+ const path_1 = __importDefault(require("path"));
41
8
  const shelljs_1 = __importDefault(require("shelljs"));
42
- const db_1 = __importDefault(require("./server/db"));
43
9
  const utils_1 = require("./utils");
44
- const { getMysqlConfig } = db_1.default;
45
- const { mysqlOptions } = getMysqlConfig();
46
- const { user: mysqlUser, password: mysqlPassword, host: mysqlHost, port: mysqlPort, database: mysqlDatabase } = mysqlOptions;
47
- const sourceFolder = __dirname;
48
- const destFolder = process.cwd();
49
- const isLocal = sourceFolder === (0, path_1.resolve)(`${destFolder}/lib`);
50
- const generationPath = '../generation';
51
- const clientPathSource = '../client';
52
- const clientPath = './client';
53
- const serverPathSource = '../server';
54
- const serverPath = './server';
55
- const pagesPathSource = '../pages';
56
- const pagesPath = './pages';
57
- const publicPathSource = '../public';
58
- const publicPath = './public';
59
- const scriptsPathSource = '../scripts';
60
- const scriptsPath = './scripts';
61
- const reduxPath = '/redux';
62
- const servicePath = '/service';
63
- const styledPath = '/styled';
64
- const styledLayoutPath = '/layout';
65
- const utilsPath = '/utils';
66
- const layoutPath = '/layout';
67
- const modulesPath = '/modules';
68
- const apisPath = '/apis';
69
- const sqlPath = '/sql';
70
- const utilsMenuPath = '/menu.tsx';
71
- const reduxReducersPath = '/reducers.ts';
72
- const slbHealthCheckPath = '/slbhealthcheck.html';
73
- const packagePath = '/package.json';
74
- const restPath = '/rest.js';
75
- const sourceGenerationPath = path_1.default.join(sourceFolder, generationPath);
76
- const sourceClientPath = path_1.default.join(sourceFolder, clientPathSource);
77
- const sourceClientPathGeneration = path_1.default.join(sourceGenerationPath, clientPath);
78
- const sourceServerPath = path_1.default.join(sourceFolder, serverPathSource);
79
- const sourceServerPathGeneration = path_1.default.join(sourceGenerationPath, serverPath);
80
- const sourcePagesPath = path_1.default.join(sourceFolder, pagesPathSource);
81
- const sourcePublicPath = path_1.default.join(sourceFolder, publicPathSource);
82
- const sourceScriptsPath = path_1.default.join(sourceFolder, scriptsPathSource);
83
- const destClientPath = path_1.default.join(destFolder, clientPath);
84
- const destClientReduxPath = (0, path_1.resolve)(destClientPath + reduxPath);
85
- const destClientServicePath = (0, path_1.resolve)(destClientPath + servicePath);
86
- const destClientStyledPath = (0, path_1.resolve)(destClientPath + styledPath);
87
- const destClientStyledLayoutPath = (0, path_1.resolve)(destClientStyledPath + styledLayoutPath);
88
- const destClientUtilsPath = (0, path_1.resolve)(destClientPath + utilsPath);
89
- const destClientLayoutPath = (0, path_1.resolve)(destClientPath + layoutPath);
90
- const destServerPath = path_1.default.join(destFolder, serverPath);
91
- const destServerModulesPath = (0, path_1.resolve)(destServerPath + modulesPath);
92
- const destServerApisPath = (0, path_1.resolve)(destServerPath + apisPath);
93
- const destServerSqlPath = (0, path_1.resolve)(destServerPath + sqlPath);
94
- const destServerUtilsPath = (0, path_1.resolve)(destServerPath + utilsPath);
95
- const destPagesPath = path_1.default.join(destFolder, pagesPath);
96
- const destPublicPath = path_1.default.join(destFolder, publicPath);
97
- const destScriptsPath = path_1.default.join(destFolder, scriptsPath);
98
- let destClientUtilsMenuPath = (0, path_1.resolve)(destClientUtilsPath + utilsMenuPath);
99
- let destClientReduxReducersAllPath = (0, path_1.resolve)(destClientReduxPath + reduxReducersPath);
100
- let destPublicHealthCheckPath = (0, path_1.resolve)(destPublicPath + slbHealthCheckPath);
101
- let destPackagePath = (0, path_1.resolve)(destFolder + packagePath);
102
- let destServerRestPath = (0, path_1.resolve)(destServerPath + restPath);
103
- const initFiles = (dictionary, upgradeFlag = false) => {
104
- if (isLocal) {
105
- upgradeFlag = false;
106
- }
10
+ const constants_1 = require("./constants");
11
+ const project_config_1 = require("./utils/project-config");
12
+ const generate_init_1 = require("./generate_init");
13
+ const generate_create_1 = require("./generate_create");
14
+ const generate_delete_1 = require("./generate_delete");
15
+ // 常量提取
16
+ const NPM_INSTALL_FLAGS = '--legacy-peer-deps';
17
+ // 辅助函数
18
+ const normalizeDirectory = (dictionary) => {
107
19
  // 禁止绝对路径,强制所有生成目录都在 cwd 下
108
- if (!dictionary || dictionary === '/') {
109
- dictionary = '.';
20
+ if (!dictionary || dictionary === '/' || dictionary.trim() === '') {
21
+ return '.';
110
22
  }
111
- let newDestFolder = destFolder;
112
- if (dictionary !== '') {
113
- newDestFolder = path_1.default.join(destFolder, dictionary);
114
- (0, utils_1.mkdirSync)(newDestFolder);
23
+ return dictionary.trim();
24
+ };
25
+ const installNpmPackages = (targetDir) => {
26
+ try {
27
+ const prefix = targetDir ? `cd ${targetDir} && ` : '';
28
+ console.log('Installing all dependencies from package.json...');
29
+ const installResult = shelljs_1.default.exec(`${prefix}npm install ${NPM_INSTALL_FLAGS}`);
30
+ return installResult.code === 0;
115
31
  }
116
- console.log('initFiles', dictionary === '' ? '.' : dictionary, upgradeFlag);
117
- const initClientFiles = () => {
118
- const clientReduxPath = reduxPath;
119
- const clientReduxReducersPath = reduxReducersPath;
120
- const clientReduxStorePath = '/store.ts';
121
- const clientStyledPath = styledPath;
122
- const clientStyledCommonPath = '/common.ts';
123
- const clientStyledLayoutPath = styledLayoutPath;
124
- const clientStyledLayoutIndexPath = '/index.ts';
125
- const clientUtilsPath = utilsPath;
126
- const clientUtilsCommonPath = '/common.ts';
127
- const clientUtilsFetchPath = '/fetch.ts';
128
- const clientUtilsCookiePath = '/cookie.ts';
129
- const clientUtilsSsoPath = '/sso.ts';
130
- const clientUtilsMenuPath = utilsMenuPath;
131
- const clientLayoutPath = layoutPath;
132
- const clientLayoutIndexPath = '/index.tsx';
133
- const sourceClientReduxReducersAllPath = (0, path_1.resolve)(sourceClientPathGeneration + clientReduxPath + clientReduxReducersPath);
134
- const sourceClientReduxStorePath = (0, path_1.resolve)(sourceClientPath + clientReduxPath + clientReduxStorePath);
135
- const sourceClientLayoutIndexPath = (0, path_1.resolve)(sourceClientPath + clientLayoutPath + clientLayoutIndexPath);
136
- const sourceClientStyledLayoutIndexPath = (0, path_1.resolve)(sourceClientPath + clientStyledPath + clientStyledLayoutPath + clientStyledLayoutIndexPath);
137
- const sourceClientStyledCommonPath = (0, path_1.resolve)(sourceClientPath + clientStyledPath + clientStyledCommonPath);
138
- const sourceClientUtilsCommonPath = (0, path_1.resolve)(sourceClientPath + clientUtilsPath + clientUtilsCommonPath);
139
- const sourceClientUtilsFetchPath = (0, path_1.resolve)(sourceClientPath + clientUtilsPath + clientUtilsFetchPath);
140
- const sourceClientUtilsCookiePath = (0, path_1.resolve)(sourceClientPath + clientUtilsPath + clientUtilsCookiePath);
141
- const sourceClientUtilsSsoPath = (0, path_1.resolve)(sourceClientPath + clientUtilsPath + clientUtilsSsoPath);
142
- const sourceClientUtilsMenuPath = (0, path_1.resolve)(sourceClientPathGeneration + clientUtilsPath + clientUtilsMenuPath);
143
- let destClientReduxStorePath = (0, path_1.resolve)(destClientReduxPath + clientReduxStorePath);
144
- let destClientLayoutIndexPath = (0, path_1.resolve)(destClientLayoutPath + clientLayoutIndexPath);
145
- let destClientStyledLayoutIndexPath = (0, path_1.resolve)(destClientStyledLayoutPath + clientStyledLayoutIndexPath);
146
- let destClientStyledCommonPath = (0, path_1.resolve)(destClientStyledPath + clientStyledCommonPath);
147
- let destClientUtilsCommonPath = (0, path_1.resolve)(destClientUtilsPath + clientUtilsCommonPath);
148
- let destClientUtilsFetchPath = (0, path_1.resolve)(destClientUtilsPath + clientUtilsFetchPath);
149
- let destClientUtilsCookiePath = (0, path_1.resolve)(destClientUtilsPath + clientUtilsCookiePath);
150
- let destClientUtilsSsoPath = (0, path_1.resolve)(destClientUtilsPath + clientUtilsSsoPath);
151
- if (dictionary === '') {
152
- (0, utils_1.mkdirSync)(destClientPath);
153
- (0, utils_1.mkdirSync)(destClientReduxPath);
154
- (0, utils_1.mkdirSync)(destClientStyledPath);
155
- (0, utils_1.mkdirSync)(destClientStyledLayoutPath);
156
- (0, utils_1.mkdirSync)(destClientUtilsPath);
157
- (0, utils_1.mkdirSync)(destClientLayoutPath);
158
- }
159
- else {
160
- const newDestClientPath = path_1.default.join(newDestFolder, clientPath);
161
- const newDestClientReduxPath = (0, path_1.resolve)(newDestClientPath + clientReduxPath);
162
- const newDestClientStyledPath = (0, path_1.resolve)(newDestClientPath + clientStyledPath);
163
- const newDestClientStyledLayoutPath = (0, path_1.resolve)(newDestClientStyledPath + clientStyledLayoutPath);
164
- const newDestClientUtilsPath = (0, path_1.resolve)(newDestClientPath + clientUtilsPath);
165
- const newDestClientLayoutPath = (0, path_1.resolve)(newDestClientPath + clientLayoutPath);
166
- (0, utils_1.mkdirSync)(newDestClientPath);
167
- (0, utils_1.mkdirSync)(newDestClientReduxPath);
168
- (0, utils_1.mkdirSync)(newDestClientStyledPath);
169
- (0, utils_1.mkdirSync)(newDestClientUtilsPath);
170
- (0, utils_1.mkdirSync)(newDestClientLayoutPath);
171
- (0, utils_1.mkdirSync)(newDestClientStyledLayoutPath);
172
- destClientReduxReducersAllPath = (0, path_1.resolve)(newDestClientReduxPath + clientReduxReducersPath);
173
- destClientReduxStorePath = (0, path_1.resolve)(newDestClientReduxPath + clientReduxStorePath);
174
- destClientLayoutIndexPath = (0, path_1.resolve)(newDestClientLayoutPath + clientLayoutIndexPath);
175
- destClientStyledLayoutIndexPath = (0, path_1.resolve)(newDestClientStyledLayoutPath + clientStyledLayoutIndexPath);
176
- destClientStyledCommonPath = (0, path_1.resolve)(newDestClientStyledPath + clientStyledCommonPath);
177
- destClientUtilsCommonPath = (0, path_1.resolve)(newDestClientUtilsPath + clientUtilsCommonPath);
178
- destClientUtilsFetchPath = (0, path_1.resolve)(newDestClientUtilsPath + clientUtilsFetchPath);
179
- destClientUtilsCookiePath = (0, path_1.resolve)(newDestClientUtilsPath + clientUtilsCookiePath);
180
- destClientUtilsSsoPath = (0, path_1.resolve)(newDestClientUtilsPath + clientUtilsSsoPath);
181
- destClientUtilsMenuPath = (0, path_1.resolve)(newDestClientUtilsPath + clientUtilsMenuPath);
182
- }
183
- (0, utils_1.copyFileSync)(sourceClientReduxStorePath, destClientReduxStorePath, upgradeFlag);
184
- (0, utils_1.copyFileSync)(sourceClientStyledCommonPath, destClientStyledCommonPath, upgradeFlag);
185
- (0, utils_1.copyFileSync)(sourceClientStyledLayoutIndexPath, destClientStyledLayoutIndexPath, upgradeFlag);
186
- (0, utils_1.copyFileSync)(sourceClientUtilsCookiePath, destClientUtilsCookiePath, upgradeFlag);
187
- (0, utils_1.copyFileSync)(sourceClientUtilsSsoPath, destClientUtilsSsoPath, upgradeFlag);
188
- (0, utils_1.copyFileSync)(sourceClientUtilsCommonPath, destClientUtilsCommonPath, upgradeFlag);
189
- (0, utils_1.copyFileSync)(sourceClientUtilsFetchPath, destClientUtilsFetchPath, upgradeFlag);
190
- (0, utils_1.copyFileSync)(sourceClientLayoutIndexPath, destClientLayoutIndexPath, upgradeFlag);
191
- (0, utils_1.copyFileSync)(sourceClientReduxReducersAllPath, destClientReduxReducersAllPath);
192
- (0, utils_1.copyFileSync)(sourceClientUtilsMenuPath, destClientUtilsMenuPath);
193
- };
194
- const initPagesFiles = () => {
195
- const pageIndexPath = '/index.tsx';
196
- const pageAppPath = '/_app.tsx';
197
- const pageDocumentPath = '/_document.tsx';
198
- const pageLoginPath = '/login.tsx';
199
- const sourcePagesIndexPath = (0, path_1.resolve)(sourcePagesPath + pageIndexPath);
200
- const sourcePagesAppPath = (0, path_1.resolve)(sourcePagesPath + pageAppPath);
201
- const sourcePagesDocumentPath = (0, path_1.resolve)(sourcePagesPath + pageDocumentPath);
202
- const sourcePagesLoginPath = (0, path_1.resolve)(sourcePagesPath + pageLoginPath);
203
- let destPagesIndexPath = (0, path_1.resolve)(destPagesPath + pageIndexPath);
204
- let destPagesAppPath = (0, path_1.resolve)(destPagesPath + pageAppPath);
205
- let destPagesDocumentPath = (0, path_1.resolve)(destPagesPath + pageDocumentPath);
206
- let destPagesLoginPath = (0, path_1.resolve)(destPagesPath + pageLoginPath);
207
- if (dictionary === '') {
208
- (0, utils_1.mkdirSync)(destPagesPath);
209
- }
210
- else {
211
- const newDestPagesPath = path_1.default.join(newDestFolder, pagesPath);
212
- (0, utils_1.mkdirSync)(newDestPagesPath);
213
- destPagesIndexPath = (0, path_1.resolve)(newDestPagesPath + pageIndexPath);
214
- destPagesAppPath = (0, path_1.resolve)(newDestPagesPath + pageAppPath);
215
- destPagesDocumentPath = (0, path_1.resolve)(newDestPagesPath + pageDocumentPath);
216
- destPagesLoginPath = (0, path_1.resolve)(newDestPagesPath + pageLoginPath);
217
- }
218
- (0, utils_1.copyFileSync)(sourcePagesIndexPath, destPagesIndexPath, upgradeFlag);
219
- (0, utils_1.copyFileSync)(sourcePagesAppPath, destPagesAppPath, upgradeFlag);
220
- (0, utils_1.copyFileSync)(sourcePagesDocumentPath, destPagesDocumentPath, upgradeFlag);
221
- (0, utils_1.copyFileSync)(sourcePagesLoginPath, destPagesLoginPath, upgradeFlag);
222
- };
223
- const initServerFiles = () => {
224
- const serverRestPath = restPath;
225
- const serverApisPath = apisPath;
226
- const serverApisSsoPath = '/sso.js';
227
- const serverUtilsPath = utilsPath;
228
- const serverUtilsCommonPath = '/common.js';
229
- const serverUtilsDBPoolManagerPath = '/db-pool-manager.js';
230
- const sourceServerRestPath = (0, path_1.resolve)(sourceServerPathGeneration + serverRestPath);
231
- const sourceServerUtilsCommonPath = (0, path_1.resolve)(sourceServerPathGeneration + serverUtilsPath + serverUtilsCommonPath);
232
- const sourceServerUtilsDBPoolManagerPath = (0, path_1.resolve)(sourceServerPathGeneration + serverUtilsPath + serverUtilsDBPoolManagerPath);
233
- const sourceServerApisSsoPath = (0, path_1.resolve)(sourceServerPath + serverApisPath + serverApisSsoPath);
234
- let destServerApisSsoPath = (0, path_1.resolve)(destServerApisPath + serverApisSsoPath);
235
- let destServerUtilsCommonPath = (0, path_1.resolve)(destServerUtilsPath + serverUtilsCommonPath);
236
- let destServerUtilsDBPoolManagerPath = (0, path_1.resolve)(destServerUtilsPath + serverUtilsDBPoolManagerPath);
237
- if (dictionary === '') {
238
- (0, utils_1.mkdirSync)(destServerPath);
239
- (0, utils_1.mkdirSync)(destServerApisPath);
240
- (0, utils_1.mkdirSync)(destServerUtilsPath);
241
- }
242
- else {
243
- const newDestServerPath = path_1.default.join(newDestFolder, serverPath);
244
- const newDestServerApisPath = (0, path_1.resolve)(newDestServerPath + serverApisPath);
245
- const newDestServerUtilsPath = (0, path_1.resolve)(newDestServerPath + serverUtilsPath);
246
- (0, utils_1.mkdirSync)(newDestServerPath);
247
- (0, utils_1.mkdirSync)(newDestServerApisPath);
248
- (0, utils_1.mkdirSync)(newDestServerUtilsPath);
249
- destServerRestPath = (0, path_1.resolve)(newDestServerPath + serverRestPath);
250
- destServerApisSsoPath = (0, path_1.resolve)(newDestServerApisPath + serverApisSsoPath);
251
- destServerUtilsCommonPath = (0, path_1.resolve)(newDestServerUtilsPath + serverUtilsCommonPath);
252
- destServerUtilsDBPoolManagerPath = (0, path_1.resolve)(newDestServerUtilsPath + serverUtilsDBPoolManagerPath);
253
- }
254
- (0, utils_1.copyFileSync)(sourceServerApisSsoPath, destServerApisSsoPath, upgradeFlag);
255
- (0, utils_1.copyFileSync)(sourceServerUtilsCommonPath, destServerUtilsCommonPath, upgradeFlag);
256
- (0, utils_1.copyFileSync)(sourceServerUtilsDBPoolManagerPath, destServerUtilsDBPoolManagerPath, upgradeFlag);
257
- (0, utils_1.copyFileSync)(sourceServerRestPath, destServerRestPath);
258
- };
259
- const initPublicFiles = () => {
260
- const publicImagesPath = '/images';
261
- const publicImagesZhizuotuPath = '/zhizuotu_1.png';
262
- const publicSlbHealthcheckPath = slbHealthCheckPath;
263
- const destPublicImagesPath = (0, path_1.resolve)(destPublicPath + publicImagesPath);
264
- const sourcePublicImages1Path = (0, path_1.resolve)(sourcePublicPath + publicImagesPath + publicImagesZhizuotuPath);
265
- const sourcePublicHealthCheckPath = (0, path_1.resolve)(sourcePublicPath + publicSlbHealthcheckPath);
266
- let destPublicImages1Path = (0, path_1.resolve)(destPublicImagesPath + publicImagesZhizuotuPath);
267
- if (dictionary === '') {
268
- (0, utils_1.mkdirSync)(destPublicPath);
269
- (0, utils_1.mkdirSync)(destPublicImagesPath);
270
- }
271
- else {
272
- const newDestPublicPath = path_1.default.join(newDestFolder, publicPath);
273
- const newDestPublicImagesPath = (0, path_1.resolve)(newDestPublicPath + publicImagesPath);
274
- (0, utils_1.mkdirSync)(newDestPublicPath);
275
- (0, utils_1.mkdirSync)(newDestPublicImagesPath);
276
- destPublicHealthCheckPath = (0, path_1.resolve)(newDestPublicPath + publicSlbHealthcheckPath);
277
- destPublicImages1Path = (0, path_1.resolve)(newDestPublicImagesPath + publicImagesZhizuotuPath);
278
- }
279
- (0, utils_1.copyFileSync)(sourcePublicHealthCheckPath, destPublicHealthCheckPath, upgradeFlag);
280
- (0, utils_1.copyFileSync)(sourcePublicImages1Path, destPublicImages1Path, upgradeFlag);
281
- };
282
- const initScriptsFiles = () => {
283
- const scriptsStartupPath = '/startup.sh';
284
- const scriptsShutdownPath = '/shutdown.sh';
285
- const scriptsPasswordPath = '/generate-password-hash.js';
286
- const sourceScriptsStartupPath = (0, path_1.resolve)(sourceScriptsPath + scriptsStartupPath);
287
- const sourceScriptsShutdownPath = (0, path_1.resolve)(sourceScriptsPath + scriptsShutdownPath);
288
- const sourceScriptsPasswordPath = (0, path_1.resolve)(sourceScriptsPath + scriptsPasswordPath);
289
- let destScriptsStartupPath = (0, path_1.resolve)(destScriptsPath + scriptsStartupPath);
290
- let destScriptsShutdownPath = (0, path_1.resolve)(destScriptsPath + scriptsShutdownPath);
291
- let destScriptsPasswordPath = (0, path_1.resolve)(destScriptsPath + scriptsPasswordPath);
292
- if (dictionary === '') {
293
- (0, utils_1.mkdirSync)(destScriptsPath);
294
- }
295
- else {
296
- const newDestScriptsPath = path_1.default.join(newDestFolder, scriptsPath);
297
- (0, utils_1.mkdirSync)(newDestScriptsPath);
298
- destScriptsStartupPath = (0, path_1.resolve)(newDestScriptsPath + scriptsStartupPath);
299
- destScriptsShutdownPath = (0, path_1.resolve)(newDestScriptsPath + scriptsShutdownPath);
300
- destScriptsPasswordPath = (0, path_1.resolve)(newDestScriptsPath + scriptsPasswordPath);
301
- }
302
- (0, utils_1.copyFileSync)(sourceScriptsStartupPath, destScriptsStartupPath);
303
- (0, utils_1.copyFileSync)(sourceScriptsShutdownPath, destScriptsShutdownPath);
304
- (0, utils_1.copyFileSync)(sourceScriptsPasswordPath, destScriptsPasswordPath);
305
- };
306
- const initRootFiles = () => {
307
- const rootNextConfigPath = '/next.config.js';
308
- const rootMysqlConfigPath = '/mysql.config.js';
309
- const rootProjectConfigPath = '/project.config.js';
310
- const rootPackagePath = packagePath;
311
- const rootTsconfigPath = '/tsconfig.json';
312
- const rootGitignorePathSource = '/gitignore';
313
- const rootGitignorePath = '/.gitignore';
314
- const rootEslintrcPathSource = '/eslintrc.js';
315
- const rootEslintrcPath = '/.eslintrc.js';
316
- const rootNextEnvPathSource = '../next-env.d.ts';
317
- const rootNextEnvPath = '/next-env.d.ts';
318
- const rootReadmePath = '/README.md';
319
- const rootAppConfigPathSource = '../app.config.js';
320
- const rootAppConfigPath = '/app.config.js';
321
- const rootAppPath = '/app.js';
322
- const sourceNextConfigPath = (0, path_1.resolve)(sourceGenerationPath + rootNextConfigPath);
323
- const sourceMysqlConfigPath = (0, path_1.resolve)(sourceGenerationPath + rootMysqlConfigPath);
324
- const sourceProjectConfigPath = (0, path_1.resolve)(sourceGenerationPath + rootProjectConfigPath);
325
- const sourceTsConfigPath = (0, path_1.resolve)(sourceGenerationPath + rootTsconfigPath);
326
- const sourceGitignorePath = (0, path_1.resolve)(sourceGenerationPath + rootGitignorePathSource);
327
- const sourceEslintrcPath = (0, path_1.resolve)(sourceGenerationPath + rootEslintrcPathSource);
328
- const sourceNextEnvPath = path_1.default.join(sourceFolder, rootNextEnvPathSource);
329
- const sourceReadmePath = (0, path_1.resolve)(sourceGenerationPath + rootReadmePath);
330
- const sourceAppConfigPath = path_1.default.join(sourceFolder, rootAppConfigPathSource);
331
- const sourceAppath = (0, path_1.resolve)(sourceGenerationPath + rootAppPath);
332
- const sourcePackagePath = (0, path_1.resolve)(sourceGenerationPath + rootPackagePath);
333
- let destNextConfigPath = (0, path_1.resolve)(destFolder + rootNextConfigPath);
334
- let destMysqlConfigPath = (0, path_1.resolve)(destFolder + rootMysqlConfigPath);
335
- let destProjectConfigPath = (0, path_1.resolve)(destFolder + rootProjectConfigPath);
336
- let destTsConfigPath = (0, path_1.resolve)(destFolder + rootTsconfigPath);
337
- let destGitignorePath = (0, path_1.resolve)(destFolder + rootGitignorePath);
338
- let destEslintrcPath = (0, path_1.resolve)(destFolder + rootEslintrcPath);
339
- let destNextEnvPath = (0, path_1.resolve)(destFolder + rootNextEnvPath);
340
- let destReadmePath = (0, path_1.resolve)(destFolder + rootReadmePath);
341
- let destAppConfigPath = (0, path_1.resolve)(destFolder + rootAppConfigPath);
342
- let destAppath = (0, path_1.resolve)(destFolder + rootAppPath);
343
- if (dictionary !== '') {
344
- destNextConfigPath = (0, path_1.resolve)(newDestFolder + rootNextConfigPath);
345
- destMysqlConfigPath = (0, path_1.resolve)(newDestFolder + rootMysqlConfigPath);
346
- destProjectConfigPath = (0, path_1.resolve)(newDestFolder + rootProjectConfigPath);
347
- destTsConfigPath = (0, path_1.resolve)(newDestFolder + rootTsconfigPath);
348
- destGitignorePath = (0, path_1.resolve)(newDestFolder + rootGitignorePath);
349
- destEslintrcPath = (0, path_1.resolve)(newDestFolder + rootEslintrcPath);
350
- destNextEnvPath = (0, path_1.resolve)(newDestFolder + rootNextEnvPath);
351
- destReadmePath = (0, path_1.resolve)(newDestFolder + rootReadmePath);
352
- destAppConfigPath = (0, path_1.resolve)(newDestFolder + rootAppConfigPath);
353
- destAppath = (0, path_1.resolve)(newDestFolder + rootAppPath);
354
- destPackagePath = (0, path_1.resolve)(newDestFolder + rootPackagePath);
355
- }
356
- (0, utils_1.copyFileSync)(sourceNextConfigPath, destNextConfigPath);
357
- (0, utils_1.copyFileSync)(sourceMysqlConfigPath, destMysqlConfigPath);
358
- (0, utils_1.copyFileSync)(sourceProjectConfigPath, destProjectConfigPath);
359
- (0, utils_1.copyFileSync)(sourcePackagePath, destPackagePath);
360
- (0, utils_1.copyFileSync)(sourceTsConfigPath, destTsConfigPath);
361
- (0, utils_1.copyFileSync)(sourceGitignorePath, destGitignorePath);
362
- (0, utils_1.copyFileSync)(sourceEslintrcPath, destEslintrcPath);
363
- (0, utils_1.copyFileSync)(sourceNextEnvPath, destNextEnvPath);
364
- (0, utils_1.copyFileSync)(sourceReadmePath, destReadmePath);
365
- (0, utils_1.copyFileSync)(sourceAppConfigPath, destAppConfigPath);
366
- (0, utils_1.copyFileSync)(sourceAppath, destAppath);
367
- };
368
- initClientFiles();
369
- initPagesFiles();
370
- initServerFiles();
371
- initPublicFiles();
372
- initScriptsFiles();
373
- initRootFiles();
374
- if (!isLocal && !upgradeFlag) {
375
- if (dictionary !== '') {
376
- shelljs_1.default.sed('-i', eval('/nsgm-cli-project/'), `${dictionary}-project`, destPackagePath);
377
- shelljs_1.default.sed('-i', eval('/NSGM-CLI/'), dictionary, destPublicHealthCheckPath);
378
- shelljs_1.default.exec(`cd ${dictionary} && npm install --save nsgm-cli --legacy-peer-deps`);
379
- shelljs_1.default.exec(`cd ${dictionary} && npm install --save-dev @types/node@^20 @types/react@^18 @types/lodash@^4 typescript@^5 --legacy-peer-deps`);
32
+ catch (error) {
33
+ console.error('Failed to install npm packages:', error);
34
+ return false;
35
+ }
36
+ };
37
+ const updateProjectFiles = (projectName, destPackagePath, destPublicHealthCheckPath, skipPackageUpdate = false) => {
38
+ try {
39
+ const cleanProjectName = path_1.default.basename(projectName);
40
+ if (!skipPackageUpdate) {
41
+ console.log(`Updating project name to: ${cleanProjectName}`);
42
+ shelljs_1.default.sed('-i', /nsgm-cli-project/g, `${cleanProjectName}-project`, destPackagePath);
380
43
  }
381
- else {
382
- shelljs_1.default.sed('-i', eval('/nsgm-cli-project/'), `${path_1.default.basename(destFolder)}-project`, destPackagePath);
383
- shelljs_1.default.sed('-i', eval('/NSGM-CLI/'), path_1.default.basename(destFolder), destPublicHealthCheckPath);
384
- shelljs_1.default.exec('npm install --save nsgm-cli --legacy-peer-deps');
385
- shelljs_1.default.exec('npm install --save-dev @types/node@^20 @types/react@^18 @types/lodash@^4 typescript@^5 --legacy-peer-deps');
44
+ shelljs_1.default.sed('-i', /NSGM-CLI/g, cleanProjectName, destPublicHealthCheckPath);
45
+ return true;
46
+ }
47
+ catch (error) {
48
+ console.error('Failed to update project files:', error);
49
+ return false;
50
+ }
51
+ };
52
+ /**
53
+ * 初始化项目文件和目录结构
54
+ * @param dictionary 目标目录名称,空字符串表示当前目录
55
+ * @param upgradeFlag 是否为升级模式,升级模式下不会安装依赖
56
+ * @param projectConfig 项目配置信息(可选)
57
+ */
58
+ const initFiles = (dictionary, upgradeFlag = false, projectConfig) => {
59
+ if (constants_1.isLocal) {
60
+ upgradeFlag = false;
61
+ }
62
+ const normalizedDictionary = normalizeDirectory(dictionary);
63
+ let newDestFolder = constants_1.destFolder;
64
+ if (normalizedDictionary !== '.') {
65
+ newDestFolder = path_1.default.join(constants_1.destFolder, normalizedDictionary);
66
+ (0, utils_1.mkdirSync)(newDestFolder);
67
+ }
68
+ console.log('initFiles', normalizedDictionary === '.' ? '.' : normalizedDictionary, upgradeFlag);
69
+ (0, generate_init_1.initClientFiles)(normalizedDictionary, newDestFolder, upgradeFlag);
70
+ (0, generate_init_1.initPagesFiles)(normalizedDictionary, newDestFolder, upgradeFlag);
71
+ (0, generate_init_1.initServerFiles)(normalizedDictionary, newDestFolder, upgradeFlag);
72
+ const { destPublicHealthCheckPath } = (0, generate_init_1.initPublicFiles)(normalizedDictionary, newDestFolder, upgradeFlag);
73
+ (0, generate_init_1.initScriptsFiles)(normalizedDictionary, newDestFolder);
74
+ const { destPackagePath } = (0, generate_init_1.initRootFiles)(normalizedDictionary, newDestFolder);
75
+ (0, generate_init_1.initTestFiles)(normalizedDictionary, newDestFolder);
76
+ // 如果提供了项目配置,应用到生成的文件中
77
+ if (projectConfig) {
78
+ console.log('应用项目配置...');
79
+ (0, project_config_1.applyProjectConfig)(newDestFolder, projectConfig);
80
+ }
81
+ const installFlag = !upgradeFlag && (!constants_1.isLocal || dictionary.indexOf('..') !== -1);
82
+ if (installFlag) {
83
+ const projectName = normalizedDictionary !== '.' ? normalizedDictionary : path_1.default.basename(constants_1.destFolder);
84
+ // 如果有项目配置,跳过 package.json 的默认更新,因为 applyProjectConfig 已经处理了
85
+ const skipPackageUpdate = !!projectConfig;
86
+ const updateSuccess = updateProjectFiles(projectName, destPackagePath, destPublicHealthCheckPath, skipPackageUpdate);
87
+ const installSuccess = installNpmPackages(normalizedDictionary !== '.' ? normalizedDictionary : undefined);
88
+ if (!updateSuccess || !installSuccess) {
89
+ console.warn('Some operations failed during project initialization');
386
90
  }
387
91
  }
388
92
  console.log('initFiles finished');
389
93
  };
390
94
  exports.initFiles = initFiles;
391
- const createFiles = (controller, action) => {
392
- console.log('createFiles', sourceFolder, destFolder, isLocal, controller, action);
393
- (0, utils_1.mkdirSync)(destClientPath);
394
- (0, utils_1.mkdirSync)(destServerPath);
395
- (0, utils_1.mkdirSync)(destPagesPath);
396
- // pages
397
- const sourcePagesActionPath = (0, path_1.resolve)(`${sourcePagesPath}/template/manage.tsx`);
398
- const destPagesControllerPath = (0, path_1.resolve)(`${destPagesPath}/${controller}`);
399
- const destPagesActionPath = (0, path_1.resolve)(`${destPagesControllerPath}/${action}.tsx`);
400
- (0, utils_1.mkdirSync)(destPagesControllerPath);
401
- (0, utils_1.copyFileSync)(sourcePagesActionPath, destPagesActionPath);
402
- console.log('pages finished');
403
- // client redux
404
- const destClientReduxControllerPath = (0, path_1.resolve)(`${destClientReduxPath}/${controller}`);
405
- const destClientReduxControllerActionPath = (0, path_1.resolve)(`${destClientReduxControllerPath}/${action}`);
406
- (0, utils_1.mkdirSync)(destClientReduxPath);
407
- (0, utils_1.mkdirSync)(destClientReduxControllerPath);
408
- (0, utils_1.mkdirSync)(destClientReduxControllerActionPath);
409
- const sourceClientReduxActionsPath = (0, path_1.resolve)(`${sourceClientPath}/redux/template/manage/actions.ts`);
410
- const sourceClientReduxReducersPath = (0, path_1.resolve)(`${sourceClientPath}/redux/template/manage/reducers.ts`);
411
- const sourceClientReduxTypesPath = (0, path_1.resolve)(`${sourceClientPath}/redux/template/manage/types.ts`);
412
- const destClientReduxActionsPath = (0, path_1.resolve)(`${destClientReduxControllerActionPath}/actions.ts`);
413
- const destClientReduxReducersPath = (0, path_1.resolve)(`${destClientReduxControllerActionPath}/reducers.ts`);
414
- const destClientReduxTypesPath = (0, path_1.resolve)(`${destClientReduxControllerActionPath}/types.ts`);
415
- (0, utils_1.copyFileSync)(sourceClientReduxActionsPath, destClientReduxActionsPath);
416
- (0, utils_1.copyFileSync)(sourceClientReduxReducersPath, destClientReduxReducersPath);
417
- (0, utils_1.copyFileSync)(sourceClientReduxTypesPath, destClientReduxTypesPath);
418
- console.log('client redux finished');
419
- // client service
420
- const sourceClientActionPath = (0, path_1.resolve)(`${sourceClientPath}/service/template/manage.ts`);
421
- const destClientServiceControllerPath = (0, path_1.resolve)(`${destClientServicePath}/${controller}`);
422
- const destClientActionPath = (0, path_1.resolve)(`${destClientServiceControllerPath}/${action}.ts`);
423
- (0, utils_1.mkdirSync)(destClientServicePath);
424
- (0, utils_1.mkdirSync)(destClientServiceControllerPath);
425
- (0, utils_1.copyFileSync)(sourceClientActionPath, destClientActionPath);
426
- console.log('client service finished');
427
- // client styled
428
- const sourceClientStyledActionPath = (0, path_1.resolve)(`${sourceClientPath}/styled/template/manage.ts`);
429
- const destClientStyledControllerPath = (0, path_1.resolve)(`${destClientStyledPath}/${controller}`);
430
- (0, utils_1.mkdirSync)(destClientStyledPath);
431
- (0, utils_1.mkdirSync)(destClientStyledControllerPath);
432
- const destClientStyledActionPath = (0, path_1.resolve)(`${destClientStyledControllerPath}/${action}.ts`);
433
- (0, utils_1.copyFileSync)(sourceClientStyledActionPath, destClientStyledActionPath);
434
- console.log('client styled finished');
435
- // server modules
436
- const sourceServerModulesResolverPath = (0, path_1.resolve)(`${sourceServerPath}/modules/template/resolver.js`);
437
- const sourceServerModulesSchemaPath = (0, path_1.resolve)(`${sourceServerPath}/modules/template/schema.js`);
438
- const destServerModulesControllerPath = (0, path_1.resolve)(`${destServerModulesPath}/${controller}`);
439
- (0, utils_1.mkdirSync)(destServerModulesPath);
440
- (0, utils_1.mkdirSync)(destServerModulesControllerPath);
441
- const destServerModulesResolverPath = (0, path_1.resolve)(`${destServerModulesControllerPath}/resolver.js`);
442
- const destServerModulesSchemaPath = (0, path_1.resolve)(`${destServerModulesControllerPath}/schema.js`);
443
- (0, utils_1.copyFileSync)(sourceServerModulesResolverPath, destServerModulesResolverPath);
444
- (0, utils_1.copyFileSync)(sourceServerModulesSchemaPath, destServerModulesSchemaPath);
445
- console.log('server modules finished');
446
- // server apis
447
- const sourceServerApisControllerPath = (0, path_1.resolve)(`${sourceServerPath}/apis/template.js`);
448
- (0, utils_1.mkdirSync)(destServerApisPath);
449
- const destServerApisControllerPath = (0, path_1.resolve)(`${destServerApisPath}/${controller}.js`);
450
- (0, utils_1.copyFileSync)(sourceServerApisControllerPath, destServerApisControllerPath);
451
- console.log('server apis finished');
452
- // server sql
453
- const sourceServerSqlControllerPath = (0, path_1.resolve)(`${sourceServerPath}/sql/template.sql`);
454
- (0, utils_1.mkdirSync)(destServerSqlPath);
455
- const destServerSqlControllerPath = (0, path_1.resolve)(`${destServerSqlPath}/${controller}.sql`);
456
- (0, utils_1.copyFileSync)(sourceServerSqlControllerPath, destServerSqlControllerPath);
457
- console.log('server sql finished');
458
- // replace dest files
459
- (0, utils_1.handleReplace)({
460
- regex: 'template',
461
- replacement: controller,
462
- paths: [
463
- destPagesActionPath,
464
- destClientActionPath,
465
- destClientReduxActionsPath,
466
- destClientReduxReducersPath,
467
- destServerModulesResolverPath,
468
- destServerModulesSchemaPath,
469
- destServerApisControllerPath
470
- ]
471
- });
472
- (0, utils_1.handleReplace)({
473
- regex: 'Template',
474
- replacement: (0, utils_1.firstUpperCase)(controller),
475
- paths: [
476
- destPagesActionPath,
477
- destClientActionPath,
478
- destClientReduxActionsPath,
479
- destServerModulesSchemaPath,
480
- destServerApisControllerPath
481
- ]
482
- });
483
- (0, utils_1.handleReplace)({
484
- regex: 'TEMPLATE',
485
- replacement: controller.toUpperCase(),
486
- paths: [destClientReduxActionsPath, destClientReduxReducersPath, destClientReduxTypesPath]
487
- });
488
- (0, utils_1.handleReplace)({
489
- regex: 'manage',
490
- replacement: action,
491
- paths: [destPagesActionPath, destClientReduxActionsPath]
492
- });
493
- (0, utils_1.handleReplace)({
494
- regex: 'Manage',
495
- replacement: (0, utils_1.firstUpperCase)(action),
496
- paths: [destPagesActionPath, destClientReduxReducersPath]
497
- });
498
- console.log('replace dest files finished');
499
- // special replace dest files
500
- const optionsArr = [
501
- {
502
- from: /\n\s*\n/,
503
- to: `\nimport { ${controller}${(0, utils_1.firstUpperCase)(action)}Reducer } from './${controller}/${action}/reducers'\n\n`,
504
- files: [destClientReduxReducersAllPath]
505
- },
506
- {
507
- from: /Reducer,\s*\n/,
508
- to: `Reducer,\n ${controller}${(0, utils_1.firstUpperCase)(action)}: ${controller}${(0, utils_1.firstUpperCase)(action)}Reducer,\n`,
509
- files: [destClientReduxReducersAllPath]
510
- },
511
- {
512
- from: /'(.\/apis\/template.*?)'\)\s*\n/,
513
- to: `'./apis/template')\nconst ${controller} = require('./apis/${controller}')\n`,
514
- files: [destServerRestPath]
515
- },
516
- {
517
- from: /template\)\s*\n/,
518
- to: `template)\nrouter.use('/${controller}', ${controller})\n`,
519
- files: [destServerRestPath]
520
- },
521
- {
522
- from: /null\s*\n/,
523
- to: `null\n },\n {\n // ${controller}_${action}_start\n key: (++key).toString(),\n text: '${controller}',\n url: '/${controller}/${action}',\n icon: <SolutionOutlined rev={undefined} />,\n ` +
524
- `subMenus: [\n {\n key: key + '_1',\n text: '${action}',\n url: '/${controller}/${action}'\n }\n ]\n // ${controller}_${action}_end\n`,
525
- files: [destClientUtilsMenuPath]
526
- }
527
- ];
528
- if (isLocal) {
529
- optionsArr.push({
530
- from: /'nsgm-cli'\)/,
531
- to: "'../../../index')",
532
- files: [destServerModulesResolverPath]
533
- });
534
- }
535
- shelljs_1.default.sed('-i', eval(`/.*${controller}${(0, utils_1.firstUpperCase)(action)}Reducer.*/`), '', destClientReduxReducersAllPath);
536
- shelljs_1.default.sed('-i', eval(`/.*${controller}.*/`), '', destServerRestPath);
537
- shelljs_1.default.sed('-i', eval('/template/'), controller, destServerSqlControllerPath);
538
- shelljs_1.default.sed('-i', eval('/crm_demo/'), mysqlDatabase, destServerSqlControllerPath);
539
- shelljs_1.default.exec(`mysql -u${mysqlUser} -p${mysqlPassword} -h${mysqlHost} -P${mysqlPort} < ${destServerSqlControllerPath}`);
540
- setTimeout(() => {
541
- (0, utils_1.replaceInFileAll)(optionsArr, 0, () => {
542
- console.log('special replace dest files finished');
543
- });
544
- }, 1000);
95
+ /**
96
+ * 创建控制器相关文件
97
+ * @param controller 控制器名称
98
+ * @param action 动作名称
99
+ * @param dictionary 目标目录名称,空字符串表示当前目录
100
+ * @param fields 字段定义数组
101
+ */
102
+ const createFiles = (controller, action, dictionary = '', fields) => {
103
+ const normalizedDictionary = normalizeDirectory(dictionary);
104
+ (0, generate_create_1.createFiles)(controller, action, normalizedDictionary, fields);
545
105
  };
546
106
  exports.createFiles = createFiles;
547
- const deleteFiles = (controller, action, deleteDBFlag = false) => {
548
- console.log('deleteFiles', sourceFolder, destFolder, isLocal, controller, action, deleteDBFlag);
549
- // pages
550
- const destPagesControllerPath = (0, path_1.resolve)(`${destPagesPath}/${controller}`);
551
- // client redux
552
- const destClientReduxControllerPath = (0, path_1.resolve)(`${destClientReduxPath}/${controller}`);
553
- // client service
554
- const destClientServiceControllerPath = (0, path_1.resolve)(`${destClientServicePath}/${controller}`);
555
- // client styled
556
- const destClientStyledControllerPath = (0, path_1.resolve)(`${destClientStyledPath}/${controller}`);
557
- // server modules
558
- const destServerModulesControllerPath = (0, path_1.resolve)(`${destServerModulesPath}/${controller}`);
559
- // server apis
560
- const destServerApisControllerPath = (0, path_1.resolve)(`${destServerApisPath}/${controller}.js`);
561
- // server sql
562
- const destServerSqlControllerPath = (0, path_1.resolve)(`${destServerSqlPath}/${controller}.sql`);
563
- if (action === 'all') {
564
- (0, utils_1.rmdirSync)(destPagesControllerPath);
565
- (0, utils_1.rmdirSync)(destClientReduxControllerPath);
566
- (0, utils_1.rmdirSync)(destClientServiceControllerPath);
567
- (0, utils_1.rmdirSync)(destClientStyledControllerPath);
568
- (0, utils_1.rmdirSync)(destServerModulesControllerPath);
569
- (0, utils_1.rmFileSync)(destServerApisControllerPath);
570
- shelljs_1.default.sed('-i', eval(`/.*${controller}.*` + `Reducer.*/`), '', destClientReduxReducersAllPath);
571
- shelljs_1.default.sed('-i', eval(`/.*${controller}.*/`), '', destServerRestPath);
572
- shelljs_1.default.sed('-i', eval(`/.*${controller}_.*_start.*/`), ' /*', destClientUtilsMenuPath);
573
- shelljs_1.default.sed('-i', eval(`/.*${controller}_.*_end.*/`), ' */', destClientUtilsMenuPath);
574
- if (deleteDBFlag) {
575
- shelljs_1.default.sed('-i', eval(`/${mysqlDatabase};/`), `${mysqlDatabase};\nDROP TABLE \`${controller}\`;\n/*`, destServerSqlControllerPath);
576
- shelljs_1.default.sed('-i', eval('/utf8mb4;/'), 'utf8mb4;\n*/', destServerSqlControllerPath);
577
- shelljs_1.default.exec(`mysql -u${mysqlUser} -p${mysqlPassword} -h${mysqlHost} -P${mysqlPort} < ${destServerSqlControllerPath}`);
578
- }
579
- (0, utils_1.rmFileSync)(destServerSqlControllerPath);
580
- const optionsArr = [
581
- {
582
- from: /\n\s*\n/,
583
- to: '\n\n',
584
- files: [destClientReduxReducersAllPath]
585
- },
586
- {
587
- from: /Reducer,\s*\n/,
588
- to: 'Reducer,\n',
589
- files: [destClientReduxReducersAllPath]
590
- },
591
- {
592
- from: /'(.\/apis\/template.*?)'\)\s*\n/,
593
- to: "'./apis/template')\n\n",
594
- files: [destServerRestPath]
595
- },
596
- {
597
- from: /template\)\s*\n/,
598
- to: 'template)\n\n',
599
- files: [destServerRestPath]
600
- }
601
- ];
602
- setTimeout(() => {
603
- (0, utils_1.replaceInFileAll)(optionsArr, 0, () => {
604
- console.log('special replace dest files finished');
605
- });
606
- }, 1000);
607
- }
608
- else {
609
- // pages
610
- const destPagesActionPath = (0, path_1.resolve)(`${destPagesControllerPath}/${action}.tsx`);
611
- // client redux
612
- const destClientReduxControllerActionPath = (0, path_1.resolve)(`${destClientReduxControllerPath}/${action}`);
613
- // client service
614
- const destClientActionPath = (0, path_1.resolve)(`${destClientServiceControllerPath}/${action}.ts`);
615
- // client styled
616
- const destClientStyledActionPath = (0, path_1.resolve)(`${destClientStyledControllerPath}/${action}.ts`);
617
- (0, utils_1.rmFileSync)(destPagesActionPath);
618
- (0, utils_1.rmdirSync)(destClientReduxControllerActionPath);
619
- (0, utils_1.rmFileSync)(destClientActionPath);
620
- (0, utils_1.rmFileSync)(destClientStyledActionPath);
621
- shelljs_1.default.sed('-i', eval(`/.*${controller}${(0, utils_1.firstUpperCase)(action)}Reducer.*/`), '', destClientReduxReducersAllPath);
622
- const optionsArr = [
623
- {
624
- from: /\n\s*\n/,
625
- to: '\n\n',
626
- files: [destClientReduxReducersAllPath]
627
- },
628
- {
629
- from: /Reducer,\s*\n/,
630
- to: 'Reducer,\n',
631
- files: [destClientReduxReducersAllPath]
632
- }
633
- ];
634
- setTimeout(() => {
635
- (0, utils_1.replaceInFileAll)(optionsArr, 0, () => {
636
- console.log('special replace dest files finished');
637
- });
638
- }, 1000);
639
- }
640
- console.log('delFiles finished');
107
+ /**
108
+ * 删除控制器相关文件
109
+ * @param controller 控制器名称
110
+ * @param action 动作名称
111
+ * @param deleteDBFlag 是否删除数据库相关文件
112
+ * @param dictionary 目标目录名称,空字符串表示当前目录
113
+ */
114
+ const deleteFiles = (controller, action, deleteDBFlag = false, dictionary = '') => {
115
+ const normalizedDictionary = normalizeDirectory(dictionary);
116
+ (0, generate_delete_1.deleteFiles)(controller, action, deleteDBFlag, normalizedDictionary);
641
117
  };
642
118
  exports.deleteFiles = deleteFiles;