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.
Files changed (99) hide show
  1. package/client/components/Button.tsx +3 -3
  2. package/client/components/ClientProviders.tsx +12 -12
  3. package/client/components/LanguageSwitcher.tsx +26 -26
  4. package/client/components/SSRSafeAntdProvider.tsx +7 -7
  5. package/client/components/SuppressHydrationWarnings.tsx +30 -30
  6. package/client/components/__tests__/Button.test.tsx +12 -12
  7. package/client/layout/index.tsx +124 -124
  8. package/client/redux/reducers.ts +2 -2
  9. package/client/redux/store.ts +24 -24
  10. package/client/redux/template/manage/actions.ts +40 -40
  11. package/client/redux/template/manage/reducers.ts +32 -32
  12. package/client/redux/template/manage/types.ts +19 -19
  13. package/client/service/template/manage.ts +29 -29
  14. package/client/styled/common.ts +6 -6
  15. package/client/styled/layout/index.ts +17 -17
  16. package/client/styled/template/manage.ts +19 -19
  17. package/client/utils/common.ts +54 -54
  18. package/client/utils/cookie.ts +30 -30
  19. package/client/utils/fetch.ts +111 -111
  20. package/client/utils/i18n.ts +41 -41
  21. package/client/utils/menu.tsx +12 -12
  22. package/client/utils/navigation.ts +22 -22
  23. package/client/utils/sso.ts +124 -124
  24. package/client/utils/suppressWarnings.ts +17 -17
  25. package/generation/prettierrc +6 -0
  26. package/lib/args.js +19 -19
  27. package/lib/cli/app.d.ts +1 -1
  28. package/lib/cli/app.js +2 -2
  29. package/lib/cli/commands/build.d.ts +1 -1
  30. package/lib/cli/commands/build.js +9 -9
  31. package/lib/cli/commands/create.d.ts +1 -1
  32. package/lib/cli/commands/create.js +36 -36
  33. package/lib/cli/commands/delete.d.ts +1 -1
  34. package/lib/cli/commands/delete.js +55 -55
  35. package/lib/cli/commands/export.d.ts +1 -1
  36. package/lib/cli/commands/export.js +12 -12
  37. package/lib/cli/commands/help.d.ts +1 -1
  38. package/lib/cli/commands/help.js +29 -29
  39. package/lib/cli/commands/init.d.ts +1 -1
  40. package/lib/cli/commands/init.js +31 -31
  41. package/lib/cli/commands/server.d.ts +1 -1
  42. package/lib/cli/commands/server.js +12 -12
  43. package/lib/cli/commands/upgrade.d.ts +1 -1
  44. package/lib/cli/commands/upgrade.js +13 -13
  45. package/lib/cli/commands/version.d.ts +1 -1
  46. package/lib/cli/commands/version.js +7 -7
  47. package/lib/cli/index.d.ts +13 -13
  48. package/lib/cli/parser.d.ts +1 -1
  49. package/lib/cli/parser.js +12 -12
  50. package/lib/cli/registry.d.ts +1 -1
  51. package/lib/cli/types.d.ts +2 -2
  52. package/lib/cli/utils/console.d.ts +2 -2
  53. package/lib/cli/utils/console.js +22 -22
  54. package/lib/cli/utils/index.d.ts +2 -2
  55. package/lib/cli/utils/prompt.d.ts +1 -1
  56. package/lib/cli/utils/prompt.js +98 -98
  57. package/lib/constants.js +28 -28
  58. package/lib/generate.d.ts +2 -2
  59. package/lib/generate.js +19 -19
  60. package/lib/generate_create.d.ts +1 -1
  61. package/lib/generate_create.js +38 -38
  62. package/lib/generate_delete.js +63 -63
  63. package/lib/generate_init.js +94 -94
  64. package/lib/generators/base-generator.d.ts +1 -1
  65. package/lib/generators/base-generator.js +23 -23
  66. package/lib/generators/file-generator.js +15 -15
  67. package/lib/generators/generator-factory.d.ts +5 -5
  68. package/lib/generators/i18n-generator.d.ts +1 -1
  69. package/lib/generators/i18n-generator.js +127 -127
  70. package/lib/generators/page-generator.d.ts +1 -1
  71. package/lib/generators/page-generator.js +25 -25
  72. package/lib/generators/resolver-generator.d.ts +1 -1
  73. package/lib/generators/resolver-generator.js +27 -27
  74. package/lib/generators/schema-generator.d.ts +1 -1
  75. package/lib/generators/schema-generator.js +4 -4
  76. package/lib/generators/service-generator.d.ts +1 -1
  77. package/lib/generators/service-generator.js +29 -29
  78. package/lib/generators/sql-generator.d.ts +1 -1
  79. package/lib/generators/sql-generator.js +10 -10
  80. package/lib/index.js +23 -23
  81. package/lib/server/csrf.d.ts +3 -3
  82. package/lib/server/csrf.js +20 -20
  83. package/lib/server/db.d.ts +1 -1
  84. package/lib/server/db.js +21 -21
  85. package/lib/server/graphql.js +26 -26
  86. package/lib/server/plugins/date.d.ts +1 -1
  87. package/lib/server/plugins/date.js +6 -6
  88. package/lib/server/utils/graphql-cache.js +5 -5
  89. package/lib/tsconfig.build.tsbuildinfo +1 -1
  90. package/lib/utils/project-config.d.ts +1 -1
  91. package/lib/utils/project-config.js +20 -20
  92. package/lib/utils.js +3 -3
  93. package/package.json +1 -1
  94. package/pages/_app.tsx +62 -62
  95. package/pages/_document.tsx +15 -15
  96. package/pages/_error.tsx +26 -26
  97. package/pages/index.tsx +48 -48
  98. package/pages/login.tsx +64 -64
  99. package/pages/template/manage.tsx +175 -175
package/lib/server/db.js CHANGED
@@ -17,7 +17,7 @@ const getMysqlConfig = () => {
17
17
  mysqlConfig = require(curMysqlConfigPath);
18
18
  }
19
19
  else {
20
- mysqlConfig = require('../../mysql.config.js');
20
+ mysqlConfig = require("../../mysql.config.js");
21
21
  }
22
22
  }
23
23
  return mysqlConfig;
@@ -41,21 +41,21 @@ const createPool = ({ user, password, host, port, database }) => {
41
41
  supportBigNumbers: true, // 支持大数字
42
42
  });
43
43
  // 监听连接池事件
44
- pool.on('connection', (connection) => {
45
- console.log('数据库连接池新建连接:', connection.threadId);
44
+ pool.on("connection", (connection) => {
45
+ console.log("数据库连接池新建连接:", connection.threadId);
46
46
  });
47
- pool.on('error', (error) => {
48
- console.error('数据库连接池错误:', error);
49
- if (error.code === 'PROTOCOL_CONNECTION_LOST') {
50
- console.log('数据库连接丢失,重新创建连接池');
47
+ pool.on("error", (error) => {
48
+ console.error("数据库连接池错误:", error);
49
+ if (error.code === "PROTOCOL_CONNECTION_LOST") {
50
+ console.log("数据库连接丢失,重新创建连接池");
51
51
  pool = null;
52
52
  createPool({ user, password, host, port, database });
53
53
  }
54
54
  });
55
- console.log('数据库连接池创建成功');
55
+ console.log("数据库连接池创建成功");
56
56
  }
57
57
  catch (error) {
58
- console.error('创建数据库连接池失败:', error);
58
+ console.error("创建数据库连接池失败:", error);
59
59
  throw error;
60
60
  }
61
61
  }
@@ -70,7 +70,7 @@ const getPool = () => {
70
70
  return createPool(mysqlOptions);
71
71
  }
72
72
  }
73
- throw new Error('无法获取数据库配置');
73
+ throw new Error("无法获取数据库配置");
74
74
  };
75
75
  // 执行查询(使用连接池)
76
76
  const executeQuery = (sql, values = []) => {
@@ -80,7 +80,7 @@ const executeQuery = (sql, values = []) => {
80
80
  // 使用 query 方法而不是 execute,更兼容各种SQL类型
81
81
  poolInstance.query(sql, values, (error, results) => {
82
82
  if (error) {
83
- console.error('SQL执行失败:', { sql, values, error: error.message });
83
+ console.error("SQL执行失败:", { sql, values, error: error.message });
84
84
  reject(new Error(`SQL执行失败: ${error.message}`));
85
85
  return;
86
86
  }
@@ -88,7 +88,7 @@ const executeQuery = (sql, values = []) => {
88
88
  });
89
89
  }
90
90
  catch (error) {
91
- console.error('获取数据库连接失败:', error);
91
+ console.error("获取数据库连接失败:", error);
92
92
  const errorMessage = error instanceof Error ? error.message : String(error);
93
93
  reject(new Error(`数据库连接失败: ${errorMessage}`));
94
94
  }
@@ -114,11 +114,11 @@ const closePool = () => {
114
114
  if (pool) {
115
115
  pool.end((error) => {
116
116
  if (error) {
117
- console.error('关闭数据库连接池失败:', error);
117
+ console.error("关闭数据库连接池失败:", error);
118
118
  reject(error);
119
119
  }
120
120
  else {
121
- console.log('数据库连接池已关闭');
121
+ console.log("数据库连接池已关闭");
122
122
  pool = null;
123
123
  resolve();
124
124
  }
@@ -132,7 +132,7 @@ const closePool = () => {
132
132
  // 兼容旧的 getConnection 方法(已废弃,建议使用新的方法)
133
133
  const mysqlConnect = ({ user, password, host, port, database }) => {
134
134
  return new Promise((resolve, reject) => {
135
- if (user !== '' && password !== '' && host !== '' && port !== 0 && database !== '') {
135
+ if (user !== "" && password !== "" && host !== "" && port !== 0 && database !== "") {
136
136
  try {
137
137
  const connection = mysql2_1.default.createConnection({ user, password, host, port, database });
138
138
  connection.connect((err) => {
@@ -140,13 +140,13 @@ const mysqlConnect = ({ user, password, host, port, database }) => {
140
140
  resolve(connection);
141
141
  }
142
142
  else {
143
- console.error('err_mysqlConnect: ', err);
143
+ console.error("err_mysqlConnect: ", err);
144
144
  reject();
145
145
  }
146
146
  });
147
147
  }
148
148
  catch (e) {
149
- console.error('e_mysqlConnect: ', e);
149
+ console.error("e_mysqlConnect: ", e);
150
150
  reject();
151
151
  }
152
152
  }
@@ -166,20 +166,20 @@ const getConnection = () => {
166
166
  mysqlConnect(mysqlOptions)
167
167
  .then(resolve)
168
168
  .catch((err) => {
169
- console.error('e_getConnection', err);
169
+ console.error("e_getConnection", err);
170
170
  reject(err);
171
171
  });
172
172
  }
173
173
  else {
174
- reject(new Error('localMysqlFlag is false'));
174
+ reject(new Error("localMysqlFlag is false"));
175
175
  }
176
176
  }
177
177
  else {
178
- reject(new Error('mysqlOptions is missing'));
178
+ reject(new Error("mysqlOptions is missing"));
179
179
  }
180
180
  });
181
181
  }
182
- return Promise.reject(new Error('mysqlConfig is missing'));
182
+ return Promise.reject(new Error("mysqlConfig is missing"));
183
183
  };
184
184
  exports.default = {
185
185
  getMysqlConfig,
@@ -12,9 +12,9 @@ const date_1 = __importDefault(require("./plugins/date"));
12
12
  // 缓存已生成的 schema 和 resolvers
13
13
  let cachedSchema = null;
14
14
  let cachedResolvers = null;
15
- const defaultPath = (0, path_1.resolve)(__dirname, './modules/');
16
- const typeDefFileName = 'schema.js';
17
- const resolverFileName = 'resolver.js';
15
+ const defaultPath = (0, path_1.resolve)(__dirname, "./modules/");
16
+ const typeDefFileName = "schema.js";
17
+ const resolverFileName = "resolver.js";
18
18
  const curFolder = process.cwd();
19
19
  const outModulesPath = (0, path_1.resolve)(`${curFolder}/server/modules/`);
20
20
  const handleOutPlugins = () => {
@@ -31,7 +31,7 @@ const handleOutPlugins = () => {
31
31
  return;
32
32
  const stat = fs_1.default.statSync(resolverPath);
33
33
  const isFile = stat.isFile();
34
- if (isFile && (item.endsWith('.js') || item.endsWith('.ts'))) {
34
+ if (isFile && (item.endsWith(".js") || item.endsWith(".ts"))) {
35
35
  const pluginModule = require(resolverPath);
36
36
  result = {
37
37
  ...result,
@@ -41,28 +41,28 @@ const handleOutPlugins = () => {
41
41
  });
42
42
  }
43
43
  catch (error) {
44
- console.warn('⚠️ Error loading plugins:', error);
44
+ console.warn("⚠️ Error loading plugins:", error);
45
45
  }
46
46
  return result;
47
47
  };
48
48
  function generateTypeDefsAndResolvers() {
49
49
  // 如果已有缓存且在生产环境,直接返回缓存
50
- if (process.env.NODE_ENV === 'production' && cachedSchema && cachedResolvers) {
50
+ if (process.env.NODE_ENV === "production" && cachedSchema && cachedResolvers) {
51
51
  return {
52
52
  schemaStr: cachedSchema,
53
53
  resolvers: cachedResolvers,
54
54
  };
55
55
  }
56
- const querySchemes = ['_: Boolean'];
57
- const mutationSchemes = ['_: Boolean'];
58
- const subscriptionSchemes = ['_: Boolean'];
56
+ const querySchemes = ["_: Boolean"];
57
+ const mutationSchemes = ["_: Boolean"];
58
+ const subscriptionSchemes = ["_: Boolean"];
59
59
  const typeSchemes = [];
60
60
  const resolvers = {
61
61
  ...date_1.default,
62
62
  ...handleOutPlugins(),
63
63
  };
64
64
  const scalars = lodash_1.default.keys(resolvers);
65
- let scalarStr = '';
65
+ let scalarStr = "";
66
66
  lodash_1.default.each(scalars, (item) => {
67
67
  scalarStr += `scalar ${item}\n `;
68
68
  });
@@ -87,13 +87,13 @@ function generateTypeDefsAndResolvers() {
87
87
  if (schemaObj.default !== undefined)
88
88
  schemaObj = schemaObj.default;
89
89
  const { query, mutation, subscription, type } = schemaObj;
90
- if (query && query !== '')
90
+ if (query && query !== "")
91
91
  querySchemes.push(query);
92
- if (mutation && mutation !== '')
92
+ if (mutation && mutation !== "")
93
93
  mutationSchemes.push(mutation);
94
- if (subscription && subscription !== '')
94
+ if (subscription && subscription !== "")
95
95
  subscriptionSchemes.push(subscription);
96
- if (type && type !== '')
96
+ if (type && type !== "")
97
97
  typeSchemes.push(type);
98
98
  }
99
99
  catch (error) {
@@ -127,21 +127,21 @@ function generateTypeDefsAndResolvers() {
127
127
  ${scalarStr}
128
128
 
129
129
  type Query {
130
- ${querySchemes.join('\n')}
130
+ ${querySchemes.join("\n")}
131
131
  }
132
132
 
133
133
  type Mutation {
134
- ${mutationSchemes.join('\n')}
134
+ ${mutationSchemes.join("\n")}
135
135
  }
136
136
 
137
137
  type Subscription {
138
- ${subscriptionSchemes.join('\n')}
138
+ ${subscriptionSchemes.join("\n")}
139
139
  }
140
140
 
141
- ${typeSchemes.join('\n')}
141
+ ${typeSchemes.join("\n")}
142
142
  `;
143
143
  // 在生产环境中缓存结果
144
- if (process.env.NODE_ENV === 'production') {
144
+ if (process.env.NODE_ENV === "production") {
145
145
  cachedSchema = schemaStr;
146
146
  cachedResolvers = resolvers;
147
147
  }
@@ -156,22 +156,22 @@ const handler = (command) => {
156
156
  ${scalarStrV}
157
157
 
158
158
  type Query {
159
- ${querySchemesV?.join('\n') || '_: Boolean'}
159
+ ${querySchemesV?.join("\n") || "_: Boolean"}
160
160
  }
161
161
 
162
162
  type Mutation {
163
- ${mutationSchemesV?.join('\n') || '_: Boolean'}
163
+ ${mutationSchemesV?.join("\n") || "_: Boolean"}
164
164
  }
165
165
 
166
166
  type Subscription {
167
- ${subscriptionSchemesV?.join('\n') || '_: Boolean'}
167
+ ${subscriptionSchemesV?.join("\n") || "_: Boolean"}
168
168
  }
169
169
 
170
- ${typeSchemesV?.join('\n') || ''}
170
+ ${typeSchemesV?.join("\n") || ""}
171
171
  `;
172
- if (command === 'dev') {
173
- console.log('schemaStr', schemaStr);
174
- console.log('resolvers', resolversV);
172
+ if (command === "dev") {
173
+ console.log("schemaStr", schemaStr);
174
+ console.log("resolvers", resolversV);
175
175
  }
176
176
  // graphql-http 不再内置 graphiql,需手动集成 playground 或 altair,以下为基础 handler
177
177
  return (0, express_1.createHandler)({
@@ -1,4 +1,4 @@
1
- import { GraphQLScalarType } from 'graphql';
1
+ import { GraphQLScalarType } from "graphql";
2
2
  declare const _default: {
3
3
  Date: GraphQLScalarType<number | null, string>;
4
4
  };
@@ -7,21 +7,21 @@ const dayjs_1 = __importDefault(require("dayjs"));
7
7
  const language_1 = require("graphql/language");
8
8
  const graphql_1 = require("graphql");
9
9
  const customScalarDate = new graphql_1.GraphQLScalarType({
10
- name: 'Date',
11
- description: 'Date custom scalar type',
10
+ name: "Date",
11
+ description: "Date custom scalar type",
12
12
  parseValue: (value) => {
13
13
  const date = (0, dayjs_1.default)(value);
14
14
  if (!date.isValid()) {
15
- throw new Error('Invalid date format');
15
+ throw new Error("Invalid date format");
16
16
  }
17
17
  return date.valueOf(); // Ensure this returns a number
18
18
  },
19
19
  serialize: (value) => {
20
20
  const date = (0, dayjs_1.default)(value);
21
21
  if (!date.isValid()) {
22
- throw new Error('Invalid date format');
22
+ throw new Error("Invalid date format");
23
23
  }
24
- return date.format('YYYY-MM-DD HH:mm:ss:SSS'); // Ensure this returns a string
24
+ return date.format("YYYY-MM-DD HH:mm:ss:SSS"); // Ensure this returns a string
25
25
  },
26
26
  parseLiteral: (ast) => {
27
27
  if (ast.kind === language_1.Kind.INT) {
@@ -30,7 +30,7 @@ const customScalarDate = new graphql_1.GraphQLScalarType({
30
30
  else if (ast.kind === language_1.Kind.STRING) {
31
31
  const date = (0, dayjs_1.default)(ast.value);
32
32
  if (!date.isValid()) {
33
- throw new Error('Invalid date format');
33
+ throw new Error("Invalid date format");
34
34
  }
35
35
  return date.valueOf();
36
36
  }
@@ -7,7 +7,7 @@ const CACHE_TTL = 5 * 60 * 1000; // 5分钟
7
7
  const graphqlCacheMiddleware = (req, res, next) => {
8
8
  const { query, variables } = req.body || {};
9
9
  // 只缓存查询操作,不缓存变更操作
10
- if (!query || query.trim().startsWith('mutation')) {
10
+ if (!query || query.trim().startsWith("mutation")) {
11
11
  return next();
12
12
  }
13
13
  const cacheKey = JSON.stringify({ query, variables });
@@ -15,14 +15,14 @@ const graphqlCacheMiddleware = (req, res, next) => {
15
15
  // 检查缓存
16
16
  const cached = queryCache.get(cacheKey);
17
17
  if (cached && now - cached.timestamp < CACHE_TTL) {
18
- console.log('🚀 GraphQL cache hit for:', `${query.substring(0, 50)}...`);
18
+ console.log("🚀 GraphQL cache hit for:", `${query.substring(0, 50)}...`);
19
19
  return res.json(cached.data);
20
20
  }
21
21
  // 拦截响应以存储缓存
22
22
  const originalSend = res.send;
23
23
  res.send = function (body) {
24
24
  try {
25
- const data = typeof body === 'string' ? JSON.parse(body) : body;
25
+ const data = typeof body === "string" ? JSON.parse(body) : body;
26
26
  // 只缓存成功的查询结果
27
27
  if (!data.errors) {
28
28
  queryCache.set(cacheKey, {
@@ -34,7 +34,7 @@ const graphqlCacheMiddleware = (req, res, next) => {
34
34
  }
35
35
  }
36
36
  catch (error) {
37
- console.warn('⚠️ GraphQL cache error:', error);
37
+ console.warn("⚠️ GraphQL cache error:", error);
38
38
  }
39
39
  originalSend.call(this, body);
40
40
  };
@@ -53,7 +53,7 @@ function cleanExpiredCache() {
53
53
  // 清空缓存的函数
54
54
  const clearGraphQLCache = () => {
55
55
  queryCache.clear();
56
- console.log('🧹 GraphQL cache cleared');
56
+ console.log("🧹 GraphQL cache cleared");
57
57
  };
58
58
  exports.clearGraphQLCache = clearGraphQLCache;
59
59
  // 获取缓存统计