@gadmin2n/cli 0.0.73

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 (182) hide show
  1. package/.circleci/config.yml +62 -0
  2. package/.claude/settings.local.json +7 -0
  3. package/.github/ISSUE_TEMPLATE/Bug_report.yml +106 -0
  4. package/.github/ISSUE_TEMPLATE/Feature_request.yml +52 -0
  5. package/.github/ISSUE_TEMPLATE/Regression.yml +78 -0
  6. package/.github/ISSUE_TEMPLATE/config.yml +7 -0
  7. package/.github/PULL_REQUEST_TEMPLATE.md +41 -0
  8. package/LICENSE +24 -0
  9. package/README.md +56 -0
  10. package/actions/abstract.action.d.ts +4 -0
  11. package/actions/abstract.action.js +6 -0
  12. package/actions/add.action.d.ts +12 -0
  13. package/actions/add.action.js +129 -0
  14. package/actions/build.action.d.ts +27 -0
  15. package/actions/build.action.js +108 -0
  16. package/actions/generate.action.d.ts +5 -0
  17. package/actions/generate.action.js +95 -0
  18. package/actions/index.d.ts +8 -0
  19. package/actions/index.js +24 -0
  20. package/actions/info.action.d.ts +28 -0
  21. package/actions/info.action.js +129 -0
  22. package/actions/new.action.d.ts +7 -0
  23. package/actions/new.action.js +294 -0
  24. package/actions/prisma.action.d.ts +5 -0
  25. package/actions/prisma.action.js +153 -0
  26. package/actions/start.action.d.ts +9 -0
  27. package/actions/start.action.js +115 -0
  28. package/actions/update.action.d.ts +5 -0
  29. package/actions/update.action.js +26 -0
  30. package/bin/gadmin.d.ts +2 -0
  31. package/bin/gadmin.js +25 -0
  32. package/commands/abstract.command.d.ts +7 -0
  33. package/commands/abstract.command.js +9 -0
  34. package/commands/add.command.d.ts +5 -0
  35. package/commands/add.command.js +43 -0
  36. package/commands/build.command.d.ts +5 -0
  37. package/commands/build.command.js +50 -0
  38. package/commands/command.input.d.ts +25 -0
  39. package/commands/command.input.js +28 -0
  40. package/commands/command.loader.d.ts +5 -0
  41. package/commands/command.loader.js +33 -0
  42. package/commands/generate.command.d.ts +7 -0
  43. package/commands/generate.command.js +105 -0
  44. package/commands/index.d.ts +2 -0
  45. package/commands/index.js +18 -0
  46. package/commands/info.command.d.ts +5 -0
  47. package/commands/info.command.js +25 -0
  48. package/commands/new.command.d.ts +5 -0
  49. package/commands/new.command.js +52 -0
  50. package/commands/start.command.d.ts +5 -0
  51. package/commands/start.command.js +64 -0
  52. package/commands/update.command.d.ts +5 -0
  53. package/commands/update.command.js +30 -0
  54. package/lib/compiler/assets-manager.d.ts +15 -0
  55. package/lib/compiler/assets-manager.js +103 -0
  56. package/lib/compiler/compiler.d.ts +12 -0
  57. package/lib/compiler/compiler.js +60 -0
  58. package/lib/compiler/defaults/webpack-defaults.d.ts +3 -0
  59. package/lib/compiler/defaults/webpack-defaults.js +95 -0
  60. package/lib/compiler/helpers/append-extension.d.ts +1 -0
  61. package/lib/compiler/helpers/append-extension.js +8 -0
  62. package/lib/compiler/helpers/copy-path-resolve.d.ts +7 -0
  63. package/lib/compiler/helpers/copy-path-resolve.js +26 -0
  64. package/lib/compiler/helpers/get-value-or-default.d.ts +4 -0
  65. package/lib/compiler/helpers/get-value-or-default.js +67 -0
  66. package/lib/compiler/helpers/tsconfig-provider.d.ts +11 -0
  67. package/lib/compiler/helpers/tsconfig-provider.js +22 -0
  68. package/lib/compiler/hooks/tsconfig-paths.hook.d.ts +2 -0
  69. package/lib/compiler/hooks/tsconfig-paths.hook.js +70 -0
  70. package/lib/compiler/plugins-loader.d.ts +21 -0
  71. package/lib/compiler/plugins-loader.js +54 -0
  72. package/lib/compiler/typescript-loader.d.ts +6 -0
  73. package/lib/compiler/typescript-loader.js +31 -0
  74. package/lib/compiler/watch-compiler.d.ts +14 -0
  75. package/lib/compiler/watch-compiler.js +70 -0
  76. package/lib/compiler/webpack-compiler.d.ts +9 -0
  77. package/lib/compiler/webpack-compiler.js +74 -0
  78. package/lib/compiler/workspace-utils.d.ts +4 -0
  79. package/lib/compiler/workspace-utils.js +26 -0
  80. package/lib/configuration/configuration.d.ts +52 -0
  81. package/lib/configuration/configuration.js +2 -0
  82. package/lib/configuration/configuration.loader.d.ts +4 -0
  83. package/lib/configuration/configuration.loader.js +2 -0
  84. package/lib/configuration/defaults.d.ts +4 -0
  85. package/lib/configuration/defaults.js +56 -0
  86. package/lib/configuration/gadmin-configuration.loader.d.ts +8 -0
  87. package/lib/configuration/gadmin-configuration.loader.js +39 -0
  88. package/lib/configuration/index.d.ts +3 -0
  89. package/lib/configuration/index.js +19 -0
  90. package/lib/dependency-managers/index.d.ts +1 -0
  91. package/lib/dependency-managers/index.js +17 -0
  92. package/lib/dependency-managers/nest.dependency-manager.d.ts +7 -0
  93. package/lib/dependency-managers/nest.dependency-manager.js +48 -0
  94. package/lib/package-managers/abstract.package-manager.d.ts +25 -0
  95. package/lib/package-managers/abstract.package-manager.js +185 -0
  96. package/lib/package-managers/index.d.ts +8 -0
  97. package/lib/package-managers/index.js +24 -0
  98. package/lib/package-managers/npm.package-manager.d.ts +7 -0
  99. package/lib/package-managers/npm.package-manager.js +26 -0
  100. package/lib/package-managers/package-manager-commands.d.ts +9 -0
  101. package/lib/package-managers/package-manager-commands.js +2 -0
  102. package/lib/package-managers/package-manager.d.ts +5 -0
  103. package/lib/package-managers/package-manager.factory.d.ts +6 -0
  104. package/lib/package-managers/package-manager.factory.js +54 -0
  105. package/lib/package-managers/package-manager.js +9 -0
  106. package/lib/package-managers/pnpm.package-manager.d.ts +7 -0
  107. package/lib/package-managers/pnpm.package-manager.js +27 -0
  108. package/lib/package-managers/project.dependency.d.ts +4 -0
  109. package/lib/package-managers/project.dependency.js +2 -0
  110. package/lib/package-managers/yarn.package-manager.d.ts +7 -0
  111. package/lib/package-managers/yarn.package-manager.js +26 -0
  112. package/lib/questions/questions.d.ts +2 -0
  113. package/lib/questions/questions.js +23 -0
  114. package/lib/readers/file-system.reader.d.ts +8 -0
  115. package/lib/readers/file-system.reader.js +61 -0
  116. package/lib/readers/index.d.ts +2 -0
  117. package/lib/readers/index.js +18 -0
  118. package/lib/readers/reader.d.ts +5 -0
  119. package/lib/readers/reader.js +2 -0
  120. package/lib/runners/abstract.runner.d.ts +11 -0
  121. package/lib/runners/abstract.runner.js +55 -0
  122. package/lib/runners/git.runner.d.ts +4 -0
  123. package/lib/runners/git.runner.js +10 -0
  124. package/lib/runners/index.d.ts +3 -0
  125. package/lib/runners/index.js +19 -0
  126. package/lib/runners/npm.runner.d.ts +4 -0
  127. package/lib/runners/npm.runner.js +10 -0
  128. package/lib/runners/pnpm.runner.d.ts +4 -0
  129. package/lib/runners/pnpm.runner.js +10 -0
  130. package/lib/runners/runner.d.ts +6 -0
  131. package/lib/runners/runner.factory.d.ts +8 -0
  132. package/lib/runners/runner.factory.js +26 -0
  133. package/lib/runners/runner.js +10 -0
  134. package/lib/runners/schematic.runner.d.ts +6 -0
  135. package/lib/runners/schematic.runner.js +21 -0
  136. package/lib/runners/yarn.runner.d.ts +4 -0
  137. package/lib/runners/yarn.runner.js +10 -0
  138. package/lib/schematics/abstract.collection.d.ts +10 -0
  139. package/lib/schematics/abstract.collection.js +34 -0
  140. package/lib/schematics/collection.d.ts +3 -0
  141. package/lib/schematics/collection.factory.d.ts +5 -0
  142. package/lib/schematics/collection.factory.js +18 -0
  143. package/lib/schematics/collection.js +7 -0
  144. package/lib/schematics/custom.collection.d.ts +3 -0
  145. package/lib/schematics/custom.collection.js +7 -0
  146. package/lib/schematics/gadmin.collection.d.ts +16 -0
  147. package/lib/schematics/gadmin.collection.js +142 -0
  148. package/lib/schematics/index.d.ts +4 -0
  149. package/lib/schematics/index.js +20 -0
  150. package/lib/schematics/schematic.option.d.ts +8 -0
  151. package/lib/schematics/schematic.option.js +44 -0
  152. package/lib/ui/banner.d.ts +1 -0
  153. package/lib/ui/banner.js +11 -0
  154. package/lib/ui/emojis.d.ts +19 -0
  155. package/lib/ui/emojis.js +23 -0
  156. package/lib/ui/errors.d.ts +4 -0
  157. package/lib/ui/errors.js +8 -0
  158. package/lib/ui/index.d.ts +5 -0
  159. package/lib/ui/index.js +21 -0
  160. package/lib/ui/messages.d.ts +26 -0
  161. package/lib/ui/messages.js +34 -0
  162. package/lib/ui/prefixes.d.ts +2 -0
  163. package/lib/ui/prefixes.js +6 -0
  164. package/lib/utils/formatting.d.ts +8 -0
  165. package/lib/utils/formatting.js +19 -0
  166. package/lib/utils/is-error.d.ts +1 -0
  167. package/lib/utils/is-error.js +11 -0
  168. package/lib/utils/load-configuration.d.ts +2 -0
  169. package/lib/utils/load-configuration.js +21 -0
  170. package/lib/utils/local-binaries.d.ts +3 -0
  171. package/lib/utils/local-binaries.js +16 -0
  172. package/lib/utils/project-utils.d.ts +8 -0
  173. package/lib/utils/project-utils.js +69 -0
  174. package/lib/utils/remaining-flags.d.ts +2 -0
  175. package/lib/utils/remaining-flags.js +37 -0
  176. package/lib/utils/tree-kill.d.ts +1 -0
  177. package/lib/utils/tree-kill.js +66 -0
  178. package/package.json +105 -0
  179. package/test/lib/compiler/hooks/__snapshots__/tsconfig-paths.hook.spec.ts.snap +68 -0
  180. package/test/lib/compiler/hooks/fixtures/aliased-imports/src/bar.tsx +1 -0
  181. package/test/lib/compiler/hooks/fixtures/aliased-imports/src/baz.js +1 -0
  182. package/test/lib/compiler/hooks/fixtures/aliased-imports/src/qux.jsx +1 -0
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.exit = exports.retrieveCols = exports.NewAction = void 0;
13
+ const chalk = require("chalk");
14
+ const child_process_1 = require("child_process");
15
+ const fs = require("fs");
16
+ const inquirer = require("inquirer");
17
+ const path_1 = require("path");
18
+ const util_1 = require("util");
19
+ const commands_1 = require("../commands");
20
+ const defaults_1 = require("../lib/configuration/defaults");
21
+ const package_managers_1 = require("../lib/package-managers");
22
+ const questions_1 = require("../lib/questions/questions");
23
+ const git_runner_1 = require("../lib/runners/git.runner");
24
+ const schematics_1 = require("../lib/schematics");
25
+ const ui_1 = require("../lib/ui");
26
+ const formatting_1 = require("../lib/utils/formatting");
27
+ const abstract_action_1 = require("./abstract.action");
28
+ class NewAction extends abstract_action_1.AbstractAction {
29
+ handle(inputs, options) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const directoryOption = options.find((option) => option.name === 'directory');
32
+ const dryRunOption = options.find((option) => option.name === 'dry-run');
33
+ const isDryRunEnabled = dryRunOption && dryRunOption.value;
34
+ yield askForMissingInformation(inputs, options);
35
+ console.info();
36
+ yield generateApplicationFiles(inputs, options).catch(exports.exit);
37
+ const shouldSkipInstall = options.some((option) => option.name === 'skip-install' && option.value === true);
38
+ const shouldSkipGit = options.some((option) => option.name === 'skip-git' && option.value === true);
39
+ const projectDirectory = getProjectDirectory(getApplicationNameInput(inputs), directoryOption);
40
+ if (!shouldSkipInstall) {
41
+ if (options.find(option => option.name === 'server-framework' && option.value === 'nest')) {
42
+ console.info('Begin to install server dependence ...');
43
+ yield installPackages(options, isDryRunEnabled, (0, path_1.join)(projectDirectory, 'server'));
44
+ console.info();
45
+ }
46
+ if (options.find(option => option.name === 'with-web' && option.value === true)) {
47
+ console.info('Begin to install web dependence ...');
48
+ yield installPackages(options, isDryRunEnabled, (0, path_1.join)(projectDirectory, 'web'));
49
+ console.info();
50
+ }
51
+ }
52
+ if (!isDryRunEnabled) {
53
+ if (!shouldSkipGit) {
54
+ yield initializeGitRepository(projectDirectory);
55
+ yield createGitIgnoreFile(projectDirectory);
56
+ }
57
+ const inputPackageManager = (options.find((option) => option.name === 'package-manager').value || 'yarn').toLowerCase();
58
+ console.info();
59
+ console.info(ui_1.MESSAGES.PACKAGE_MANAGER_INSTALLATION_SUCCEED(projectDirectory));
60
+ console.info(ui_1.MESSAGES.GET_STARTED_INFORMATION);
61
+ console.info();
62
+ console.info(chalk.gray(ui_1.MESSAGES.CHANGE_DIR_COMMAND(projectDirectory)));
63
+ if (shouldSkipInstall) {
64
+ console.info('#Install dependence: ');
65
+ if (options.find(option => option.name === 'server-framework' && option.value === 'nest')) {
66
+ if (inputPackageManager === 'yarn') {
67
+ if (options.find(option => option.name === 'with-web' && option.value === true)) {
68
+ console.info(chalk.gray(`cd server && ${inputPackageManager}; cd ../web && ${inputPackageManager}; cd ..`));
69
+ }
70
+ else {
71
+ console.info(chalk.gray(`cd server && ${inputPackageManager}; cd ..`));
72
+ }
73
+ }
74
+ else {
75
+ if (options.find(option => option.name === 'with-web' && option.value === true)) {
76
+ console.info(chalk.gray(`cd server && ${inputPackageManager} install; cd ../web && ${inputPackageManager} install; cd ..`));
77
+ }
78
+ else {
79
+ console.info(chalk.gray(`cd server && ${inputPackageManager} install; cd ..`));
80
+ }
81
+ }
82
+ }
83
+ else { // go iris
84
+ if (inputPackageManager === 'yarn') {
85
+ if (options.find(option => option.name === 'with-web' && option.value === true)) {
86
+ console.info(chalk.gray(`cd server && go get && cd bin/prisma-parse && ${inputPackageManager}; cd ../../web && ${inputPackageManager}; cd ..`));
87
+ }
88
+ else {
89
+ console.info(chalk.gray(`cd server && go get && cd bin/prisma-parse && ${inputPackageManager}; cd ../..`));
90
+ }
91
+ }
92
+ else {
93
+ if (options.find(option => option.name === 'with-web' && option.value === true)) {
94
+ console.info(chalk.gray(`cd server && go get && cd bin/prisma-parse && ${inputPackageManager} install; cd ../../web && ${inputPackageManager} install; cd ..`));
95
+ }
96
+ else {
97
+ console.info(chalk.gray(`cd server && go get && cd bin/prisma-parse && ${inputPackageManager} install; cd ../..`));
98
+ }
99
+ }
100
+ }
101
+ console.info();
102
+ }
103
+ console.info("#Generate code by config/schema.prisma in project root dir:");
104
+ console.info(chalk.gray("gadmin2 g prisma:dev"));
105
+ console.info();
106
+ if (options.find(option => option.name === 'server-framework' && option.value === 'nest')) {
107
+ console.info('#Start server devServer:');
108
+ console.info(chalk.gray('cd server'));
109
+ if (inputPackageManager === 'yarn') {
110
+ console.info(chalk.gray(`${inputPackageManager} seed (only run once)`));
111
+ console.info(chalk.gray(`${inputPackageManager} start:dev`));
112
+ }
113
+ else {
114
+ console.info(chalk.gray(`${inputPackageManager} run seed (only run once)`));
115
+ console.info(chalk.gray(`${inputPackageManager} run start:dev`));
116
+ }
117
+ }
118
+ else {
119
+ console.info(chalk.gray(`swag init -g main.go && go run main.go`));
120
+ }
121
+ if (options.find(option => option.name === 'with-web' && option.value === true)) {
122
+ console.info();
123
+ console.info('#Start web devServer (In anthor terminal): ');
124
+ console.info(chalk.gray('cd web'));
125
+ if (inputPackageManager === 'yarn') {
126
+ console.info(chalk.gray(`${inputPackageManager} dev`));
127
+ }
128
+ else {
129
+ console.info(chalk.gray(`${inputPackageManager} run dev`));
130
+ }
131
+ }
132
+ printCollective();
133
+ }
134
+ process.exit(0);
135
+ });
136
+ }
137
+ }
138
+ exports.NewAction = NewAction;
139
+ const getApplicationNameInput = (inputs) => inputs.find((input) => input.name === 'name');
140
+ const getOptionByName = (inputs, option) => { var _a; return (_a = inputs.find((input) => input.name === option)) === null || _a === void 0 ? void 0 : _a.value; };
141
+ const getProjectDirectory = (applicationName, directoryOption) => {
142
+ return ((directoryOption && directoryOption.value) ||
143
+ (0, formatting_1.normalizeToKebabOrSnakeCase)(applicationName.value));
144
+ };
145
+ const askForMissingInformation = (inputs, options) => __awaiter(void 0, void 0, void 0, function* () {
146
+ console.info(ui_1.MESSAGES.PROJECT_INFORMATION_START);
147
+ console.info();
148
+ const prompt = inquirer.createPromptModule();
149
+ const nameInput = getApplicationNameInput(inputs);
150
+ if (!nameInput.value) {
151
+ const message = 'What name would you like to use for the new project?';
152
+ const questions = [(0, questions_1.generateInput)('name', message)('gadmin-app')];
153
+ const answers = yield prompt(questions);
154
+ replaceInputMissingInformation(inputs, answers);
155
+ }
156
+ // 默认使用 gadmin2-game-angle-demo 模板、nest + react(antd) 技术栈
157
+ replaceInputMissingInformation(options, { 'template': commands_1.Template.GameAngle });
158
+ replaceInputMissingInformation(options, { 'server-framework': 'nest' });
159
+ if (getOptionByName(options, 'with-web') === undefined) {
160
+ const answers = yield askForWithWeb();
161
+ answers['with-web'] = answers['with-web'] === 'yes';
162
+ replaceInputMissingInformation(options, answers);
163
+ }
164
+ });
165
+ const askForWithWeb = () => __awaiter(void 0, void 0, void 0, function* () {
166
+ const questions = [
167
+ (0, questions_1.generateSelect)('with-web')(ui_1.MESSAGES.WITH_WEB_QUESTION)([
168
+ commands_1.WithWeb.Yes,
169
+ commands_1.WithWeb.No,
170
+ ]),
171
+ ];
172
+ const prompt = inquirer.createPromptModule();
173
+ return yield prompt(questions);
174
+ });
175
+ const replaceInputMissingInformation = (inputs, answers) => {
176
+ return inputs.map((input) => (input.value =
177
+ input.value !== undefined ? input.value : answers[input.name]));
178
+ };
179
+ const generateApplicationFiles = (args, options) => __awaiter(void 0, void 0, void 0, function* () {
180
+ const collectionName = options.find((option) => option.name === 'collection' && option.value != null).value;
181
+ const collection = schematics_1.CollectionFactory.create(collectionName || schematics_1.Collection.GADMIN_GENERATOR);
182
+ const schematicOptions = mapSchematicOptions(args.concat(options));
183
+ yield collection.execute('application', schematicOptions);
184
+ console.info();
185
+ });
186
+ const mapSchematicOptions = (options) => {
187
+ return options.reduce((schematicOptions, option) => {
188
+ if (option.name !== 'skip-install' &&
189
+ option.value !== 'package-manager') {
190
+ schematicOptions.push(new schematics_1.SchematicOption(option.name, option.value));
191
+ }
192
+ return schematicOptions;
193
+ }, []);
194
+ };
195
+ const installPackages = (options, dryRunMode, installDirectory) => __awaiter(void 0, void 0, void 0, function* () {
196
+ const inputPackageManager = options.find((option) => option.name === 'package-manager').value;
197
+ let packageManager;
198
+ if (dryRunMode) {
199
+ console.info();
200
+ console.info(chalk.green(ui_1.MESSAGES.DRY_RUN_MODE));
201
+ console.info();
202
+ return;
203
+ }
204
+ if (inputPackageManager !== undefined) {
205
+ try {
206
+ packageManager = package_managers_1.PackageManagerFactory.create(inputPackageManager);
207
+ yield packageManager.install(installDirectory, inputPackageManager);
208
+ }
209
+ catch (error) {
210
+ if (error && error.message) {
211
+ console.error(chalk.red(error.message));
212
+ }
213
+ }
214
+ }
215
+ else {
216
+ packageManager = yield selectPackageManager();
217
+ yield packageManager.install(installDirectory, packageManager.name.toLowerCase());
218
+ options.find((option) => option.name === 'package-manager').value = packageManager.name.toLowerCase();
219
+ }
220
+ });
221
+ const selectPackageManager = () => __awaiter(void 0, void 0, void 0, function* () {
222
+ const answers = yield askForPackageManager();
223
+ return package_managers_1.PackageManagerFactory.create(answers['package-manager']);
224
+ });
225
+ const askForPackageManager = () => __awaiter(void 0, void 0, void 0, function* () {
226
+ const questions = [
227
+ (0, questions_1.generateSelect)('package-manager')(ui_1.MESSAGES.PACKAGE_MANAGER_QUESTION)([
228
+ package_managers_1.PackageManager.YARN,
229
+ package_managers_1.PackageManager.NPM,
230
+ package_managers_1.PackageManager.PNPM,
231
+ ]),
232
+ ];
233
+ const prompt = inquirer.createPromptModule();
234
+ return yield prompt(questions);
235
+ });
236
+ const initializeGitRepository = (dir) => __awaiter(void 0, void 0, void 0, function* () {
237
+ const runner = new git_runner_1.GitRunner();
238
+ yield runner.run('init', true, (0, path_1.join)(process.cwd(), dir)).catch(() => {
239
+ console.error(chalk.red(ui_1.MESSAGES.GIT_INITIALIZATION_ERROR));
240
+ });
241
+ });
242
+ /**
243
+ * Write a file `.gitignore` in the root of the newly created project.
244
+ * `.gitignore` available in `@gadmin2/schematics` cannot be published to
245
+ * NPM (needs to be investigated).
246
+ *
247
+ * @param dir Relative path to the project.
248
+ * @param content (optional) Content written in the `.gitignore`.
249
+ *
250
+ * @return Resolves when succeeds, or rejects with any error from `fn.writeFile`.
251
+ */
252
+ const createGitIgnoreFile = (dir, content) => {
253
+ const fileContent = content || defaults_1.defaultGitIgnore;
254
+ const filePath = (0, path_1.join)(process.cwd(), dir, '.gitignore');
255
+ return (0, util_1.promisify)(fs.writeFile)(filePath, fileContent);
256
+ };
257
+ const printCollective = () => {
258
+ const dim = print('dim');
259
+ const yellow = print('yellow');
260
+ const emptyLine = print();
261
+ emptyLine();
262
+ yellow(`Thanks for using Gadmin2 ${ui_1.EMOJIS.ROCKET}`);
263
+ // dim('Please consider donating to our open collective');
264
+ // dim('to help us maintain this package.');
265
+ emptyLine();
266
+ emptyLine();
267
+ print()(`${chalk.bold(`${ui_1.EMOJIS.WINE} More info:`)} ${chalk.underline('https://ptc.coding.intlgame.com/p/gadmin2/wiki/1')}`);
268
+ emptyLine();
269
+ };
270
+ const print = (color = null) => (str = '') => {
271
+ const terminalCols = (0, exports.retrieveCols)();
272
+ const strLength = str.replace(/\u001b\[[0-9]{2}m/g, '').length;
273
+ const leftPaddingLength = Math.floor((terminalCols - strLength) / 2);
274
+ const leftPadding = ' '.repeat(Math.max(leftPaddingLength, 0));
275
+ if (color) {
276
+ str = chalk[color](str);
277
+ }
278
+ console.log(leftPadding, str);
279
+ };
280
+ const retrieveCols = () => {
281
+ const defaultCols = 80;
282
+ try {
283
+ const terminalCols = (0, child_process_1.execSync)('tput cols', {
284
+ stdio: ['pipe', 'pipe', 'ignore'],
285
+ });
286
+ return parseInt(terminalCols.toString(), 10) || defaultCols;
287
+ }
288
+ catch (_a) {
289
+ return defaultCols;
290
+ }
291
+ };
292
+ exports.retrieveCols = retrieveCols;
293
+ const exit = () => process.exit(1);
294
+ exports.exit = exit;
@@ -0,0 +1,5 @@
1
+ import { Input } from '../commands';
2
+ import { AbstractAction } from './abstract.action';
3
+ export declare class PrismaAction extends AbstractAction {
4
+ handle(inputs: Input[], options: Input[]): Promise<void>;
5
+ }
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PrismaAction = void 0;
13
+ const chalk = require("chalk");
14
+ const fs = require("fs");
15
+ const abstract_action_1 = require("./abstract.action");
16
+ const shell = require("shelljs");
17
+ const readline = require("readline");
18
+ // 暂时没用上
19
+ function replaceFileContent(filePath, match, src, dest) {
20
+ // 创建可读流和可写流
21
+ const readStream = fs.createReadStream(filePath);
22
+ const writeStream = fs.createWriteStream(filePath + '.tmp');
23
+ // 创建接口
24
+ const rl = readline.createInterface({
25
+ input: readStream,
26
+ output: writeStream,
27
+ terminal: false,
28
+ });
29
+ // 逐行读取文件并处理
30
+ rl.on('line', (line) => {
31
+ if (line.match(match)) {
32
+ const newLine = line.replace(src, dest);
33
+ writeStream.write(newLine + ''); // 将替换后的行写入临时文件
34
+ }
35
+ else {
36
+ writeStream.write(line + ''); // 将原始行写入临时文件
37
+ }
38
+ });
39
+ rl.on('close', () => {
40
+ // 关闭可写流
41
+ writeStream.end();
42
+ // 重命名临时文件为目标文件
43
+ fs.rename(filePath + '.tmp', filePath, (err) => {
44
+ if (err) {
45
+ console.error('Error renaming file:', err);
46
+ }
47
+ });
48
+ });
49
+ }
50
+ class PrismaAction extends abstract_action_1.AbstractAction {
51
+ handle(inputs, options) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ // 检查 prisma schema 配置是否存在
54
+ const hasPrismaConfig = shell.test('-e', 'config/schema.prisma') ||
55
+ shell.test('-d', 'config/prisma');
56
+ if (!hasPrismaConfig) {
57
+ console.error(`${chalk.red('This command must run in project root dir.')}`);
58
+ console.error(`${chalk.red('Missing: config/schema.prisma or config/prisma/ directory')}`);
59
+ process.exit(-1);
60
+ }
61
+ const devMode = options.find((option) => option.name === 'dev');
62
+ shell
63
+ .cat('server/prisma/.generator.prisma')
64
+ .to('server/prisma/schema.prisma');
65
+ let schemaStr = '';
66
+ if (shell.test('-d', 'config/prisma')) {
67
+ schemaStr = shell.cat('config/prisma/*.prisma');
68
+ }
69
+ else {
70
+ schemaStr = shell.cat('config/schema.prisma');
71
+ }
72
+ const schemaRegex = /([\s\S]*?model\s\w*\s*\{)([^\}]*)(\})/gim; // https://regex101.com/
73
+ // const subst = `$1\n id Int @id @default(autoincrement())$2 createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n$3`;
74
+ let m, result = '';
75
+ while ((m = schemaRegex.exec(schemaStr)) !== null) {
76
+ // This is necessary to avoid infinite loops with zero-width matches
77
+ if (m.index === schemaRegex.lastIndex) {
78
+ schemaRegex.lastIndex++;
79
+ }
80
+ // The result can be accessed through the `m`-variable.
81
+ // m.forEach((match, groupIndex) => {
82
+ // console.log(`Found match, group ${groupIndex}: ${match}`);
83
+ // });
84
+ let ignore = !!m[1].match(/\/\/\/\s*@IgnoreAutoField/);
85
+ result += m[1];
86
+ if (!ignore) {
87
+ result += '\n id Int @id @default(autoincrement())';
88
+ }
89
+ result += m[2];
90
+ if (!ignore) {
91
+ result +=
92
+ ' creator String @default("") @db.VarChar(128)\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt @default(now())\n';
93
+ }
94
+ result += m[3];
95
+ }
96
+ //const result = schemaStr.replace(schemaRegex, subst);
97
+ new shell.ShellString(result).toEnd('server/prisma/schema.prisma');
98
+ fs.rmSync('server/src/generated', { recursive: true, force: true });
99
+ fs.rmSync('web/src/generated', { recursive: true, force: true });
100
+ /*
101
+ const {code} = shell.cd('config/').exec('tsc ui.config.ts');
102
+ if(code !== 0){
103
+ process.exit(code);
104
+ }
105
+ shell.cd('../');
106
+ */
107
+ const { code } = shell
108
+ .cd('server/')
109
+ .exec(devMode ? 'npm run generate:dev' : 'npm run generate');
110
+ if (code !== 0) {
111
+ process.exit(code);
112
+ }
113
+ shell.cd('../');
114
+ fs.cpSync('server/src/generated/.react', 'web/src/generated', {
115
+ recursive: true,
116
+ force: true,
117
+ });
118
+ fs.rmSync('server/src/generated/.react', { recursive: true, force: true });
119
+ shell.cd('server/src/generated/');
120
+ const models = shell
121
+ .ls('-d', '*')
122
+ .filter((file) => shell.test('-d', file))
123
+ .filter((dir) => shell.test('-e', `${dir}/dto/${dir}.form.validator.ts`));
124
+ shell.cd('../../..');
125
+ models.forEach((modelName) => {
126
+ shell.mv('-f', `server/src/generated/${modelName}/dto/${modelName}.form.validator.ts`, `web/src/generated/props/${modelName}/form.validator.ts`);
127
+ fs.cpSync(`server/src/generated/${modelName}`, `server/src/modules/${modelName}`, { recursive: true, force: false });
128
+ shell.rm('-f', `server/src/generated/${modelName}/*.ts`);
129
+ fs.rmSync(`server/src/modules/${modelName}/dto`, {
130
+ recursive: true,
131
+ force: true,
132
+ });
133
+ fs.rmSync(`server/src/modules/${modelName}/entities`, {
134
+ recursive: true,
135
+ force: true,
136
+ });
137
+ });
138
+ fs.cpSync('web/src/generated/pages', 'web/src/pages', {
139
+ recursive: true,
140
+ force: false,
141
+ });
142
+ fs.rmSync('web/src/generated/pages', { recursive: true, force: true });
143
+ fs.mkdirSync('web/src/generated/types');
144
+ fs.copyFileSync('server/node_modules/.prisma/client/index.d.ts', 'web/src/generated/types/prisma.types.d.ts');
145
+ const prismaRegex = new RegExp("import \\* as runtime from '@prisma/client/runtime/index';");
146
+ shell.sed('-i', prismaRegex, 'declare const runtime : any', 'web/src/generated/types/prisma.types.d.ts');
147
+ shell.sed('-i', new RegExp('bigint', 'g'), 'number', 'web/src/generated/types/prisma.types.d.ts');
148
+ fs.copyFileSync('config/.types.d.ts', 'web/src/generated/types/config.types.d.ts');
149
+ process.exit(0);
150
+ });
151
+ }
152
+ }
153
+ exports.PrismaAction = PrismaAction;
@@ -0,0 +1,9 @@
1
+ import { Input } from '../commands';
2
+ import { Configuration } from '../lib/configuration';
3
+ import { BuildAction } from './build.action';
4
+ export declare class StartAction extends BuildAction {
5
+ handle(inputs: Input[], options: Input[]): Promise<void>;
6
+ createOnSuccessHook(configuration: Required<Configuration>, appName: string, debugFlag: boolean | string | undefined, outDirName: string, binaryToRun?: string): () => void;
7
+ private spawnChildProcess;
8
+ private isSourceMapSupportPkgAvailable;
9
+ }
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.StartAction = void 0;
13
+ const chalk = require("chalk");
14
+ const child_process_1 = require("child_process");
15
+ const fs = require("fs");
16
+ const path_1 = require("path");
17
+ const killProcess = require("tree-kill");
18
+ const tree_kill_1 = require("../lib/utils/tree-kill");
19
+ const get_value_or_default_1 = require("../lib/compiler/helpers/get-value-or-default");
20
+ const defaults_1 = require("../lib/configuration/defaults");
21
+ const ui_1 = require("../lib/ui");
22
+ const build_action_1 = require("./build.action");
23
+ class StartAction extends build_action_1.BuildAction {
24
+ handle(inputs, options) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ try {
27
+ const configFileName = options.find((option) => option.name === 'config')
28
+ .value;
29
+ const configuration = yield this.loader.load(configFileName);
30
+ const appName = inputs.find((input) => input.name === 'app')
31
+ .value;
32
+ const pathToTsconfig = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.tsConfigPath', appName, 'path', options);
33
+ const binaryToRunOption = options.find((option) => option.name === 'exec');
34
+ const debugModeOption = options.find((option) => option.name === 'debug');
35
+ const watchModeOption = options.find((option) => option.name === 'watch');
36
+ const isWatchEnabled = !!(watchModeOption && watchModeOption.value);
37
+ const watchAssetsModeOption = options.find((option) => option.name === 'watchAssets');
38
+ const isWatchAssetsEnabled = !!(watchAssetsModeOption && watchAssetsModeOption.value);
39
+ const debugFlag = debugModeOption && debugModeOption.value;
40
+ const binaryToRun = binaryToRunOption && binaryToRunOption.value;
41
+ const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
42
+ const outDir = tsOptions.outDir || defaults_1.defaultOutDir;
43
+ const onSuccess = this.createOnSuccessHook(configuration, appName, debugFlag, outDir, binaryToRun);
44
+ yield this.runBuild(inputs, options, isWatchEnabled, isWatchAssetsEnabled, !!debugFlag, onSuccess);
45
+ }
46
+ catch (err) {
47
+ if (err instanceof Error) {
48
+ console.log(`\n${ui_1.ERROR_PREFIX} ${err.message}\n`);
49
+ }
50
+ else {
51
+ console.error(`\n${chalk.red(err)}\n`);
52
+ }
53
+ }
54
+ });
55
+ }
56
+ createOnSuccessHook(configuration, appName, debugFlag, outDirName, binaryToRun = 'node') {
57
+ const sourceRoot = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'sourceRoot', appName);
58
+ const entryFile = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'entryFile', appName);
59
+ let childProcessRef;
60
+ process.on('exit', () => childProcessRef && (0, tree_kill_1.treeKillSync)(childProcessRef.pid));
61
+ return () => {
62
+ if (childProcessRef) {
63
+ childProcessRef.removeAllListeners('exit');
64
+ childProcessRef.on('exit', () => {
65
+ childProcessRef = this.spawnChildProcess(entryFile, sourceRoot, debugFlag, outDirName, binaryToRun);
66
+ childProcessRef.on('exit', () => (childProcessRef = undefined));
67
+ });
68
+ childProcessRef.stdin && childProcessRef.stdin.pause();
69
+ killProcess(childProcessRef.pid);
70
+ }
71
+ else {
72
+ childProcessRef = this.spawnChildProcess(entryFile, sourceRoot, debugFlag, outDirName, binaryToRun);
73
+ childProcessRef.on('exit', (code) => {
74
+ process.exitCode = code;
75
+ childProcessRef = undefined;
76
+ });
77
+ }
78
+ };
79
+ }
80
+ spawnChildProcess(entryFile, sourceRoot, debug, outDirName, binaryToRun) {
81
+ let outputFilePath = (0, path_1.join)(outDirName, sourceRoot, entryFile);
82
+ if (!fs.existsSync(outputFilePath + '.js')) {
83
+ outputFilePath = (0, path_1.join)(outDirName, entryFile);
84
+ }
85
+ let childProcessArgs = [];
86
+ const argsStartIndex = process.argv.indexOf('--');
87
+ if (argsStartIndex >= 0) {
88
+ childProcessArgs = process.argv.slice(argsStartIndex + 1);
89
+ }
90
+ outputFilePath =
91
+ outputFilePath.indexOf(' ') >= 0 ? `"${outputFilePath}"` : outputFilePath;
92
+ const processArgs = [outputFilePath, ...childProcessArgs];
93
+ if (debug) {
94
+ const inspectFlag = typeof debug === 'string' ? `--inspect=${debug}` : '--inspect';
95
+ processArgs.unshift(inspectFlag);
96
+ }
97
+ if (this.isSourceMapSupportPkgAvailable()) {
98
+ processArgs.unshift('-r source-map-support/register');
99
+ }
100
+ return (0, child_process_1.spawn)(binaryToRun, processArgs, {
101
+ stdio: 'inherit',
102
+ shell: true,
103
+ });
104
+ }
105
+ isSourceMapSupportPkgAvailable() {
106
+ try {
107
+ require.resolve('source-map-support');
108
+ return true;
109
+ }
110
+ catch (_a) {
111
+ return false;
112
+ }
113
+ }
114
+ }
115
+ exports.StartAction = StartAction;
@@ -0,0 +1,5 @@
1
+ import { Input } from '../commands';
2
+ import { AbstractAction } from './abstract.action';
3
+ export declare class UpdateAction extends AbstractAction {
4
+ handle(inputs: Input[], options: Input[]): Promise<void>;
5
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UpdateAction = void 0;
13
+ const dependency_managers_1 = require("../lib/dependency-managers");
14
+ const package_managers_1 = require("../lib/package-managers");
15
+ const abstract_action_1 = require("./abstract.action");
16
+ class UpdateAction extends abstract_action_1.AbstractAction {
17
+ handle(inputs, options) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const force = options.find((option) => option.name === 'force');
20
+ const tag = options.find((option) => option.name === 'tag');
21
+ const manager = new dependency_managers_1.NestDependencyManager(yield package_managers_1.PackageManagerFactory.find());
22
+ yield manager.update(force.value, tag.value);
23
+ });
24
+ }
25
+ }
26
+ exports.UpdateAction = UpdateAction;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/bin/gadmin.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander = require("commander");
5
+ const commands_1 = require("../commands");
6
+ const local_binaries_1 = require("../lib/utils/local-binaries");
7
+ const bootstrap = () => {
8
+ const program = commander;
9
+ program
10
+ .version(require('../package.json').version, '-v, --version', 'Output the current version.')
11
+ .usage('<command> [options]')
12
+ .helpOption('-h, --help', 'Output usage information.');
13
+ if ((0, local_binaries_1.localBinExists)()) {
14
+ const localCommandLoader = (0, local_binaries_1.loadLocalBinCommandLoader)();
15
+ localCommandLoader.load(program);
16
+ }
17
+ else {
18
+ commands_1.CommandLoader.load(program);
19
+ }
20
+ commander.parse(process.argv);
21
+ if (!process.argv.slice(2).length) {
22
+ program.outputHelp();
23
+ }
24
+ };
25
+ bootstrap();
@@ -0,0 +1,7 @@
1
+ import { CommanderStatic } from 'commander';
2
+ import { AbstractAction } from '../actions/abstract.action';
3
+ export declare abstract class AbstractCommand {
4
+ protected action: AbstractAction;
5
+ constructor(action: AbstractAction);
6
+ abstract load(program: CommanderStatic): void;
7
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractCommand = void 0;
4
+ class AbstractCommand {
5
+ constructor(action) {
6
+ this.action = action;
7
+ }
8
+ }
9
+ exports.AbstractCommand = AbstractCommand;