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
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initCommand = void 0;
4
+ const parser_1 = require("../parser");
5
+ const utils_1 = require("../utils");
6
+ const generate_1 = require("../../generate");
7
+ exports.initCommand = {
8
+ name: 'init',
9
+ aliases: ['-i', '--init'],
10
+ description: '初始化 NSGM 项目',
11
+ usage: 'nsgm init [dictionary] [options]',
12
+ examples: ['nsgm init', 'nsgm init myproject', 'nsgm init --dictionary=myproject'],
13
+ options: [
14
+ {
15
+ name: 'dictionary',
16
+ description: '项目目录名称',
17
+ default: '.',
18
+ type: 'string',
19
+ },
20
+ {
21
+ name: 'interactive',
22
+ description: '使用交互式向导',
23
+ default: true,
24
+ type: 'boolean',
25
+ },
26
+ ],
27
+ execute: async (options) => {
28
+ try {
29
+ let projectConfig;
30
+ // 智能判断是否使用交互模式:如果用户提供了 dictionary 参数且不是默认值,则自动使用非交互模式
31
+ if (options.dictionary && options.dictionary !== '.') {
32
+ options.interactive = false;
33
+ }
34
+ // 如果启用交互模式
35
+ if (options.interactive) {
36
+ const wizardResult = await utils_1.Prompt.initWizard();
37
+ utils_1.Console.separator();
38
+ utils_1.Console.title('📋 项目配置确认');
39
+ utils_1.Console.info(`项目名称: ${wizardResult.projectName}`);
40
+ utils_1.Console.info(`项目描述: ${wizardResult.description}`);
41
+ utils_1.Console.info(`作者: ${wizardResult.author}`);
42
+ utils_1.Console.info(`数据库: ${wizardResult.database ? '是' : '否'}`);
43
+ utils_1.Console.info(`功能: ${wizardResult.features.join(', ')}`);
44
+ utils_1.Console.separator();
45
+ const confirmed = await utils_1.Prompt.confirm('确认创建项目?', true);
46
+ if (!confirmed) {
47
+ utils_1.Console.warning('项目创建已取消');
48
+ process.exit(0);
49
+ }
50
+ options.dictionary = wizardResult.projectName;
51
+ projectConfig = wizardResult;
52
+ }
53
+ const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
54
+ dictionary: '.',
55
+ });
56
+ // 检查是否需要跳过初始化(保持原有逻辑)
57
+ let initFlag = true;
58
+ const argvArr = process.argv;
59
+ const argvArrLen = argvArr.length;
60
+ let fileName = '';
61
+ if (argvArrLen > 2) {
62
+ fileName = argvArr[2];
63
+ }
64
+ else if (argvArrLen > 1) {
65
+ fileName = argvArr[1];
66
+ }
67
+ if (fileName !== '') {
68
+ if (fileName.indexOf('\\') !== -1) {
69
+ fileName = fileName.replace(/\\/g, '/');
70
+ }
71
+ const fileNameArr = fileName.split('/');
72
+ const fileNameArrLen = fileNameArr.length;
73
+ const fileNameStr = fileNameArr[fileNameArrLen - 1];
74
+ if (fileNameStr === 'app') {
75
+ initFlag = false;
76
+ }
77
+ for (const item of fileNameArr) {
78
+ if (item === 'pm2') {
79
+ initFlag = false;
80
+ break;
81
+ }
82
+ }
83
+ }
84
+ if (initFlag) {
85
+ const spinner = utils_1.Console.spinner('正在初始化项目...', 'cyan');
86
+ spinner.start();
87
+ try {
88
+ await new Promise((resolve) => setTimeout(resolve, 1000)); // 模拟初始化时间
89
+ (0, generate_1.initFiles)(finalOptions.dictionary || '.', false, projectConfig);
90
+ spinner.succeed(`项目初始化完成! 目录: ${finalOptions.dictionary}`);
91
+ utils_1.Console.newLine();
92
+ utils_1.Console.box(`项目已成功创建到 ${finalOptions.dictionary} 目录\n\n` +
93
+ `下一步:\n` +
94
+ `1. cd ${finalOptions.dictionary}\n` +
95
+ `2. cp .env.example .env\n` +
96
+ `3. npm run generate-password yourPassword\n` +
97
+ `4. modify .env LOGIN_PASSWORD_HASH=yourEncryptedPassword\n` +
98
+ `5. npm run dev`, 'success');
99
+ }
100
+ catch (error) {
101
+ spinner.fail('项目初始化失败');
102
+ throw error;
103
+ }
104
+ }
105
+ else {
106
+ utils_1.Console.warning('跳过初始化(检测到特殊环境)');
107
+ }
108
+ process.exit(0);
109
+ }
110
+ catch (error) {
111
+ utils_1.Console.error(`初始化失败: ${error}`);
112
+ process.exit(1);
113
+ }
114
+ },
115
+ };
@@ -0,0 +1,3 @@
1
+ import { Command } from '../types';
2
+ export declare const devCommand: Command;
3
+ export declare const startCommand: Command;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startCommand = exports.devCommand = void 0;
4
+ const index_1 = require("../../index");
5
+ exports.devCommand = {
6
+ name: 'dev',
7
+ aliases: [],
8
+ description: '开发模式启动服务器',
9
+ usage: 'nsgm dev',
10
+ examples: ['nsgm dev'],
11
+ execute: async (_options) => {
12
+ console.log('🚀 启动开发服务器...');
13
+ (0, index_1.startExpress)({ dev: true }, undefined, 'dev');
14
+ },
15
+ };
16
+ exports.startCommand = {
17
+ name: 'start',
18
+ aliases: [],
19
+ description: '生产模式启动服务器',
20
+ usage: 'nsgm start',
21
+ examples: ['nsgm start'],
22
+ execute: async (_options) => {
23
+ console.log('🌟 启动生产服务器...');
24
+ (0, index_1.startExpress)({ dev: false }, undefined, 'start');
25
+ },
26
+ };
@@ -0,0 +1,2 @@
1
+ import { Command } from '../types';
2
+ export declare const upgradeCommand: Command;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.upgradeCommand = void 0;
4
+ const parser_1 = require("../parser");
5
+ const generate_1 = require("../../generate");
6
+ exports.upgradeCommand = {
7
+ name: 'upgrade',
8
+ aliases: ['-u', '--upgrade'],
9
+ description: '升级 NSGM 项目',
10
+ usage: 'nsgm upgrade [dictionary]',
11
+ examples: ['nsgm upgrade', 'nsgm upgrade myproject'],
12
+ options: [
13
+ {
14
+ name: 'dictionary',
15
+ description: '项目目录名称',
16
+ default: '',
17
+ type: 'string',
18
+ },
19
+ ],
20
+ execute: async (options) => {
21
+ try {
22
+ const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
23
+ dictionary: '',
24
+ });
25
+ console.log('⬆️ 升级 NSGM 项目...');
26
+ if (finalOptions.dictionary) {
27
+ console.log(`📁 目录: ${finalOptions.dictionary}`);
28
+ }
29
+ (0, generate_1.initFiles)(finalOptions.dictionary, true);
30
+ console.log('✅ 升级完成!');
31
+ process.exit(0);
32
+ }
33
+ catch (error) {
34
+ console.error('❌ 升级失败:', error);
35
+ process.exit(1);
36
+ }
37
+ },
38
+ };
@@ -0,0 +1,2 @@
1
+ import { Command } from '../types';
2
+ export declare const versionCommand: Command;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.versionCommand = void 0;
4
+ exports.versionCommand = {
5
+ name: 'version',
6
+ aliases: ['-v', '--version'],
7
+ description: '显示版本信息',
8
+ usage: 'nsgm version',
9
+ examples: ['nsgm version', 'nsgm -v'],
10
+ execute: async () => {
11
+ try {
12
+ const { version } = require('../../../package.json');
13
+ console.log(`📦 NSGM CLI 版本: ${version}`);
14
+ // 显示额外的环境信息
15
+ console.log(`🔧 Node.js 版本: ${process.version}`);
16
+ console.log(`💻 运行平台: ${process.platform} ${process.arch}`);
17
+ process.exit(0);
18
+ }
19
+ catch (error) {
20
+ console.error('❌ 无法获取版本信息:', error);
21
+ process.exit(1);
22
+ }
23
+ },
24
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * CLI 模块入口
3
+ */
4
+ export * from './types';
5
+ export * from './parser';
6
+ export * from './registry';
7
+ export * from './app';
8
+ export * from './commands/build';
9
+ export * from './commands/create';
10
+ export * from './commands/delete';
11
+ export * from './commands/export';
12
+ export * from './commands/help';
13
+ export * from './commands/init';
14
+ export * from './commands/server';
15
+ export * from './commands/upgrade';
16
+ export * from './commands/version';
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /**
3
+ * CLI 模块入口
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./types"), exports);
21
+ __exportStar(require("./parser"), exports);
22
+ __exportStar(require("./registry"), exports);
23
+ __exportStar(require("./app"), exports);
24
+ // 命令导出
25
+ __exportStar(require("./commands/build"), exports);
26
+ __exportStar(require("./commands/create"), exports);
27
+ __exportStar(require("./commands/delete"), exports);
28
+ __exportStar(require("./commands/export"), exports);
29
+ __exportStar(require("./commands/help"), exports);
30
+ __exportStar(require("./commands/init"), exports);
31
+ __exportStar(require("./commands/server"), exports);
32
+ __exportStar(require("./commands/upgrade"), exports);
33
+ __exportStar(require("./commands/version"), exports);
@@ -0,0 +1,22 @@
1
+ import { CommandOptions, ParsedArgs } from './types';
2
+ /**
3
+ * 改进的命令行参数解析器
4
+ */
5
+ export declare class ArgumentParser {
6
+ /**
7
+ * 解析命令行参数
8
+ */
9
+ static parse(args?: string[]): ParsedArgs;
10
+ /**
11
+ * 解析位置参数(保持向后兼容)
12
+ */
13
+ private static parsePositionalArgs;
14
+ /**
15
+ * 验证必需参数
16
+ */
17
+ static validateRequired(options: CommandOptions, required: string[]): string[];
18
+ /**
19
+ * 应用默认值
20
+ */
21
+ static applyDefaults(options: CommandOptions, defaults: Record<string, any>): CommandOptions;
22
+ }
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArgumentParser = void 0;
4
+ /**
5
+ * 改进的命令行参数解析器
6
+ */
7
+ class ArgumentParser {
8
+ /**
9
+ * 解析命令行参数
10
+ */
11
+ static parse(args = process.argv.slice(2)) {
12
+ if (args.length === 0) {
13
+ return { command: 'help', options: {} };
14
+ }
15
+ const command = args[0];
16
+ const options = {};
17
+ // 解析参数
18
+ for (let i = 1; i < args.length; i++) {
19
+ const arg = args[i];
20
+ if (arg.includes('=')) {
21
+ // 处理 key=value 格式
22
+ const [key, value] = arg.split('=', 2);
23
+ options[key.toLowerCase()] = value;
24
+ }
25
+ else if (arg.startsWith('--')) {
26
+ // 处理 --key value 格式
27
+ const key = arg.slice(2).toLowerCase();
28
+ const nextArg = args[i + 1];
29
+ if (nextArg && !nextArg.startsWith('-')) {
30
+ options[key] = nextArg;
31
+ i++; // 跳过下一个参数
32
+ }
33
+ else {
34
+ options[key] = true;
35
+ }
36
+ }
37
+ else if (arg.startsWith('-')) {
38
+ // 处理 -k value 格式
39
+ const key = arg.slice(1).toLowerCase();
40
+ const nextArg = args[i + 1];
41
+ if (nextArg && !nextArg.startsWith('-')) {
42
+ options[key] = nextArg;
43
+ i++; // 跳过下一个参数
44
+ }
45
+ else {
46
+ options[key] = true;
47
+ }
48
+ }
49
+ else {
50
+ // 处理位置参数
51
+ this.parsePositionalArgs(command, args.slice(1), options);
52
+ break;
53
+ }
54
+ }
55
+ return { command, options };
56
+ }
57
+ /**
58
+ * 解析位置参数(保持向后兼容)
59
+ */
60
+ static parsePositionalArgs(command, args, options) {
61
+ const createCommands = ['create', '-c', 'delete', '-d', 'deletedb', '-db'];
62
+ const initCommands = ['init', '-i', 'export'];
63
+ args.forEach((arg, index) => {
64
+ if (arg.includes('=') || arg.startsWith('-')) {
65
+ return; // 跳过已处理的参数
66
+ }
67
+ if (createCommands.includes(command)) {
68
+ switch (index) {
69
+ case 0:
70
+ if (!options.controller)
71
+ options.controller = arg;
72
+ break;
73
+ case 1:
74
+ if (!options.action)
75
+ options.action = arg;
76
+ break;
77
+ case 2:
78
+ if (!options.dictionary)
79
+ options.dictionary = arg;
80
+ break;
81
+ }
82
+ }
83
+ else if (initCommands.includes(command)) {
84
+ if (index === 0 && !options.dictionary) {
85
+ options.dictionary = arg;
86
+ }
87
+ }
88
+ });
89
+ }
90
+ /**
91
+ * 验证必需参数
92
+ */
93
+ static validateRequired(options, required) {
94
+ const missing = [];
95
+ for (const key of required) {
96
+ if (!options[key] || options[key] === '') {
97
+ missing.push(key);
98
+ }
99
+ }
100
+ return missing;
101
+ }
102
+ /**
103
+ * 应用默认值
104
+ */
105
+ static applyDefaults(options, defaults) {
106
+ const result = { ...options };
107
+ for (const [key, value] of Object.entries(defaults)) {
108
+ if (result[key] === undefined || result[key] === '') {
109
+ result[key] = value;
110
+ }
111
+ }
112
+ return result;
113
+ }
114
+ }
115
+ exports.ArgumentParser = ArgumentParser;
@@ -0,0 +1,33 @@
1
+ import { Command } from './types';
2
+ /**
3
+ * CLI 命令注册表
4
+ */
5
+ export declare class CommandRegistry {
6
+ private commands;
7
+ private aliases;
8
+ constructor();
9
+ /**
10
+ * 注册默认命令
11
+ */
12
+ private registerDefaultCommands;
13
+ /**
14
+ * 注册命令
15
+ */
16
+ register(command: Command): void;
17
+ /**
18
+ * 获取命令
19
+ */
20
+ get(name: string): Command | undefined;
21
+ /**
22
+ * 获取所有命令
23
+ */
24
+ getAll(): Command[];
25
+ /**
26
+ * 获取所有命令(别名方法)
27
+ */
28
+ getAllCommands(): Command[];
29
+ /**
30
+ * 检查命令是否存在
31
+ */
32
+ has(name: string): boolean;
33
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandRegistry = void 0;
4
+ const build_1 = require("./commands/build");
5
+ const create_1 = require("./commands/create");
6
+ const delete_1 = require("./commands/delete");
7
+ const export_1 = require("./commands/export");
8
+ const help_1 = require("./commands/help");
9
+ const init_1 = require("./commands/init");
10
+ const server_1 = require("./commands/server");
11
+ const upgrade_1 = require("./commands/upgrade");
12
+ const version_1 = require("./commands/version");
13
+ /**
14
+ * CLI 命令注册表
15
+ */
16
+ class CommandRegistry {
17
+ constructor() {
18
+ this.commands = new Map();
19
+ this.aliases = new Map();
20
+ this.registerDefaultCommands();
21
+ }
22
+ /**
23
+ * 注册默认命令
24
+ */
25
+ registerDefaultCommands() {
26
+ const commands = [
27
+ build_1.buildCommand,
28
+ create_1.createCommand,
29
+ delete_1.deleteCommand,
30
+ delete_1.deleteDbCommand,
31
+ export_1.exportCommand,
32
+ help_1.helpCommand,
33
+ init_1.initCommand,
34
+ server_1.devCommand,
35
+ server_1.startCommand,
36
+ upgrade_1.upgradeCommand,
37
+ version_1.versionCommand,
38
+ ];
39
+ for (const command of commands) {
40
+ this.register(command);
41
+ }
42
+ }
43
+ /**
44
+ * 注册命令
45
+ */
46
+ register(command) {
47
+ this.commands.set(command.name, command);
48
+ // 注册别名
49
+ for (const alias of command.aliases) {
50
+ this.aliases.set(alias, command.name);
51
+ }
52
+ }
53
+ /**
54
+ * 获取命令
55
+ */
56
+ get(name) {
57
+ // 首先检查是否是别名
58
+ const realName = this.aliases.get(name) || name;
59
+ return this.commands.get(realName);
60
+ }
61
+ /**
62
+ * 获取所有命令
63
+ */
64
+ getAll() {
65
+ return Array.from(this.commands.values());
66
+ }
67
+ /**
68
+ * 获取所有命令(别名方法)
69
+ */
70
+ getAllCommands() {
71
+ return this.getAll();
72
+ }
73
+ /**
74
+ * 检查命令是否存在
75
+ */
76
+ has(name) {
77
+ const realName = this.aliases.get(name) || name;
78
+ return this.commands.has(realName);
79
+ }
80
+ }
81
+ exports.CommandRegistry = CommandRegistry;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 项目配置接口
3
+ */
4
+ export interface ProjectConfig {
5
+ projectName: string;
6
+ description: string;
7
+ author: string;
8
+ database: boolean;
9
+ features: string[];
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * CLI 类型定义
3
+ */
4
+ export * from './types/project';
5
+ export interface CommandOptions {
6
+ dictionary?: string;
7
+ controller?: string;
8
+ action?: string;
9
+ [key: string]: any;
10
+ }
11
+ export interface Command {
12
+ name: string;
13
+ aliases: string[];
14
+ description: string;
15
+ usage?: string;
16
+ examples?: string[];
17
+ options?: CommandOption[];
18
+ execute: (options: CommandOptions) => Promise<void> | void;
19
+ }
20
+ export interface CommandOption {
21
+ name: string;
22
+ alias?: string;
23
+ description: string;
24
+ required?: boolean;
25
+ default?: any;
26
+ type?: 'string' | 'number' | 'boolean';
27
+ }
28
+ export interface ParsedArgs {
29
+ command: string;
30
+ options: CommandOptions;
31
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * CLI 类型定义
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./types/project"), exports);
@@ -0,0 +1,62 @@
1
+ /**
2
+ * 控制台输出工具类
3
+ */
4
+ export declare class Console {
5
+ /**
6
+ * 成功消息
7
+ */
8
+ static success(message: string): void;
9
+ /**
10
+ * 错误消息
11
+ */
12
+ static error(message: string): void;
13
+ /**
14
+ * 警告消息
15
+ */
16
+ static warning(message: string): void;
17
+ /**
18
+ * 信息消息
19
+ */
20
+ static info(message: string): void;
21
+ /**
22
+ * 调试消息
23
+ */
24
+ static debug(message: string): void;
25
+ /**
26
+ * 标题
27
+ */
28
+ static title(message: string): void;
29
+ /**
30
+ * 副标题
31
+ */
32
+ static subtitle(message: string): void;
33
+ /**
34
+ * 突出显示
35
+ */
36
+ static highlight(message: string): void;
37
+ /**
38
+ * 分隔线
39
+ */
40
+ static separator(): void;
41
+ /**
42
+ * 空行
43
+ */
44
+ static newLine(count?: number): void;
45
+ /**
46
+ * 简单的加载动画
47
+ */
48
+ static spinner(text: string, color?: 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white'): {
49
+ start(): void;
50
+ stop(): void;
51
+ succeed(message?: string): void;
52
+ fail(message?: string): void;
53
+ };
54
+ /**
55
+ * 带边框的消息
56
+ */
57
+ static box(message: string, type?: 'success' | 'error' | 'warning' | 'info'): void;
58
+ /**
59
+ * 进度条(简单版本)
60
+ */
61
+ static progress(current: number, total: number, description?: string): void;
62
+ }