nsgm-cli 2.1.19 → 2.1.21
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.
- package/client/components/Button.tsx +3 -3
- package/client/components/ClientProviders.tsx +12 -12
- package/client/components/LanguageSwitcher.tsx +26 -26
- package/client/components/SSRSafeAntdProvider.tsx +7 -7
- package/client/components/SuppressHydrationWarnings.tsx +30 -30
- package/client/components/__tests__/Button.test.tsx +12 -12
- package/client/layout/index.tsx +124 -124
- package/client/redux/reducers.ts +2 -2
- package/client/redux/store.ts +24 -24
- package/client/redux/template/manage/actions.ts +40 -40
- package/client/redux/template/manage/reducers.ts +32 -32
- package/client/redux/template/manage/types.ts +19 -19
- package/client/service/template/manage.ts +29 -29
- package/client/styled/common.ts +6 -6
- package/client/styled/layout/index.ts +17 -17
- package/client/styled/template/manage.ts +19 -19
- package/client/utils/common.ts +54 -54
- package/client/utils/cookie.ts +30 -30
- package/client/utils/fetch.ts +111 -111
- package/client/utils/i18n.ts +41 -41
- package/client/utils/menu.tsx +12 -12
- package/client/utils/navigation.ts +22 -22
- package/client/utils/sso.ts +124 -124
- package/client/utils/suppressWarnings.ts +17 -17
- package/generation/prettierrc +6 -0
- package/lib/args.js +19 -19
- package/lib/cli/app.d.ts +1 -1
- package/lib/cli/app.js +2 -2
- package/lib/cli/commands/build.d.ts +1 -1
- package/lib/cli/commands/build.js +9 -9
- package/lib/cli/commands/create.d.ts +1 -1
- package/lib/cli/commands/create.js +36 -36
- package/lib/cli/commands/delete.d.ts +1 -1
- package/lib/cli/commands/delete.js +55 -55
- package/lib/cli/commands/export.d.ts +1 -1
- package/lib/cli/commands/export.js +12 -12
- package/lib/cli/commands/help.d.ts +1 -1
- package/lib/cli/commands/help.js +29 -29
- package/lib/cli/commands/init.d.ts +1 -1
- package/lib/cli/commands/init.js +31 -31
- package/lib/cli/commands/server.d.ts +1 -1
- package/lib/cli/commands/server.js +12 -12
- package/lib/cli/commands/upgrade.d.ts +1 -1
- package/lib/cli/commands/upgrade.js +13 -13
- package/lib/cli/commands/version.d.ts +1 -1
- package/lib/cli/commands/version.js +7 -7
- package/lib/cli/index.d.ts +13 -13
- package/lib/cli/parser.d.ts +1 -1
- package/lib/cli/parser.js +12 -12
- package/lib/cli/registry.d.ts +1 -1
- package/lib/cli/types.d.ts +2 -2
- package/lib/cli/utils/console.d.ts +2 -2
- package/lib/cli/utils/console.js +22 -22
- package/lib/cli/utils/index.d.ts +2 -2
- package/lib/cli/utils/prompt.d.ts +1 -1
- package/lib/cli/utils/prompt.js +98 -98
- package/lib/constants.js +28 -28
- package/lib/generate.d.ts +2 -2
- package/lib/generate.js +19 -19
- package/lib/generate_create.d.ts +1 -1
- package/lib/generate_create.js +38 -38
- package/lib/generate_delete.js +63 -63
- package/lib/generate_init.js +94 -94
- package/lib/generators/base-generator.d.ts +1 -1
- package/lib/generators/base-generator.js +23 -23
- package/lib/generators/file-generator.js +15 -15
- package/lib/generators/generator-factory.d.ts +5 -5
- package/lib/generators/i18n-generator.d.ts +1 -1
- package/lib/generators/i18n-generator.js +127 -127
- package/lib/generators/page-generator.d.ts +1 -1
- package/lib/generators/page-generator.js +25 -25
- package/lib/generators/resolver-generator.d.ts +1 -1
- package/lib/generators/resolver-generator.js +27 -27
- package/lib/generators/schema-generator.d.ts +1 -1
- package/lib/generators/schema-generator.js +4 -4
- package/lib/generators/service-generator.d.ts +1 -1
- package/lib/generators/service-generator.js +29 -29
- package/lib/generators/sql-generator.d.ts +1 -1
- package/lib/generators/sql-generator.js +10 -10
- package/lib/index.js +23 -23
- package/lib/server/csrf.d.ts +3 -3
- package/lib/server/csrf.js +20 -20
- package/lib/server/db.d.ts +1 -1
- package/lib/server/db.js +21 -21
- package/lib/server/graphql.js +26 -26
- package/lib/server/plugins/date.d.ts +1 -1
- package/lib/server/plugins/date.js +6 -6
- package/lib/server/utils/graphql-cache.js +5 -5
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/utils/project-config.d.ts +1 -1
- package/lib/utils/project-config.js +20 -20
- package/lib/utils.js +3 -3
- package/package.json +1 -1
- package/pages/_app.tsx +62 -62
- package/pages/_document.tsx +15 -15
- package/pages/_error.tsx +26 -26
- package/pages/index.tsx +48 -48
- package/pages/login.tsx +64 -64
- package/pages/template/manage.tsx +175 -175
|
@@ -5,61 +5,61 @@ const parser_1 = require("../parser");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const generate_1 = require("../../generate");
|
|
7
7
|
exports.createCommand = {
|
|
8
|
-
name:
|
|
9
|
-
aliases: [
|
|
10
|
-
description:
|
|
11
|
-
usage:
|
|
12
|
-
examples: [
|
|
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
13
|
options: [
|
|
14
14
|
{
|
|
15
|
-
name:
|
|
16
|
-
description:
|
|
15
|
+
name: "controller",
|
|
16
|
+
description: "控制器名称",
|
|
17
17
|
required: false,
|
|
18
|
-
type:
|
|
18
|
+
type: "string",
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
name:
|
|
22
|
-
description:
|
|
23
|
-
default:
|
|
24
|
-
type:
|
|
21
|
+
name: "action",
|
|
22
|
+
description: "操作名称",
|
|
23
|
+
default: "manage",
|
|
24
|
+
type: "string",
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
name:
|
|
28
|
-
description:
|
|
29
|
-
default:
|
|
30
|
-
type:
|
|
27
|
+
name: "dictionary",
|
|
28
|
+
description: "项目目录",
|
|
29
|
+
default: "",
|
|
30
|
+
type: "string",
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
name:
|
|
34
|
-
description:
|
|
33
|
+
name: "interactive",
|
|
34
|
+
description: "使用交互式向导",
|
|
35
35
|
default: true,
|
|
36
|
-
type:
|
|
36
|
+
type: "boolean",
|
|
37
37
|
},
|
|
38
38
|
],
|
|
39
39
|
execute: async (options) => {
|
|
40
40
|
try {
|
|
41
41
|
// 智能判断是否使用交互模式:如果用户提供了 controller 参数,则自动使用非交互模式
|
|
42
|
-
if (options.controller && options.controller.trim() !==
|
|
42
|
+
if (options.controller && options.controller.trim() !== "") {
|
|
43
43
|
options.interactive = false;
|
|
44
44
|
}
|
|
45
45
|
// 如果启用交互模式
|
|
46
46
|
if (options.interactive) {
|
|
47
47
|
const wizardResult = await utils_1.Prompt.createControllerWizard();
|
|
48
48
|
utils_1.Console.separator();
|
|
49
|
-
utils_1.Console.title(
|
|
49
|
+
utils_1.Console.title("📋 控制器配置确认");
|
|
50
50
|
utils_1.Console.info(`项目目录: ${wizardResult.dictionary}`);
|
|
51
51
|
utils_1.Console.info(`控制器名称: ${wizardResult.controller}`);
|
|
52
52
|
utils_1.Console.info(`功能模块: 完整CRUD + 导入导出 + 批量删除`);
|
|
53
53
|
utils_1.Console.info(`描述: ${wizardResult.description}`);
|
|
54
|
-
utils_1.Console.info(`数据库表: ${wizardResult.includeDatabase ?
|
|
54
|
+
utils_1.Console.info(`数据库表: ${wizardResult.includeDatabase ? "是" : "否"}`);
|
|
55
55
|
if (wizardResult.includeDatabase && wizardResult.fields.length > 0) {
|
|
56
|
-
const fieldNames = wizardResult.fields.map((field) => field.name).join(
|
|
56
|
+
const fieldNames = wizardResult.fields.map((field) => field.name).join(", ");
|
|
57
57
|
utils_1.Console.info(`字段: ${fieldNames}`);
|
|
58
58
|
}
|
|
59
59
|
utils_1.Console.separator();
|
|
60
|
-
const confirmed = await utils_1.Prompt.confirm(
|
|
60
|
+
const confirmed = await utils_1.Prompt.confirm("确认创建控制器?", true);
|
|
61
61
|
if (!confirmed) {
|
|
62
|
-
utils_1.Console.warning(
|
|
62
|
+
utils_1.Console.warning("控制器创建已取消");
|
|
63
63
|
process.exit(0);
|
|
64
64
|
}
|
|
65
65
|
// 更新选项
|
|
@@ -70,38 +70,38 @@ exports.createCommand = {
|
|
|
70
70
|
}
|
|
71
71
|
// 验证必需参数(仅在非交互模式下)
|
|
72
72
|
if (!options.interactive) {
|
|
73
|
-
const missing = parser_1.ArgumentParser.validateRequired(options, [
|
|
73
|
+
const missing = parser_1.ArgumentParser.validateRequired(options, ["controller"]);
|
|
74
74
|
if (missing.length > 0) {
|
|
75
|
-
utils_1.Console.error(`缺少必需参数: ${missing.join(
|
|
76
|
-
utils_1.Console.info(
|
|
77
|
-
utils_1.Console.info(
|
|
78
|
-
utils_1.Console.info(
|
|
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
79
|
process.exit(1);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
|
|
83
|
-
action:
|
|
84
|
-
dictionary:
|
|
83
|
+
action: "manage",
|
|
84
|
+
dictionary: "",
|
|
85
85
|
});
|
|
86
86
|
utils_1.Console.highlight(`🎯 创建控制器: ${finalOptions.controller}`);
|
|
87
87
|
utils_1.Console.info(`📝 操作: ${finalOptions.action}`);
|
|
88
88
|
if (finalOptions.dictionary) {
|
|
89
89
|
utils_1.Console.info(`📁 目录: ${finalOptions.dictionary}`);
|
|
90
90
|
}
|
|
91
|
-
const spinner = utils_1.Console.spinner(
|
|
91
|
+
const spinner = utils_1.Console.spinner("正在创建文件...", "green");
|
|
92
92
|
spinner.start();
|
|
93
93
|
try {
|
|
94
94
|
// 模拟创建过程
|
|
95
95
|
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
96
96
|
(0, generate_1.createFiles)(finalOptions.controller, finalOptions.action, finalOptions.dictionary, finalOptions.fields);
|
|
97
|
-
spinner.succeed(
|
|
97
|
+
spinner.succeed("控制器创建完成!");
|
|
98
98
|
utils_1.Console.newLine();
|
|
99
99
|
utils_1.Console.box(`控制器 "${finalOptions.controller}" 已创建成功!\n\n` +
|
|
100
100
|
`操作: ${finalOptions.action}\n` +
|
|
101
|
-
`路径: ${finalOptions.dictionary ||
|
|
101
|
+
`路径: ${finalOptions.dictionary || "./"}`, "success");
|
|
102
102
|
}
|
|
103
103
|
catch (error) {
|
|
104
|
-
spinner.fail(
|
|
104
|
+
spinner.fail("控制器创建失败");
|
|
105
105
|
throw error;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -5,57 +5,57 @@ const parser_1 = require("../parser");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const generate_1 = require("../../generate");
|
|
7
7
|
exports.deleteCommand = {
|
|
8
|
-
name:
|
|
9
|
-
aliases: [
|
|
10
|
-
description:
|
|
11
|
-
usage:
|
|
12
|
-
examples: [
|
|
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
13
|
options: [
|
|
14
14
|
{
|
|
15
|
-
name:
|
|
16
|
-
description:
|
|
15
|
+
name: "controller",
|
|
16
|
+
description: "控制器名称",
|
|
17
17
|
required: false,
|
|
18
|
-
type:
|
|
18
|
+
type: "string",
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
name:
|
|
22
|
-
description:
|
|
23
|
-
default:
|
|
24
|
-
type:
|
|
21
|
+
name: "action",
|
|
22
|
+
description: "操作名称",
|
|
23
|
+
default: "all",
|
|
24
|
+
type: "string",
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
name:
|
|
28
|
-
description:
|
|
29
|
-
default:
|
|
30
|
-
type:
|
|
27
|
+
name: "dictionary",
|
|
28
|
+
description: "项目目录",
|
|
29
|
+
default: "",
|
|
30
|
+
type: "string",
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
name:
|
|
34
|
-
description:
|
|
33
|
+
name: "interactive",
|
|
34
|
+
description: "使用交互式向导",
|
|
35
35
|
default: true,
|
|
36
|
-
type:
|
|
36
|
+
type: "boolean",
|
|
37
37
|
},
|
|
38
38
|
],
|
|
39
39
|
execute: async (options) => {
|
|
40
40
|
try {
|
|
41
41
|
let deleteDatabase = false;
|
|
42
42
|
// 智能判断是否使用交互模式:如果用户提供了 controller 参数,则自动使用非交互模式
|
|
43
|
-
if (options.controller && options.controller.trim() !==
|
|
43
|
+
if (options.controller && options.controller.trim() !== "") {
|
|
44
44
|
options.interactive = false;
|
|
45
45
|
}
|
|
46
46
|
// 如果启用交互模式
|
|
47
47
|
if (options.interactive) {
|
|
48
48
|
const wizardResult = await utils_1.Prompt.deleteControllerWizard();
|
|
49
49
|
utils_1.Console.separator();
|
|
50
|
-
utils_1.Console.title(
|
|
50
|
+
utils_1.Console.title("📋 删除确认");
|
|
51
51
|
utils_1.Console.info(`项目目录: ${wizardResult.dictionary}`);
|
|
52
52
|
utils_1.Console.info(`控制器名称: ${wizardResult.controller}`);
|
|
53
|
-
utils_1.Console.info(`删除范围: ${wizardResult.action ===
|
|
54
|
-
utils_1.Console.info(`删除数据库: ${wizardResult.deleteDatabase ?
|
|
53
|
+
utils_1.Console.info(`删除范围: ${wizardResult.action === "all" ? "所有相关文件" : "指定操作"}`);
|
|
54
|
+
utils_1.Console.info(`删除数据库: ${wizardResult.deleteDatabase ? "是" : "否"}`);
|
|
55
55
|
utils_1.Console.separator();
|
|
56
|
-
const confirmed = await utils_1.Prompt.confirm(
|
|
56
|
+
const confirmed = await utils_1.Prompt.confirm("确认删除?此操作不可恢复!", false);
|
|
57
57
|
if (!confirmed) {
|
|
58
|
-
utils_1.Console.warning(
|
|
58
|
+
utils_1.Console.warning("删除操作已取消");
|
|
59
59
|
process.exit(0);
|
|
60
60
|
}
|
|
61
61
|
// 更新选项
|
|
@@ -66,37 +66,37 @@ exports.deleteCommand = {
|
|
|
66
66
|
}
|
|
67
67
|
// 验证必需参数(仅在非交互模式下)
|
|
68
68
|
if (!options.interactive) {
|
|
69
|
-
const missing = parser_1.ArgumentParser.validateRequired(options, [
|
|
69
|
+
const missing = parser_1.ArgumentParser.validateRequired(options, ["controller"]);
|
|
70
70
|
if (missing.length > 0) {
|
|
71
|
-
utils_1.Console.error(`缺少必需参数: ${missing.join(
|
|
72
|
-
utils_1.Console.info(
|
|
73
|
-
utils_1.Console.info(
|
|
74
|
-
utils_1.Console.info(
|
|
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
75
|
process.exit(1);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
|
|
79
|
-
action:
|
|
80
|
-
dictionary:
|
|
79
|
+
action: "all",
|
|
80
|
+
dictionary: "",
|
|
81
81
|
});
|
|
82
82
|
utils_1.Console.highlight(`🗑️ 删除控制器: ${finalOptions.controller}`);
|
|
83
83
|
utils_1.Console.info(`📝 操作: ${finalOptions.action}`);
|
|
84
84
|
if (finalOptions.dictionary) {
|
|
85
85
|
utils_1.Console.info(`📁 目录: ${finalOptions.dictionary}`);
|
|
86
86
|
}
|
|
87
|
-
const spinner = utils_1.Console.spinner(
|
|
87
|
+
const spinner = utils_1.Console.spinner("正在删除文件...", "red");
|
|
88
88
|
spinner.start();
|
|
89
89
|
try {
|
|
90
90
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
91
91
|
(0, generate_1.deleteFiles)(finalOptions.controller, finalOptions.action, deleteDatabase, finalOptions.dictionary);
|
|
92
|
-
spinner.succeed(
|
|
92
|
+
spinner.succeed("删除完成!");
|
|
93
93
|
utils_1.Console.newLine();
|
|
94
94
|
utils_1.Console.box(`控制器 "${finalOptions.controller}" 已删除成功!\n\n` +
|
|
95
95
|
`操作: ${finalOptions.action}\n` +
|
|
96
|
-
`路径: ${finalOptions.dictionary ||
|
|
96
|
+
`路径: ${finalOptions.dictionary || "./"}${deleteDatabase ? "\n数据库表: 已删除" : ""}`, "success");
|
|
97
97
|
}
|
|
98
98
|
catch (error) {
|
|
99
|
-
spinner.fail(
|
|
99
|
+
spinner.fail("删除失败");
|
|
100
100
|
throw error;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -107,44 +107,44 @@ exports.deleteCommand = {
|
|
|
107
107
|
},
|
|
108
108
|
};
|
|
109
109
|
exports.deleteDbCommand = {
|
|
110
|
-
name:
|
|
111
|
-
aliases: [
|
|
112
|
-
description:
|
|
113
|
-
usage:
|
|
114
|
-
examples: [
|
|
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
115
|
options: [
|
|
116
116
|
{
|
|
117
|
-
name:
|
|
118
|
-
description:
|
|
117
|
+
name: "controller",
|
|
118
|
+
description: "控制器名称",
|
|
119
119
|
required: true,
|
|
120
|
-
type:
|
|
120
|
+
type: "string",
|
|
121
121
|
},
|
|
122
122
|
{
|
|
123
|
-
name:
|
|
124
|
-
description:
|
|
125
|
-
default:
|
|
126
|
-
type:
|
|
123
|
+
name: "action",
|
|
124
|
+
description: "操作名称",
|
|
125
|
+
default: "all",
|
|
126
|
+
type: "string",
|
|
127
127
|
},
|
|
128
128
|
],
|
|
129
129
|
execute: async (options) => {
|
|
130
130
|
try {
|
|
131
131
|
// 验证必需参数
|
|
132
|
-
const missing = parser_1.ArgumentParser.validateRequired(options, [
|
|
132
|
+
const missing = parser_1.ArgumentParser.validateRequired(options, ["controller"]);
|
|
133
133
|
if (missing.length > 0) {
|
|
134
|
-
console.error(`❌ 缺少必需参数: ${missing.join(
|
|
135
|
-
console.log(
|
|
134
|
+
console.error(`❌ 缺少必需参数: ${missing.join(", ")}`);
|
|
135
|
+
console.log("使用方法: nsgm deletedb <controller> [action]");
|
|
136
136
|
process.exit(1);
|
|
137
137
|
}
|
|
138
138
|
const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
|
|
139
|
-
action:
|
|
139
|
+
action: "all",
|
|
140
140
|
});
|
|
141
141
|
console.log(`🗑️ 删除控制器和数据库: ${finalOptions.controller}`);
|
|
142
142
|
console.log(`📝 操作: ${finalOptions.action}`);
|
|
143
|
-
(0, generate_1.deleteFiles)(finalOptions.controller, finalOptions.action, true,
|
|
144
|
-
console.log(
|
|
143
|
+
(0, generate_1.deleteFiles)(finalOptions.controller, finalOptions.action, true, "");
|
|
144
|
+
console.log("✅ 删除完成!");
|
|
145
145
|
}
|
|
146
146
|
catch (error) {
|
|
147
|
-
console.error(
|
|
147
|
+
console.error("❌ 删除失败:", error);
|
|
148
148
|
process.exit(1);
|
|
149
149
|
}
|
|
150
150
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "../types";
|
|
2
2
|
export declare const exportCommand: Command;
|
|
@@ -6,36 +6,36 @@ const child_process_1 = require("child_process");
|
|
|
6
6
|
const util_1 = require("util");
|
|
7
7
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
8
8
|
exports.exportCommand = {
|
|
9
|
-
name:
|
|
9
|
+
name: "export",
|
|
10
10
|
aliases: [],
|
|
11
|
-
description:
|
|
12
|
-
usage:
|
|
13
|
-
examples: [
|
|
11
|
+
description: "导出静态网站",
|
|
12
|
+
usage: "nsgm export [dictionary]",
|
|
13
|
+
examples: ["nsgm export", "nsgm export webapp", "nsgm export --dictionary=myapp"],
|
|
14
14
|
options: [
|
|
15
15
|
{
|
|
16
|
-
name:
|
|
17
|
-
description:
|
|
18
|
-
default:
|
|
19
|
-
type:
|
|
16
|
+
name: "dictionary",
|
|
17
|
+
description: "输出目录名称",
|
|
18
|
+
default: "webapp",
|
|
19
|
+
type: "string",
|
|
20
20
|
},
|
|
21
21
|
],
|
|
22
22
|
execute: async (options) => {
|
|
23
23
|
try {
|
|
24
24
|
const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
|
|
25
|
-
dictionary:
|
|
25
|
+
dictionary: "webapp",
|
|
26
26
|
});
|
|
27
27
|
console.log(`📦 开始导出到目录: ${finalOptions.dictionary}`);
|
|
28
28
|
const shellCommand = `next export -o ${finalOptions.dictionary}`;
|
|
29
29
|
const { stdout, stderr } = await execAsync(shellCommand);
|
|
30
30
|
if (stderr) {
|
|
31
|
-
console.error(
|
|
31
|
+
console.error("导出警告:", stderr);
|
|
32
32
|
}
|
|
33
|
-
console.log(
|
|
33
|
+
console.log("✅ 导出完成!");
|
|
34
34
|
console.log(stdout);
|
|
35
35
|
process.exit(0);
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
|
-
console.error(
|
|
38
|
+
console.error("❌ 导出失败:", error);
|
|
39
39
|
process.exit(1);
|
|
40
40
|
}
|
|
41
41
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "../types";
|
|
2
2
|
export declare const helpCommand: Command;
|
package/lib/cli/commands/help.js
CHANGED
|
@@ -3,40 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.helpCommand = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
exports.helpCommand = {
|
|
6
|
-
name:
|
|
7
|
-
aliases: [
|
|
8
|
-
description:
|
|
9
|
-
usage:
|
|
10
|
-
examples: [
|
|
6
|
+
name: "help",
|
|
7
|
+
aliases: ["-h", "--help"],
|
|
8
|
+
description: "显示帮助信息",
|
|
9
|
+
usage: "nsgm help [command]",
|
|
10
|
+
examples: ["nsgm help", "nsgm help create"],
|
|
11
11
|
execute: async () => {
|
|
12
|
-
utils_1.Console.title(
|
|
12
|
+
utils_1.Console.title("🎉 Welcome to use NSGM");
|
|
13
13
|
utils_1.Console.newLine();
|
|
14
|
-
utils_1.Console.subtitle(
|
|
15
|
-
console.log(
|
|
14
|
+
utils_1.Console.subtitle("📖 使用方法:");
|
|
15
|
+
console.log(" nsgm <command> [options]");
|
|
16
16
|
utils_1.Console.newLine();
|
|
17
|
-
utils_1.Console.subtitle(
|
|
18
|
-
console.log(
|
|
19
|
-
console.log(
|
|
20
|
-
console.log(
|
|
21
|
-
console.log(
|
|
22
|
-
console.log(
|
|
23
|
-
console.log(
|
|
24
|
-
console.log(
|
|
25
|
-
console.log(
|
|
26
|
-
console.log(
|
|
27
|
-
console.log(
|
|
28
|
-
console.log(
|
|
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
29
|
utils_1.Console.newLine();
|
|
30
|
-
utils_1.Console.subtitle(
|
|
31
|
-
console.log(
|
|
32
|
-
console.log(
|
|
33
|
-
console.log(
|
|
34
|
-
console.log(
|
|
35
|
-
console.log(
|
|
36
|
-
console.log(
|
|
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
37
|
utils_1.Console.newLine();
|
|
38
|
-
utils_1.Console.highlight(
|
|
39
|
-
utils_1.Console.info(
|
|
38
|
+
utils_1.Console.highlight("🎈 Happy to use!");
|
|
39
|
+
utils_1.Console.info("❓ If you have questions, please contact Erishen (787058731@qq.com)");
|
|
40
40
|
process.exit(0);
|
|
41
41
|
},
|
|
42
42
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "../types";
|
|
2
2
|
export declare const initCommand: Command;
|
package/lib/cli/commands/init.js
CHANGED
|
@@ -5,88 +5,88 @@ const parser_1 = require("../parser");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const generate_1 = require("../../generate");
|
|
7
7
|
exports.initCommand = {
|
|
8
|
-
name:
|
|
9
|
-
aliases: [
|
|
10
|
-
description:
|
|
11
|
-
usage:
|
|
12
|
-
examples: [
|
|
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
13
|
options: [
|
|
14
14
|
{
|
|
15
|
-
name:
|
|
16
|
-
description:
|
|
17
|
-
default:
|
|
18
|
-
type:
|
|
15
|
+
name: "dictionary",
|
|
16
|
+
description: "项目目录",
|
|
17
|
+
default: ".",
|
|
18
|
+
type: "string",
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
name:
|
|
22
|
-
description:
|
|
21
|
+
name: "interactive",
|
|
22
|
+
description: "使用交互式向导",
|
|
23
23
|
default: true,
|
|
24
|
-
type:
|
|
24
|
+
type: "boolean",
|
|
25
25
|
},
|
|
26
26
|
],
|
|
27
27
|
execute: async (options) => {
|
|
28
28
|
try {
|
|
29
29
|
let projectConfig;
|
|
30
30
|
// 智能判断是否使用交互模式:如果用户提供了 dictionary 参数且不是默认值,则自动使用非交互模式
|
|
31
|
-
if (options.dictionary && options.dictionary !==
|
|
31
|
+
if (options.dictionary && options.dictionary !== ".") {
|
|
32
32
|
options.interactive = false;
|
|
33
33
|
}
|
|
34
34
|
// 如果启用交互模式
|
|
35
35
|
if (options.interactive) {
|
|
36
36
|
const wizardResult = await utils_1.Prompt.initWizard();
|
|
37
37
|
utils_1.Console.separator();
|
|
38
|
-
utils_1.Console.title(
|
|
38
|
+
utils_1.Console.title("📋 项目配置确认");
|
|
39
39
|
utils_1.Console.info(`项目目录: ${wizardResult.projectName}`);
|
|
40
40
|
utils_1.Console.info(`项目描述: ${wizardResult.description}`);
|
|
41
41
|
utils_1.Console.info(`作者: ${wizardResult.author}`);
|
|
42
|
-
utils_1.Console.info(`数据库: ${wizardResult.database ?
|
|
43
|
-
utils_1.Console.info(`功能: ${wizardResult.features.join(
|
|
42
|
+
utils_1.Console.info(`数据库: ${wizardResult.database ? "是" : "否"}`);
|
|
43
|
+
utils_1.Console.info(`功能: ${wizardResult.features.join(", ")}`);
|
|
44
44
|
utils_1.Console.separator();
|
|
45
|
-
const confirmed = await utils_1.Prompt.confirm(
|
|
45
|
+
const confirmed = await utils_1.Prompt.confirm("确认创建项目?", true);
|
|
46
46
|
if (!confirmed) {
|
|
47
|
-
utils_1.Console.warning(
|
|
47
|
+
utils_1.Console.warning("项目创建已取消");
|
|
48
48
|
process.exit(0);
|
|
49
49
|
}
|
|
50
50
|
options.dictionary = wizardResult.projectName;
|
|
51
51
|
projectConfig = wizardResult;
|
|
52
52
|
}
|
|
53
53
|
const finalOptions = parser_1.ArgumentParser.applyDefaults(options, {
|
|
54
|
-
dictionary:
|
|
54
|
+
dictionary: ".",
|
|
55
55
|
});
|
|
56
56
|
// 检查是否需要跳过初始化(保持原有逻辑)
|
|
57
57
|
let initFlag = true;
|
|
58
58
|
const argvArr = process.argv;
|
|
59
59
|
const argvArrLen = argvArr.length;
|
|
60
|
-
let fileName =
|
|
60
|
+
let fileName = "";
|
|
61
61
|
if (argvArrLen > 2) {
|
|
62
62
|
fileName = argvArr[2];
|
|
63
63
|
}
|
|
64
64
|
else if (argvArrLen > 1) {
|
|
65
65
|
fileName = argvArr[1];
|
|
66
66
|
}
|
|
67
|
-
if (fileName !==
|
|
68
|
-
if (fileName.indexOf(
|
|
69
|
-
fileName = fileName.replace(/\\/g,
|
|
67
|
+
if (fileName !== "") {
|
|
68
|
+
if (fileName.indexOf("\\") !== -1) {
|
|
69
|
+
fileName = fileName.replace(/\\/g, "/");
|
|
70
70
|
}
|
|
71
|
-
const fileNameArr = fileName.split(
|
|
71
|
+
const fileNameArr = fileName.split("/");
|
|
72
72
|
const fileNameArrLen = fileNameArr.length;
|
|
73
73
|
const fileNameStr = fileNameArr[fileNameArrLen - 1];
|
|
74
|
-
if (fileNameStr ===
|
|
74
|
+
if (fileNameStr === "app") {
|
|
75
75
|
initFlag = false;
|
|
76
76
|
}
|
|
77
77
|
for (const item of fileNameArr) {
|
|
78
|
-
if (item ===
|
|
78
|
+
if (item === "pm2") {
|
|
79
79
|
initFlag = false;
|
|
80
80
|
break;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if (initFlag) {
|
|
85
|
-
const spinner = utils_1.Console.spinner(
|
|
85
|
+
const spinner = utils_1.Console.spinner("正在初始化项目...", "cyan");
|
|
86
86
|
spinner.start();
|
|
87
87
|
try {
|
|
88
88
|
await new Promise((resolve) => setTimeout(resolve, 1000)); // 模拟初始化时间
|
|
89
|
-
(0, generate_1.initFiles)(finalOptions.dictionary ||
|
|
89
|
+
(0, generate_1.initFiles)(finalOptions.dictionary || ".", false, projectConfig);
|
|
90
90
|
spinner.succeed(`项目初始化完成! 目录: ${finalOptions.dictionary}`);
|
|
91
91
|
utils_1.Console.newLine();
|
|
92
92
|
utils_1.Console.box(`项目已成功创建到 ${finalOptions.dictionary} 目录\n\n` +
|
|
@@ -95,15 +95,15 @@ exports.initCommand = {
|
|
|
95
95
|
`2. npm run dev\n\n` +
|
|
96
96
|
`默认登录账号: admin/admin123\n` +
|
|
97
97
|
`如需修改密码: npm run generate-password yourNewPassword\n` +
|
|
98
|
-
`然后修改 .env 中的 LOGIN_PASSWORD_HASH`,
|
|
98
|
+
`然后修改 .env 中的 LOGIN_PASSWORD_HASH`, "success");
|
|
99
99
|
}
|
|
100
100
|
catch (error) {
|
|
101
|
-
spinner.fail(
|
|
101
|
+
spinner.fail("项目初始化失败");
|
|
102
102
|
throw error;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
|
-
utils_1.Console.warning(
|
|
106
|
+
utils_1.Console.warning("跳过初始化(检测到特殊环境)");
|
|
107
107
|
}
|
|
108
108
|
process.exit(0);
|
|
109
109
|
}
|