nsgm-cli 2.1.12 → 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 +369 -163
  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 -18
  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 +25 -4
  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 -193
  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
@@ -2,7 +2,7 @@
2
2
  "name": "nsgm-cli-project",
3
3
  "version": "1.0.0",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "app.js",
6
6
  "scripts": {
7
7
  "dev": "nsgm dev",
8
8
  "build": "nsgm build",
@@ -13,10 +13,31 @@
13
13
  "create": "nsgm create",
14
14
  "delete": "nsgm delete",
15
15
  "deletedb": "nsgm deletedb",
16
- "generate-password": "nsgm password",
16
+ "generate-password": "node scripts/generate-password-hash.js",
17
17
  "postversion": "git push && git push --tags",
18
- "test": "echo \"Error: no test specified\" && exit 1"
18
+ "test": "jest",
19
+ "test:watch": "jest --watch",
20
+ "test:coverage": "jest --coverage"
19
21
  },
20
22
  "author": "",
21
- "license": "ISC"
23
+ "license": "ISC",
24
+ "dependencies": {
25
+ "nsgm-cli": "^2"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^20",
29
+ "@types/react": "^18",
30
+ "@types/lodash": "^4",
31
+ "typescript": "^5",
32
+ "jest": "^30",
33
+ "jest-environment-jsdom": "^30",
34
+ "@testing-library/jest-dom": "^6",
35
+ "@testing-library/react": "^14",
36
+ "@testing-library/user-event": "^14",
37
+ "@types/jest": "^30",
38
+ "eslint": "^9",
39
+ "eslint-config-prettier": "^10",
40
+ "eslint-plugin-prettier": "^5",
41
+ "prettier": "^3"
42
+ }
22
43
  }
package/jest.config.js CHANGED
@@ -4,6 +4,19 @@ module.exports = {
4
4
  transform: {
5
5
  '^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }]
6
6
  },
7
+ transformIgnorePatterns: ['/node_modules/', '^.+\\.module\\.(css|sass|scss|less)$'],
8
+ moduleNameMapper: {
9
+ '^replace-in-file$': '<rootDir>/__mocks__/replace-in-file.js',
10
+ '^replace$': '<rootDir>/__mocks__/replace.js',
11
+ '^fs$': '<rootDir>/__mocks__/fs.js',
12
+ '^next$': '<rootDir>/__mocks__/next.js',
13
+ '^express$': '<rootDir>/__mocks__/express.js',
14
+ '^body-parser$': '<rootDir>/__mocks__/body-parser.js',
15
+ '^url$': '<rootDir>/__mocks__/url.js',
16
+ '^dotenv$': '<rootDir>/__mocks__/dotenv.js',
17
+ '^chalk$': '<rootDir>/__mocks__/chalk.js'
18
+ },
19
+ setupFiles: ['<rootDir>/jest.setup-globals.js'],
7
20
  testMatch: [
8
21
  '**/__tests__/**/*.(ts|tsx|js)',
9
22
  '**/*.(test|spec).(ts|tsx|js)'
@@ -16,14 +29,18 @@ module.exports = {
16
29
  'src/**/*.{js,jsx,ts,tsx}',
17
30
  '!**/*.d.ts',
18
31
  '!**/node_modules/**',
19
- '!**/.next/**'
32
+ '!**/.next/**',
33
+ '!**/coverage/**',
34
+ '!**/*.config.js'
20
35
  ],
21
36
  coverageDirectory: 'coverage',
22
- coverageReporters: ['json', 'lcov', 'text', 'clover'],
23
- extensionsToTreatAsEsm: ['.ts', '.tsx'],
24
- globals: {
25
- 'ts-jest': {
26
- useESM: true
37
+ coverageReporters: ['json', 'lcov', 'text', 'clover', 'html'],
38
+ coverageThreshold: {
39
+ global: {
40
+ branches: 70,
41
+ functions: 70,
42
+ lines: 70,
43
+ statements: 70
27
44
  }
28
45
  }
29
46
  }
package/lib/args.js CHANGED
@@ -11,7 +11,7 @@ const getProcessArgvs = (removeItems = 2) => {
11
11
  command: '', // dev, start, build, export, create, delete, init, help
12
12
  dictionary: '', // export/init dictionary=${dictionary}
13
13
  controller: '',
14
- action: '' // create/delete controller=${controller} action=${action}
14
+ action: '', // create/delete controller=${controller} action=${action}
15
15
  };
16
16
  lodash_1.default.each(args, (item, index) => {
17
17
  if (item.indexOf('=') !== -1) {
@@ -44,6 +44,14 @@ const getProcessArgvs = (removeItems = 2) => {
44
44
  result.action = item;
45
45
  }
46
46
  break;
47
+ case 3:
48
+ if (command === 'create' ||
49
+ command === '-c' ||
50
+ command.indexOf('delete') !== -1 ||
51
+ command.indexOf('-d') !== -1) {
52
+ result.dictionary = item;
53
+ }
54
+ break;
47
55
  }
48
56
  }
49
57
  });
@@ -0,0 +1,28 @@
1
+ import { CommandRegistry } from './registry';
2
+ /**
3
+ * CLI 应用程序主类
4
+ */
5
+ export declare class CliApp {
6
+ private registry;
7
+ constructor();
8
+ /**
9
+ * 运行 CLI 应用
10
+ */
11
+ run(args?: string[]): Promise<void>;
12
+ /**
13
+ * 查找相似的命令(简单的字符串匹配)
14
+ */
15
+ private findSimilarCommands;
16
+ /**
17
+ * 应用命令默认值
18
+ */
19
+ private applyCommandDefaults;
20
+ /**
21
+ * 获取命令注册表(用于测试)
22
+ */
23
+ getRegistry(): CommandRegistry;
24
+ }
25
+ /**
26
+ * 创建并运行 CLI 应用的便捷函数
27
+ */
28
+ export declare function runCli(args?: string[]): Promise<void>;
package/lib/cli/app.js ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CliApp = void 0;
4
+ exports.runCli = runCli;
5
+ const parser_1 = require("./parser");
6
+ const registry_1 = require("./registry");
7
+ const utils_1 = require("./utils");
8
+ /**
9
+ * CLI 应用程序主类
10
+ */
11
+ class CliApp {
12
+ constructor() {
13
+ this.registry = new registry_1.CommandRegistry();
14
+ }
15
+ /**
16
+ * 运行 CLI 应用
17
+ */
18
+ async run(args = process.argv.slice(2)) {
19
+ try {
20
+ const { command, options } = parser_1.ArgumentParser.parse(args);
21
+ // 查找命令
22
+ const cmd = this.registry.get(command);
23
+ if (!cmd) {
24
+ utils_1.Console.error(`未知命令: ${command}`);
25
+ utils_1.Console.info('使用 "nsgm help" 查看可用命令');
26
+ utils_1.Console.newLine();
27
+ // 提供建议的命令
28
+ const availableCommands = this.registry.getAllCommands().map((c) => c.name);
29
+ const suggestions = this.findSimilarCommands(command, availableCommands);
30
+ if (suggestions.length > 0) {
31
+ utils_1.Console.subtitle('你是否想要运行:');
32
+ suggestions.forEach((suggestion) => {
33
+ console.log(` nsgm ${suggestion}`);
34
+ });
35
+ }
36
+ process.exit(1);
37
+ }
38
+ // 应用命令选项的默认值
39
+ const finalOptions = this.applyCommandDefaults(cmd, options);
40
+ // 执行命令
41
+ await cmd.execute(finalOptions);
42
+ }
43
+ catch (error) {
44
+ utils_1.Console.error(`执行命令时发生错误: ${error}`);
45
+ utils_1.Console.debug('使用 "nsgm help" 查看帮助信息');
46
+ process.exit(1);
47
+ }
48
+ }
49
+ /**
50
+ * 查找相似的命令(简单的字符串匹配)
51
+ */
52
+ findSimilarCommands(input, commands) {
53
+ const suggestions = [];
54
+ // 查找包含输入字符的命令
55
+ for (const cmd of commands) {
56
+ if (cmd.includes(input) || input.includes(cmd)) {
57
+ suggestions.push(cmd);
58
+ }
59
+ }
60
+ // 如果没有找到,查找第一个字符相同的
61
+ if (suggestions.length === 0) {
62
+ for (const cmd of commands) {
63
+ if (cmd[0] === input[0]) {
64
+ suggestions.push(cmd);
65
+ }
66
+ }
67
+ }
68
+ return suggestions.slice(0, 3); // 最多返回3个建议
69
+ }
70
+ /**
71
+ * 应用命令默认值
72
+ */
73
+ applyCommandDefaults(cmd, options) {
74
+ const result = { ...options };
75
+ // 应用命令选项中定义的默认值
76
+ if (cmd.options) {
77
+ for (const option of cmd.options) {
78
+ if (option.default !== undefined && (result[option.name] === undefined || result[option.name] === '')) {
79
+ result[option.name] = option.default;
80
+ }
81
+ }
82
+ }
83
+ return result;
84
+ }
85
+ /**
86
+ * 获取命令注册表(用于测试)
87
+ */
88
+ getRegistry() {
89
+ return this.registry;
90
+ }
91
+ }
92
+ exports.CliApp = CliApp;
93
+ /**
94
+ * 创建并运行 CLI 应用的便捷函数
95
+ */
96
+ async function runCli(args) {
97
+ const app = new CliApp();
98
+ await app.run(args);
99
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from '../types';
2
+ export declare const buildCommand: Command;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCommand = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const util_1 = require("util");
6
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
7
+ exports.buildCommand = {
8
+ name: 'build',
9
+ aliases: [],
10
+ description: '构建生产版本',
11
+ usage: 'nsgm build',
12
+ examples: ['nsgm build'],
13
+ execute: async (_options) => {
14
+ try {
15
+ console.log('🔨 开始构建生产版本...');
16
+ const { stdout, stderr } = await execAsync('next build');
17
+ if (stderr) {
18
+ console.error('构建警告:', stderr);
19
+ }
20
+ console.log('✅ 构建完成!');
21
+ console.log(stdout);
22
+ process.exit(0);
23
+ }
24
+ catch (error) {
25
+ console.error('❌ 构建失败:', error);
26
+ process.exit(1);
27
+ }
28
+ },
29
+ };
@@ -0,0 +1,2 @@
1
+ import { Command } from '../types';
2
+ export declare const createCommand: Command;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCommand = void 0;
4
+ const parser_1 = require("../parser");
5
+ const utils_1 = require("../utils");
6
+ const generate_1 = require("../../generate");
7
+ exports.createCommand = {
8
+ name: 'create',
9
+ aliases: ['-c', '--create'],
10
+ description: '创建控制器和操作',
11
+ usage: 'nsgm create [controller] [action] [dictionary] [options]',
12
+ examples: ['nsgm create', 'nsgm create user', 'nsgm create user manage', 'nsgm create user manage myproject'],
13
+ options: [
14
+ {
15
+ name: 'controller',
16
+ description: '控制器名称',
17
+ required: false,
18
+ type: 'string',
19
+ },
20
+ {
21
+ name: 'action',
22
+ description: '操作名称',
23
+ default: 'manage',
24
+ type: 'string',
25
+ },
26
+ {
27
+ name: 'dictionary',
28
+ description: '项目目录',
29
+ default: '',
30
+ type: 'string',
31
+ },
32
+ {
33
+ name: 'interactive',
34
+ description: '使用交互式向导',
35
+ default: true,
36
+ type: 'boolean',
37
+ },
38
+ ],
39
+ execute: async (options) => {
40
+ try {
41
+ // 智能判断是否使用交互模式:如果用户提供了 controller 参数,则自动使用非交互模式
42
+ if (options.controller && options.controller.trim() !== '') {
43
+ options.interactive = false;
44
+ }
45
+ // 如果启用交互模式
46
+ if (options.interactive) {
47
+ const wizardResult = await utils_1.Prompt.createControllerWizard();
48
+ utils_1.Console.separator();
49
+ utils_1.Console.title('📋 控制器配置确认');
50
+ utils_1.Console.info(`控制器名称: ${wizardResult.controller}`);
51
+ utils_1.Console.info(`功能模块: 完整CRUD + 导入导出 + 批量删除`);
52
+ utils_1.Console.info(`描述: ${wizardResult.description}`);
53
+ utils_1.Console.info(`项目目录: ${wizardResult.dictionary}`);
54
+ utils_1.Console.info(`数据库表: ${wizardResult.includeDatabase ? '是' : '否'}`);
55
+ if (wizardResult.includeDatabase && wizardResult.fields.length > 0) {
56
+ const fieldNames = wizardResult.fields.map((field) => field.name).join(', ');
57
+ utils_1.Console.info(`字段: ${fieldNames}`);
58
+ }
59
+ utils_1.Console.separator();
60
+ const confirmed = await utils_1.Prompt.confirm('确认创建控制器?', true);
61
+ if (!confirmed) {
62
+ utils_1.Console.warning('控制器创建已取消');
63
+ process.exit(0);
64
+ }
65
+ // 更新选项
66
+ options.controller = wizardResult.controller;
67
+ options.action = wizardResult.action;
68
+ options.dictionary = wizardResult.dictionary;
69
+ options.fields = wizardResult.fields;
70
+ }
71
+ // 验证必需参数(仅在非交互模式下)
72
+ if (!options.interactive) {
73
+ const missing = parser_1.ArgumentParser.validateRequired(options, ['controller']);
74
+ if (missing.length > 0) {
75
+ utils_1.Console.error(`缺少必需参数: ${missing.join(', ')}`);
76
+ utils_1.Console.info('使用方法:');
77
+ utils_1.Console.info(' 交互模式: nsgm create');
78
+ utils_1.Console.info(' 命令行模式: nsgm create [controller] [action] [dictionary]');
79
+ process.exit(1);
80
+ }
81
+ }
82
+ const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
83
+ action: 'manage',
84
+ dictionary: '',
85
+ });
86
+ utils_1.Console.highlight(`🎯 创建控制器: ${finalOptions.controller}`);
87
+ utils_1.Console.info(`📝 操作: ${finalOptions.action}`);
88
+ if (finalOptions.dictionary) {
89
+ utils_1.Console.info(`📁 目录: ${finalOptions.dictionary}`);
90
+ }
91
+ const spinner = utils_1.Console.spinner('正在创建文件...', 'green');
92
+ spinner.start();
93
+ try {
94
+ // 模拟创建过程
95
+ await new Promise((resolve) => setTimeout(resolve, 800));
96
+ (0, generate_1.createFiles)(finalOptions.controller, finalOptions.action, finalOptions.dictionary, finalOptions.fields);
97
+ spinner.succeed('控制器创建完成!');
98
+ utils_1.Console.newLine();
99
+ utils_1.Console.box(`控制器 "${finalOptions.controller}" 已创建成功!\n\n` +
100
+ `操作: ${finalOptions.action}\n` +
101
+ `路径: ${finalOptions.dictionary || './'}`, 'success');
102
+ }
103
+ catch (error) {
104
+ spinner.fail('控制器创建失败');
105
+ throw error;
106
+ }
107
+ }
108
+ catch (error) {
109
+ utils_1.Console.error(`创建失败: ${error}`);
110
+ process.exit(1);
111
+ }
112
+ },
113
+ };
@@ -0,0 +1,3 @@
1
+ import { Command } from '../types';
2
+ export declare const deleteCommand: Command;
3
+ export declare const deleteDbCommand: Command;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteDbCommand = exports.deleteCommand = void 0;
4
+ const parser_1 = require("../parser");
5
+ const utils_1 = require("../utils");
6
+ const generate_1 = require("../../generate");
7
+ exports.deleteCommand = {
8
+ name: 'delete',
9
+ aliases: ['-d', '--delete'],
10
+ description: '删除控制器和操作',
11
+ usage: 'nsgm delete [controller] [action] [dictionary] [options]',
12
+ examples: ['nsgm delete', 'nsgm delete user', 'nsgm delete user list', 'nsgm delete user all myproject'],
13
+ options: [
14
+ {
15
+ name: 'controller',
16
+ description: '控制器名称',
17
+ required: false,
18
+ type: 'string',
19
+ },
20
+ {
21
+ name: 'action',
22
+ description: '操作名称',
23
+ default: 'all',
24
+ type: 'string',
25
+ },
26
+ {
27
+ name: 'dictionary',
28
+ description: '项目目录',
29
+ default: '',
30
+ type: 'string',
31
+ },
32
+ {
33
+ name: 'interactive',
34
+ description: '使用交互式向导',
35
+ default: true,
36
+ type: 'boolean',
37
+ },
38
+ ],
39
+ execute: async (options) => {
40
+ try {
41
+ let deleteDatabase = false;
42
+ // 智能判断是否使用交互模式:如果用户提供了 controller 参数,则自动使用非交互模式
43
+ if (options.controller && options.controller.trim() !== '') {
44
+ options.interactive = false;
45
+ }
46
+ // 如果启用交互模式
47
+ if (options.interactive) {
48
+ const wizardResult = await utils_1.Prompt.deleteControllerWizard();
49
+ utils_1.Console.separator();
50
+ utils_1.Console.title('📋 删除确认');
51
+ utils_1.Console.info(`控制器名称: ${wizardResult.controller}`);
52
+ utils_1.Console.info(`删除范围: ${wizardResult.action === 'all' ? '所有相关文件' : '指定操作'}`);
53
+ utils_1.Console.info(`项目目录: ${wizardResult.dictionary}`);
54
+ utils_1.Console.info(`删除数据库: ${wizardResult.deleteDatabase ? '是' : '否'}`);
55
+ utils_1.Console.separator();
56
+ const confirmed = await utils_1.Prompt.confirm('确认删除?此操作不可恢复!', false);
57
+ if (!confirmed) {
58
+ utils_1.Console.warning('删除操作已取消');
59
+ process.exit(0);
60
+ }
61
+ // 更新选项
62
+ options.controller = wizardResult.controller;
63
+ options.action = wizardResult.action;
64
+ options.dictionary = wizardResult.dictionary;
65
+ deleteDatabase = wizardResult.deleteDatabase;
66
+ }
67
+ // 验证必需参数(仅在非交互模式下)
68
+ if (!options.interactive) {
69
+ const missing = parser_1.ArgumentParser.validateRequired(options, ['controller']);
70
+ if (missing.length > 0) {
71
+ utils_1.Console.error(`缺少必需参数: ${missing.join(', ')}`);
72
+ utils_1.Console.info('使用方法:');
73
+ utils_1.Console.info(' 交互模式: nsgm delete');
74
+ utils_1.Console.info(' 命令行模式: nsgm delete [controller] [action] [dictionary]');
75
+ process.exit(1);
76
+ }
77
+ }
78
+ const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
79
+ action: 'all',
80
+ dictionary: '',
81
+ });
82
+ utils_1.Console.highlight(`🗑️ 删除控制器: ${finalOptions.controller}`);
83
+ utils_1.Console.info(`📝 操作: ${finalOptions.action}`);
84
+ if (finalOptions.dictionary) {
85
+ utils_1.Console.info(`📁 目录: ${finalOptions.dictionary}`);
86
+ }
87
+ const spinner = utils_1.Console.spinner('正在删除文件...', 'red');
88
+ spinner.start();
89
+ try {
90
+ await new Promise((resolve) => setTimeout(resolve, 500));
91
+ (0, generate_1.deleteFiles)(finalOptions.controller, finalOptions.action, deleteDatabase, finalOptions.dictionary);
92
+ spinner.succeed('删除完成!');
93
+ utils_1.Console.newLine();
94
+ utils_1.Console.box(`控制器 "${finalOptions.controller}" 已删除成功!\n\n` +
95
+ `操作: ${finalOptions.action}\n` +
96
+ `路径: ${finalOptions.dictionary || './'}${deleteDatabase ? '\n数据库表: 已删除' : ''}`, 'success');
97
+ }
98
+ catch (error) {
99
+ spinner.fail('删除失败');
100
+ throw error;
101
+ }
102
+ }
103
+ catch (error) {
104
+ utils_1.Console.error(`删除失败: ${error}`);
105
+ process.exit(1);
106
+ }
107
+ },
108
+ };
109
+ exports.deleteDbCommand = {
110
+ name: 'deletedb',
111
+ aliases: ['-db', '--deletedb'],
112
+ description: '删除控制器、操作和相关数据库',
113
+ usage: 'nsgm deletedb <controller> [action]',
114
+ examples: ['nsgm deletedb user', 'nsgm deletedb user list'],
115
+ options: [
116
+ {
117
+ name: 'controller',
118
+ description: '控制器名称',
119
+ required: true,
120
+ type: 'string',
121
+ },
122
+ {
123
+ name: 'action',
124
+ description: '操作名称',
125
+ default: 'all',
126
+ type: 'string',
127
+ },
128
+ ],
129
+ execute: async (options) => {
130
+ try {
131
+ // 验证必需参数
132
+ const missing = parser_1.ArgumentParser.validateRequired(options, ['controller']);
133
+ if (missing.length > 0) {
134
+ console.error(`❌ 缺少必需参数: ${missing.join(', ')}`);
135
+ console.log('使用方法: nsgm deletedb <controller> [action]');
136
+ process.exit(1);
137
+ }
138
+ const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
139
+ action: 'all',
140
+ });
141
+ console.log(`🗑️ 删除控制器和数据库: ${finalOptions.controller}`);
142
+ console.log(`📝 操作: ${finalOptions.action}`);
143
+ (0, generate_1.deleteFiles)(finalOptions.controller, finalOptions.action, true, '');
144
+ console.log('✅ 删除完成!');
145
+ }
146
+ catch (error) {
147
+ console.error('❌ 删除失败:', error);
148
+ process.exit(1);
149
+ }
150
+ },
151
+ };
@@ -0,0 +1,2 @@
1
+ import { Command } from '../types';
2
+ export declare const exportCommand: Command;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportCommand = void 0;
4
+ const parser_1 = require("../parser");
5
+ const child_process_1 = require("child_process");
6
+ const util_1 = require("util");
7
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
8
+ exports.exportCommand = {
9
+ name: 'export',
10
+ aliases: [],
11
+ description: '导出静态网站',
12
+ usage: 'nsgm export [dictionary]',
13
+ examples: ['nsgm export', 'nsgm export webapp', 'nsgm export --dictionary=myapp'],
14
+ options: [
15
+ {
16
+ name: 'dictionary',
17
+ description: '输出目录名称',
18
+ default: 'webapp',
19
+ type: 'string',
20
+ },
21
+ ],
22
+ execute: async (options) => {
23
+ try {
24
+ const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
25
+ dictionary: 'webapp',
26
+ });
27
+ console.log(`📦 开始导出到目录: ${finalOptions.dictionary}`);
28
+ const shellCommand = `next export -o ${finalOptions.dictionary}`;
29
+ const { stdout, stderr } = await execAsync(shellCommand);
30
+ if (stderr) {
31
+ console.error('导出警告:', stderr);
32
+ }
33
+ console.log('✅ 导出完成!');
34
+ console.log(stdout);
35
+ process.exit(0);
36
+ }
37
+ catch (error) {
38
+ console.error('❌ 导出失败:', error);
39
+ process.exit(1);
40
+ }
41
+ },
42
+ };
@@ -0,0 +1,2 @@
1
+ import { Command } from '../types';
2
+ export declare const helpCommand: Command;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.helpCommand = void 0;
4
+ const utils_1 = require("../utils");
5
+ exports.helpCommand = {
6
+ name: 'help',
7
+ aliases: ['-h', '--help'],
8
+ description: '显示帮助信息',
9
+ usage: 'nsgm help [command]',
10
+ examples: ['nsgm help', 'nsgm help create'],
11
+ execute: async () => {
12
+ utils_1.Console.title('🎉 Welcome to use NSGM');
13
+ utils_1.Console.newLine();
14
+ utils_1.Console.subtitle('📖 使用方法:');
15
+ console.log(' nsgm <command> [options]');
16
+ utils_1.Console.newLine();
17
+ utils_1.Console.subtitle('🛠️ 可用命令:');
18
+ console.log(' help, -h, --help 显示帮助信息');
19
+ console.log(' version, -v, --version 显示版本信息');
20
+ console.log(' init, -i, --init 初始化项目 [dictionary]');
21
+ console.log(' upgrade, -u, --upgrade 升级项目');
22
+ console.log(' create, -c, --create 创建控制器 <controller> [action] [dictionary]');
23
+ console.log(' delete, -d, --delete 删除控制器 <controller> [action] [dictionary]');
24
+ console.log(' deletedb, -db, --deletedb 删除控制器和数据库 <controller> [action]');
25
+ console.log(' dev 开发模式启动');
26
+ console.log(' build 构建生产版本');
27
+ console.log(' start 生产模式启动');
28
+ console.log(' export 导出静态网站 [dictionary]');
29
+ utils_1.Console.newLine();
30
+ utils_1.Console.subtitle('💡 示例:');
31
+ console.log(' nsgm init myproject # 初始化项目到 myproject 目录');
32
+ console.log(' nsgm create user # 创建 user 控制器,默认 manage 操作');
33
+ console.log(' nsgm create user list # 创建 user 控制器的 list 操作');
34
+ console.log(' nsgm dev # 开发模式启动');
35
+ console.log(' nsgm build # 构建生产版本');
36
+ console.log(' nsgm export webapp # 导出到 webapp 目录');
37
+ utils_1.Console.newLine();
38
+ utils_1.Console.highlight('🎈 Happy to use!');
39
+ utils_1.Console.info('❓ If you have questions, please contact Erishen (787058731@qq.com)');
40
+ process.exit(0);
41
+ },
42
+ };
@@ -0,0 +1,2 @@
1
+ import { Command } from '../types';
2
+ export declare const initCommand: Command;