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
@@ -1,4 +1,4 @@
1
- import { ProjectConfig } from '../cli/types/project';
1
+ import { ProjectConfig } from "../cli/types/project";
2
2
  /**
3
3
  * 应用项目配置到生成的文件中
4
4
  */
@@ -52,17 +52,17 @@ function applyProjectConfig(projectPath, config) {
52
52
  */
53
53
  function ensureDefaultFeatures(config) {
54
54
  console.log(`✅ 项目已配置默认功能栈: Next.js + Styled Components + GraphQL + MySQL + TypeScript + ESLint`);
55
- console.log(`✅ 数据库配置: ${config.database ? '已启用' : '未启用'}`);
56
- console.log(`✅ 包含功能: ${config.features.join(', ')}`);
55
+ console.log(`✅ 数据库配置: ${config.database ? "已启用" : "未启用"}`);
56
+ console.log(`✅ 包含功能: ${config.features.join(", ")}`);
57
57
  }
58
58
  /**
59
59
  * 更新 package.json 文件
60
60
  */
61
61
  function updatePackageJson(projectPath, config) {
62
- const packageJsonPath = path.join(projectPath, 'package.json');
62
+ const packageJsonPath = path.join(projectPath, "package.json");
63
63
  if (fs.existsSync(packageJsonPath)) {
64
64
  try {
65
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
65
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
66
66
  // 更新基本信息
67
67
  packageJson.name = config.projectName;
68
68
  packageJson.description = config.description;
@@ -90,49 +90,49 @@ function updatePackageJson(projectPath, config) {
90
90
  * 更新 README.md 文件
91
91
  */
92
92
  function updateReadme(projectPath, config) {
93
- const readmePath = path.join(projectPath, 'README.md');
93
+ const readmePath = path.join(projectPath, "README.md");
94
94
  if (fs.existsSync(readmePath)) {
95
95
  try {
96
- let readmeContent = fs.readFileSync(readmePath, 'utf8');
96
+ let readmeContent = fs.readFileSync(readmePath, "utf8");
97
97
  // 替换项目名称
98
98
  readmeContent = readmeContent.replace(/nsgm-cli-project/g, config.projectName);
99
99
  // 如果有描述,添加到 README 开头
100
- if (config.description && config.description !== 'A NSGM fullstack project') {
100
+ if (config.description && config.description !== "A NSGM fullstack project") {
101
101
  const descriptionSection = `# ${config.projectName}\n\n${config.description}\n\n`;
102
102
  // 检查是否已经有项目名称标题
103
- if (readmeContent.startsWith('# ')) {
103
+ if (readmeContent.startsWith("# ")) {
104
104
  // 替换第一行
105
- const lines = readmeContent.split('\n');
105
+ const lines = readmeContent.split("\n");
106
106
  lines[0] = `# ${config.projectName}`;
107
- if (lines[1] === '' && lines[2] && !lines[2].startsWith('#')) {
107
+ if (lines[1] === "" && lines[2] && !lines[2].startsWith("#")) {
108
108
  lines[2] = config.description;
109
109
  }
110
110
  else {
111
- lines.splice(2, 0, '', config.description);
111
+ lines.splice(2, 0, "", config.description);
112
112
  }
113
- readmeContent = lines.join('\n');
113
+ readmeContent = lines.join("\n");
114
114
  }
115
115
  else {
116
116
  readmeContent = descriptionSection + readmeContent;
117
117
  }
118
118
  }
119
119
  // 添加作者信息
120
- if (config.author && config.author !== 'Your Name') {
120
+ if (config.author && config.author !== "Your Name") {
121
121
  const authorSection = `\n## 作者\n\n${config.author}\n`;
122
122
  readmeContent += authorSection;
123
123
  }
124
124
  // 添加功能说明
125
125
  if (config.features.length > 0) {
126
126
  const featureMap = {
127
- nextjs: 'Next.js 全栈框架',
128
- styled: 'Styled Components CSS-in-JS',
129
- graphql: 'GraphQL API',
130
- mysql: 'MySQL 数据库',
131
- typescript: 'TypeScript 强类型支持',
132
- eslint: 'ESLint 代码质量检查',
127
+ nextjs: "Next.js 全栈框架",
128
+ styled: "Styled Components CSS-in-JS",
129
+ graphql: "GraphQL API",
130
+ mysql: "MySQL 数据库",
131
+ typescript: "TypeScript 强类型支持",
132
+ eslint: "ESLint 代码质量检查",
133
133
  };
134
134
  const featureNames = config.features.map((feature) => featureMap[feature] || feature);
135
- const featuresSection = `\n## 技术栈\n\n${featureNames.map((feature) => `- ${feature}`).join('\n')}\n`;
135
+ const featuresSection = `\n## 技术栈\n\n${featureNames.map((feature) => `- ${feature}`).join("\n")}\n`;
136
136
  readmeContent += featuresSection;
137
137
  }
138
138
  fs.writeFileSync(readmePath, readmeContent);
package/lib/utils.js CHANGED
@@ -84,18 +84,18 @@ const handleReplace = ({ regex, replacement, paths }) => {
84
84
  exports.handleReplace = handleReplace;
85
85
  const replaceInFileAll = async (array, index = 0, callback) => {
86
86
  if (replaceInFileFlag) {
87
- console.log('replaceInFileAll', index);
87
+ console.log("replaceInFileAll", index);
88
88
  const arrayLen = array.length;
89
89
  if (index < arrayLen) {
90
90
  const item = array[index];
91
91
  (0, replace_in_file_1.replaceInFile)(item)
92
92
  .then((changedFiles) => {
93
- console.log('Modified files:', changedFiles);
93
+ console.log("Modified files:", changedFiles);
94
94
  (0, exports.replaceInFileAll)(array, ++index, callback);
95
95
  })
96
96
  .catch((error) => {
97
97
  if (error) {
98
- console.error('Error occurred:', error);
98
+ console.error("Error occurred:", error);
99
99
  }
100
100
  });
101
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsgm-cli",
3
- "version": "2.1.19",
3
+ "version": "2.1.21",
4
4
  "description": "A CLI tool to run Next/Style-components and Graphql/Mysql fullstack project",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/pages/_app.tsx CHANGED
@@ -1,104 +1,104 @@
1
1
  // 必须在所有其他导入之前执行
2
- import '@/utils/suppressWarnings'
3
-
4
- import React, { useEffect, useState } from 'react'
5
- import { Provider } from 'react-redux'
6
- import { Spin } from 'antd'
7
- import { appWithTranslation } from 'next-i18next'
8
- import { useRouter } from 'next/router'
9
- import { useStore } from '@/redux/store'
10
- import { Loading } from '@/styled/common'
11
- import LayoutComponent from '@/layout'
12
- import ClientProviders from '@/components/ClientProviders'
13
- import SuppressHydrationWarnings from '@/components/SuppressHydrationWarnings'
14
- import SSRSafeAntdProvider from '@/components/SSRSafeAntdProvider'
15
- import { login } from '@/utils/sso'
16
- import { getAntdLocale } from '@/utils/i18n'
17
- import { navigateToLogin } from '@/utils/navigation'
18
- import nextI18NextConfig from '../next-i18next.config.js'
19
- import 'antd/dist/reset.css'
2
+ import "@/utils/suppressWarnings";
3
+
4
+ import React, { useEffect, useState } from "react";
5
+ import { Provider } from "react-redux";
6
+ import { Spin } from "antd";
7
+ import { appWithTranslation } from "next-i18next";
8
+ import { useRouter } from "next/router";
9
+ import { useStore } from "@/redux/store";
10
+ import { Loading } from "@/styled/common";
11
+ import LayoutComponent from "@/layout";
12
+ import ClientProviders from "@/components/ClientProviders";
13
+ import SuppressHydrationWarnings from "@/components/SuppressHydrationWarnings";
14
+ import SSRSafeAntdProvider from "@/components/SSRSafeAntdProvider";
15
+ import { login } from "@/utils/sso";
16
+ import { getAntdLocale } from "@/utils/i18n";
17
+ import { navigateToLogin } from "@/utils/navigation";
18
+ import nextI18NextConfig from "../next-i18next.config.js";
19
+ import "antd/dist/reset.css";
20
20
 
21
21
  const theme = {
22
22
  colors: {
23
- primary: '#0070f3',
23
+ primary: "#0070f3",
24
24
  },
25
- }
25
+ };
26
26
 
27
27
  const App = ({ Component, pageProps }) => {
28
- const store = useStore(pageProps.initialReduxState)
29
- const router = useRouter()
30
- const [ssoUser, setSsoUser] = useState(null)
31
- const [pageLoad, setPageLoad] = useState(false)
32
- const [loginChecked, setLoginChecked] = useState(false)
33
- const [mounted, setMounted] = useState(false)
34
- const [currentLocale, setCurrentLocale] = useState('zh-CN')
28
+ const store = useStore(pageProps.initialReduxState);
29
+ const router = useRouter();
30
+ const [ssoUser, setSsoUser] = useState(null);
31
+ const [pageLoad, setPageLoad] = useState(false);
32
+ const [loginChecked, setLoginChecked] = useState(false);
33
+ const [mounted, setMounted] = useState(false);
34
+ const [currentLocale, setCurrentLocale] = useState("zh-CN");
35
35
 
36
36
  // 检查是否为特殊页面(登录页、错误页)
37
37
  // 避免在服务器端访问 router.pathname
38
38
  const isSpecialPage =
39
- Component.displayName === 'ErrorPage' ||
40
- Component.name === 'ErrorPage' ||
41
- Component.displayName === 'LoginPage' ||
42
- Component.name === 'LoginPage'
39
+ Component.displayName === "ErrorPage" ||
40
+ Component.name === "ErrorPage" ||
41
+ Component.displayName === "LoginPage" ||
42
+ Component.name === "LoginPage";
43
43
 
44
44
  // Get Antd locale based on current locale
45
- const antdLocale = getAntdLocale(currentLocale)
45
+ const antdLocale = getAntdLocale(currentLocale);
46
46
 
47
47
  useEffect(() => {
48
- setMounted(true)
48
+ setMounted(true);
49
49
  // 只在客户端设置当前语言
50
- if (typeof window !== 'undefined') {
51
- const locale = router.locale || 'zh-CN'
52
- setCurrentLocale(locale)
50
+ if (typeof window !== "undefined") {
51
+ const locale = router.locale || "zh-CN";
52
+ setCurrentLocale(locale);
53
53
  }
54
- }, [router.locale])
54
+ }, [router.locale]);
55
55
 
56
56
  useEffect(() => {
57
- if (!mounted) return
57
+ if (!mounted) return;
58
58
 
59
59
  // 对于特殊页面,跳过登录检查
60
60
  if (isSpecialPage) {
61
- setLoginChecked(true)
62
- setPageLoad(true)
63
- return
61
+ setLoginChecked(true);
62
+ setPageLoad(true);
63
+ return;
64
64
  }
65
65
 
66
66
  // 检查当前路径是否为登录页或错误页
67
- const isLoginPage = typeof window !== 'undefined' && window.location.pathname === '/login'
67
+ const isLoginPage = typeof window !== "undefined" && window.location.pathname === "/login";
68
68
  const isErrorPage =
69
- typeof window !== 'undefined' &&
70
- (window.location.pathname === '/404' ||
71
- window.location.pathname === '/500' ||
72
- window.location.pathname === '/_error')
69
+ typeof window !== "undefined" &&
70
+ (window.location.pathname === "/404" ||
71
+ window.location.pathname === "/500" ||
72
+ window.location.pathname === "/_error");
73
73
 
74
74
  // 如果是登录页或错误页,直接设置加载完成,不进行登录检查
75
75
  if (isLoginPage || isErrorPage) {
76
- setLoginChecked(true)
77
- setPageLoad(true)
78
- return
76
+ setLoginChecked(true);
77
+ setPageLoad(true);
78
+ return;
79
79
  }
80
80
 
81
81
  // 检查是否有登录凭证
82
- const hasLoginCookie = typeof window !== 'undefined' && document.cookie.includes('_cas_nsgm')
82
+ const hasLoginCookie = typeof window !== "undefined" && document.cookie.includes("_cas_nsgm");
83
83
 
84
84
  // 如果没有登录凭证,直接跳转到登录页面(保持当前语言)
85
- if (!hasLoginCookie && typeof window !== 'undefined') {
86
- navigateToLogin(router)
87
- return
85
+ if (!hasLoginCookie && typeof window !== "undefined") {
86
+ navigateToLogin(router);
87
+ return;
88
88
  }
89
89
 
90
90
  // 否则执行登录检查
91
91
  login((user: any) => {
92
92
  if (user) {
93
- setSsoUser(user)
93
+ setSsoUser(user);
94
94
  }
95
- setLoginChecked(true)
96
- })
95
+ setLoginChecked(true);
96
+ });
97
97
 
98
98
  setTimeout(() => {
99
- setPageLoad(true)
100
- }, 100)
101
- }, [mounted, isSpecialPage])
99
+ setPageLoad(true);
100
+ }, 100);
101
+ }, [mounted, isSpecialPage]);
102
102
 
103
103
  return (
104
104
  <>
@@ -130,10 +130,10 @@ const App = ({ Component, pageProps }) => {
130
130
  </ClientProviders>
131
131
  </SSRSafeAntdProvider>
132
132
  </>
133
- )
134
- }
133
+ );
134
+ };
135
135
 
136
136
  // 移除 getInitialProps 以启用静态优化
137
137
  // 如果需要页面级别的数据获取,请在各个页面中使用 getStaticProps 或 getServerSideProps
138
138
 
139
- export default appWithTranslation(App, nextI18NextConfig)
139
+ export default appWithTranslation(App, nextI18NextConfig);
@@ -1,10 +1,10 @@
1
- import Document, { Html, Head, Main, NextScript, DocumentContext } from 'next/document'
2
- import React from 'react'
3
- import { ServerStyleSheet } from 'styled-components'
1
+ import Document, { Html, Head, Main, NextScript, DocumentContext } from "next/document";
2
+ import React from "react";
3
+ import { ServerStyleSheet } from "styled-components";
4
4
 
5
5
  const MyDocument = (props) => {
6
6
  // 从 props 中获取语言信息,如果没有则默认为 zh-CN
7
- const locale = props.locale || 'zh-CN'
7
+ const locale = props.locale || "zh-CN";
8
8
 
9
9
  return (
10
10
  <Html lang={locale}>
@@ -86,31 +86,31 @@ const MyDocument = (props) => {
86
86
  <NextScript />
87
87
  </body>
88
88
  </Html>
89
- )
90
- }
89
+ );
90
+ };
91
91
 
92
92
  // MyDocument.renderDocument = Document.renderDocument
93
93
 
94
94
  MyDocument.getInitialProps = async (ctx: DocumentContext) => {
95
- const sheet = new ServerStyleSheet()
96
- const originalRenderPage = ctx.renderPage
95
+ const sheet = new ServerStyleSheet();
96
+ const originalRenderPage = ctx.renderPage;
97
97
 
98
98
  try {
99
99
  ctx.renderPage = () =>
100
100
  originalRenderPage({
101
101
  enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),
102
- })
102
+ });
103
103
 
104
- const initialProps = await Document?.getInitialProps(ctx)
104
+ const initialProps = await Document?.getInitialProps(ctx);
105
105
 
106
106
  return {
107
107
  ...initialProps,
108
- locale: ctx.locale || 'zh-CN',
108
+ locale: ctx.locale || "zh-CN",
109
109
  styles: [initialProps.styles, sheet.getStyleElement()],
110
- }
110
+ };
111
111
  } finally {
112
- sheet.seal()
112
+ sheet.seal();
113
113
  }
114
- }
114
+ };
115
115
 
116
- export default MyDocument
116
+ export default MyDocument;
package/pages/_error.tsx CHANGED
@@ -1,50 +1,50 @@
1
- import React from 'react'
2
- import { Result, Button } from 'antd'
3
- import { NextPageContext } from 'next'
1
+ import React from "react";
2
+ import { Result, Button } from "antd";
3
+ import { NextPageContext } from "next";
4
4
 
5
5
  interface ErrorProps {
6
- statusCode?: number
6
+ statusCode?: number;
7
7
  }
8
8
 
9
9
  function ErrorPage({ statusCode }: ErrorProps) {
10
10
  const getErrorMessage = () => {
11
11
  if (statusCode === 404) {
12
- return '页面未找到'
12
+ return "页面未找到";
13
13
  } else if (statusCode === 500) {
14
- return '服务器错误'
14
+ return "服务器错误";
15
15
  }
16
- return '发生了未知错误'
17
- }
16
+ return "发生了未知错误";
17
+ };
18
18
 
19
19
  const getErrorTitle = () => {
20
20
  if (statusCode === 404) {
21
- return '404'
21
+ return "404";
22
22
  } else if (statusCode === 500) {
23
- return '500'
23
+ return "500";
24
24
  }
25
- return '错误'
26
- }
25
+ return "错误";
26
+ };
27
27
 
28
28
  return (
29
29
  <div
30
30
  style={{
31
- minHeight: '100vh',
32
- display: 'flex',
33
- alignItems: 'center',
34
- justifyContent: 'center',
35
- padding: '20px',
31
+ minHeight: "100vh",
32
+ display: "flex",
33
+ alignItems: "center",
34
+ justifyContent: "center",
35
+ padding: "20px",
36
36
  }}
37
37
  >
38
38
  <Result
39
- status={statusCode === 404 ? '404' : '500'}
39
+ status={statusCode === 404 ? "404" : "500"}
40
40
  title={getErrorTitle()}
41
41
  subTitle={getErrorMessage()}
42
42
  extra={
43
43
  <Button
44
44
  type="primary"
45
45
  onClick={() => {
46
- if (typeof window !== 'undefined') {
47
- window.location.href = '/'
46
+ if (typeof window !== "undefined") {
47
+ window.location.href = "/";
48
48
  }
49
49
  }}
50
50
  >
@@ -53,14 +53,14 @@ function ErrorPage({ statusCode }: ErrorProps) {
53
53
  }
54
54
  />
55
55
  </div>
56
- )
56
+ );
57
57
  }
58
58
 
59
59
  ErrorPage.getInitialProps = ({ res, err }: NextPageContext) => {
60
- const statusCode = res ? res.statusCode : err ? err.statusCode : 404
61
- return { statusCode }
62
- }
60
+ const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
61
+ return { statusCode };
62
+ };
63
63
 
64
- ErrorPage.displayName = 'ErrorPage'
64
+ ErrorPage.displayName = "ErrorPage";
65
65
 
66
- export default ErrorPage
66
+ export default ErrorPage;