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
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from 'react'
2
- import { Layout, Menu, Breadcrumb, Image, Select, Dropdown, Space, Tooltip } from 'antd'
2
+ import { Layout, Menu, Breadcrumb, Image, Dropdown, Space, Tooltip } from 'antd'
3
3
  import { Container } from '@/styled/layout'
4
4
  import styled from 'styled-components'
5
5
  import { useRouter } from 'next/router'
@@ -9,8 +9,20 @@ import { logout } from '@/utils/sso'
9
9
  import getConfig from 'next/config'
10
10
  import { LogoutOutlined, SettingOutlined, BellOutlined, UserOutlined } from '@ant-design/icons'
11
11
 
12
- const { Option } = Select
13
- const { SubMenu } = Menu
12
+ interface SubMenuItem {
13
+ key: string
14
+ text: string
15
+ url: string
16
+ }
17
+
18
+ interface MenuItem {
19
+ key: string
20
+ text: string
21
+ url: string
22
+ icon?: React.ReactNode
23
+ subMenus?: SubMenuItem[]
24
+ }
25
+
14
26
  const { Header, Content, Sider } = Layout
15
27
 
16
28
  const nextConfig = getConfig()
@@ -19,92 +31,92 @@ const { prefix } = publicRuntimeConfig
19
31
 
20
32
  // styled-components
21
33
  const FlexLayout = styled(Layout)`
22
- display: flex;
23
- flex: 1;
24
- `
34
+ display: flex;
35
+ flex: 1;
36
+ `
25
37
  const StyledSider = styled(Sider)`
26
- display: flex;
27
- flex-direction: column;
28
- box-shadow: 2px 0 8px -4px rgba(0, 0, 0, 0.1);
29
- z-index: 5;
30
- position: relative;
31
- `
38
+ display: flex;
39
+ flex-direction: column;
40
+ box-shadow: 2px 0 8px -4px rgba(0, 0, 0, 0.1);
41
+ z-index: 5;
42
+ position: relative;
43
+ `
32
44
 
33
45
  const SideMenu = styled(Menu)`
34
- height: 100%;
35
- border-right: 0;
36
- padding: 8px 0;
37
- `
46
+ height: 100%;
47
+ border-right: 0;
48
+ padding: 8px 0;
49
+ `
38
50
 
39
51
  const ContentLayout = styled(Layout)`
40
- display: flex;
41
- flex-direction: column;
42
- flex: 1;
43
- background: #f5f7fa;
44
- position: relative;
45
- z-index: 1;
46
- `
52
+ display: flex;
53
+ flex-direction: column;
54
+ flex: 1;
55
+ background: #f5f7fa;
56
+ position: relative;
57
+ z-index: 1;
58
+ `
47
59
  const StyledHeader = styled(Header)`
60
+ display: flex;
61
+ align-items: center;
62
+ padding: 0 24px;
63
+ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
64
+ z-index: 11;
65
+
66
+ .logo {
67
+ margin-right: 24px;
68
+ }
69
+
70
+ .main-menu {
71
+ flex: 1;
72
+ }
73
+
74
+ .user-actions {
48
75
  display: flex;
49
76
  align-items: center;
50
- padding: 0 24px;
51
- box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
52
- z-index: 11;
53
-
54
- .logo {
55
- margin-right: 24px;
56
- }
57
-
58
- .main-menu {
59
- flex: 1;
77
+
78
+ .action-icon {
79
+ font-size: 18px;
80
+ color: rgba(255, 255, 255, 0.85);
81
+ cursor: pointer;
82
+ padding: 0 8px;
83
+ transition: color 0.3s;
84
+
85
+ &:hover {
86
+ color: #fff;
87
+ }
60
88
  }
61
-
62
- .user-actions {
63
- display: flex;
64
- align-items: center;
65
-
66
- .action-icon {
67
- font-size: 18px;
89
+
90
+ .user-dropdown {
91
+ cursor: pointer;
92
+ padding: 0 8px;
93
+
94
+ .username {
68
95
  color: rgba(255, 255, 255, 0.85);
69
- cursor: pointer;
70
- padding: 0 8px;
71
- transition: color 0.3s;
72
-
73
- &:hover {
74
- color: #fff;
75
- }
76
- }
77
-
78
- .user-dropdown {
79
- cursor: pointer;
80
- padding: 0 8px;
81
-
82
- .username {
83
- color: rgba(255, 255, 255, 0.85);
84
- margin-left: 8px;
85
- }
96
+ margin-left: 8px;
86
97
  }
87
98
  }
88
- `
99
+ }
100
+ `
89
101
  const StyledBreadcrumb = styled(Breadcrumb)`
90
- margin: 16px 24px;
91
- font-size: 14px;
92
- `
102
+ margin: 16px 24px;
103
+ font-size: 14px;
104
+ `
93
105
  const StyledContent = styled(Content)`
94
- margin: 0 24px 24px;
95
- padding: 24px;
96
- background: #fff;
97
- border-radius: 4px;
98
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
99
- min-height: calc(100vh - 180px);
100
- position: relative;
101
- z-index: 1;
102
- `
106
+ margin: 0 24px 24px;
107
+ padding: 24px;
108
+ background: #fff;
109
+ border-radius: 4px;
110
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
111
+ min-height: calc(100vh - 180px);
112
+ position: relative;
113
+ z-index: 1;
114
+ `
103
115
 
104
116
  const getLocationKey = () => {
105
- let result = {
117
+ const result = {
106
118
  topMenu: '1',
107
- slideMenu: '0'
119
+ slideMenu: '0',
108
120
  }
109
121
 
110
122
  if (typeof window !== 'undefined') {
@@ -123,13 +135,11 @@ const getLocationKey = () => {
123
135
  locationStr = locationStr.split(prefix)[1]
124
136
  }
125
137
 
126
- // console.log('locationStr', locationStr)
127
-
128
- _.each(menuConfig, (item, index) => {
138
+ _.each(menuConfig, (item) => {
129
139
  const { key, url, subMenus } = item
130
140
 
131
141
  if (subMenus) {
132
- _.each(subMenus, (subItem, subIndex) => {
142
+ _.each(subMenus, (subItem: MenuItem) => {
133
143
  const { key: subKey, url: subUrl } = subItem
134
144
 
135
145
  if (locationStr === subUrl.split('?')[0]) {
@@ -142,6 +152,7 @@ const getLocationKey = () => {
142
152
 
143
153
  return false
144
154
  }
155
+ return true
145
156
  })
146
157
  } else {
147
158
  if (url && locationStr === url.split('?')[0]) {
@@ -149,16 +160,15 @@ const getLocationKey = () => {
149
160
  return false
150
161
  }
151
162
  }
163
+ return true
152
164
  })
153
165
  }
154
166
  }
155
167
  }
156
- // console.log('result', result)
157
168
  return result
158
169
  }
159
170
 
160
171
  const routerPush = (router: any, url: string) => {
161
- // console.log('routerPush', url)
162
172
  if (router && url) {
163
173
  if (prefix && url.indexOf(prefix) === -1) {
164
174
  url = prefix + url
@@ -173,8 +183,6 @@ const LayoutComponent = ({ user, children }) => {
173
183
  const [sliderMenuKey, setSliderMenuKey] = useState('1')
174
184
  const [collapsed, setCollapsed] = useState(false)
175
185
 
176
- // console.log('topMenuKey: ' + topMenuKey, ', sliderMenuKey: ' + sliderMenuKey, user)
177
-
178
186
  useEffect(() => {
179
187
  const { topMenu, slideMenu } = getLocationKey()
180
188
  setTopMenuKey(topMenu)
@@ -184,10 +192,10 @@ const LayoutComponent = ({ user, children }) => {
184
192
  const menuItems: any = []
185
193
  const menuItemsVertical: any = []
186
194
 
187
- _.each(menuConfig, (item, index) => {
195
+ _.each(menuConfig, (item) => {
188
196
  const { key, text, url, icon, subMenus } = item
189
197
 
190
- if (key) {
198
+ if (key && text && url) {
191
199
  const menuObj = {
192
200
  label: text,
193
201
  key,
@@ -200,7 +208,7 @@ const LayoutComponent = ({ user, children }) => {
200
208
  } else {
201
209
  setSliderMenuKey('0')
202
210
  }
203
- }
211
+ },
204
212
  }
205
213
 
206
214
  menuItems.push(menuObj)
@@ -209,51 +217,53 @@ const LayoutComponent = ({ user, children }) => {
209
217
  if (subMenus) {
210
218
  const subMenusChildren: any = []
211
219
 
212
- _.each(subMenus, (subItem, subIndex) => {
220
+ _.each(subMenus, (subItem: MenuItem) => {
213
221
  const { key: subKey, text: subText, url: subUrl } = subItem
214
222
 
215
- const subMenusChildrenObj = {
216
- key: 'slider_' + subKey,
217
- label: subText,
218
- onClick: () => {
219
- routerPush(router, subUrl)
220
-
221
- const subKeyArr = subKey.split('_')
222
- const subKeyArrLen = subKeyArr.length
223
+ if (subKey && subText && subUrl) {
224
+ const subMenusChildrenObj = {
225
+ key: `slider_${subKey}`,
226
+ label: subText,
227
+ onClick: () => {
228
+ routerPush(router, subUrl)
223
229
 
224
- // console.log(subKeyArr, subKeyArrLen)
230
+ const subKeyArr = subKey.split('_')
231
+ const subKeyArrLen = subKeyArr.length
225
232
 
226
- if (subKeyArrLen >= 1) setTopMenuKey(subKeyArr[0])
227
- if (subKeyArrLen >= 2) setSliderMenuKey(subKeyArr[1])
233
+ if (subKeyArrLen >= 1) setTopMenuKey(subKeyArr[0])
234
+ if (subKeyArrLen >= 2) setSliderMenuKey(subKeyArr[1])
235
+ },
228
236
  }
229
- }
230
237
 
231
- subMenusChildren.push(subMenusChildrenObj)
238
+ subMenusChildren.push(subMenusChildrenObj)
239
+ }
232
240
  })
233
241
 
234
- const subMenuObjVertical = {
235
- key: 'slider_' + key,
236
- icon,
237
- label: text,
238
- onTitleClick: () => {
239
- setTopMenuKey(key)
240
- setSliderMenuKey('1')
241
- },
242
- children: subMenusChildren
243
- }
242
+ if (key && text && icon) {
243
+ const subMenuObjVertical = {
244
+ key: `slider_${key}`,
245
+ icon,
246
+ label: text,
247
+ onTitleClick: () => {
248
+ setTopMenuKey(key)
249
+ setSliderMenuKey('1')
250
+ },
251
+ children: subMenusChildren,
252
+ }
244
253
 
245
- menuItemsVertical.push(subMenuObjVertical)
254
+ menuItemsVertical.push(subMenuObjVertical)
255
+ }
246
256
  } else {
247
- if (key) {
257
+ if (key && text && url) {
248
258
  const menuObjVertical = {
249
259
  label: text,
250
260
  icon,
251
- key: 'slider_' + key + '_0',
261
+ key: `slider_${key}_0`,
252
262
  onClick: () => {
253
263
  routerPush(router, url)
254
264
  setTopMenuKey(key)
255
265
  setSliderMenuKey('0')
256
- }
266
+ },
257
267
  }
258
268
 
259
269
  menuItemsVertical.push(menuObjVertical)
@@ -266,7 +276,7 @@ const LayoutComponent = ({ user, children }) => {
266
276
  <Container>
267
277
  <StyledHeader>
268
278
  <div className="logo">
269
- <Image width={120} src={prefix + "/images/zhizuotu_1.png"} preview={false} />
279
+ <Image width={120} src={`${prefix}/images/zhizuotu_1.png`} preview={false} />
270
280
  </div>
271
281
  <Menu
272
282
  theme="dark"
@@ -329,39 +339,41 @@ const LayoutComponent = ({ user, children }) => {
329
339
  mode="inline"
330
340
  defaultSelectedKeys={['slider_1_0']}
331
341
  defaultOpenKeys={['slider_1']}
332
- selectedKeys={['slider_' + topMenuKey + '_' + sliderMenuKey]}
333
- openKeys={['slider_' + topMenuKey]}
342
+ selectedKeys={[`slider_${topMenuKey}_${sliderMenuKey}`]}
343
+ openKeys={[`slider_${topMenuKey}`]}
334
344
  items={menuItemsVertical}
335
345
  className="side-menu"
336
346
  />
337
347
  </div>
338
348
  </StyledSider>
339
349
  <ContentLayout className="content-layout">
340
- <StyledBreadcrumb>
341
- {_.map(menuConfig, (item, index) => {
342
- const { key, text, subMenus } = item
343
-
344
- if (subMenus) {
345
- let subContent: any = []
346
- _.each(subMenus, (subItem, subIndex) => {
347
- const { key: subKey, text: subText } = subItem
348
- if (subKey === topMenuKey + '_' + sliderMenuKey) {
349
- subContent.push(<Breadcrumb.Item key={'breadcrumb' + subIndex}>{text}</Breadcrumb.Item>)
350
- subContent.push(<Breadcrumb.Item key={'breadcrumb' + subIndex + '_sub'}>{subText}</Breadcrumb.Item>)
351
- return false
350
+ <StyledBreadcrumb
351
+ items={_.compact(
352
+ _.flatMap(menuConfig, (item, index) => {
353
+ const { key, text, subMenus } = item
354
+
355
+ if (subMenus) {
356
+ const subItems: any = []
357
+ _.each(subMenus, (subItem: MenuItem, subIndex: number) => {
358
+ const { key: subKey, text: subText } = subItem
359
+ if (subKey === `${topMenuKey}_${sliderMenuKey}`) {
360
+ subItems.push({ title: text, key: `breadcrumb${subIndex}` })
361
+ subItems.push({ title: subText, key: `breadcrumb${subIndex}_sub` })
362
+ return false
363
+ }
364
+ return true
365
+ })
366
+ return subItems
367
+ } else {
368
+ if (key && key === topMenuKey) {
369
+ return { title: text, key: `breadcrumb${index}` }
352
370
  }
353
- })
354
- return subContent
355
- } else {
356
- if (key && key === topMenuKey) {
357
- return <Breadcrumb.Item key={'breadcrumb' + index}>{text}</Breadcrumb.Item>
358
371
  }
359
- }
360
- })}
361
- </StyledBreadcrumb>
362
- <StyledContent>
363
- {children}
364
- </StyledContent>
372
+ return null
373
+ })
374
+ )}
375
+ />
376
+ <StyledContent>{children}</StyledContent>
365
377
  </ContentLayout>
366
378
  </FlexLayout>
367
379
  </Container>
@@ -2,4 +2,4 @@ import { templateManageReducer } from './template/manage/reducers'
2
2
 
3
3
  export default {
4
4
  templateManage: templateManageReducer,
5
- }
5
+ }
@@ -16,6 +16,7 @@ if (reducersKeysLen > 0) {
16
16
  export type RootState = ReturnType<typeof combineReducer>
17
17
 
18
18
  // 创建一个临时 store 实例来获取正确的 dispatch 类型
19
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
20
  const tempStore = configureStore({
20
21
  reducer: combineReducer,
21
22
  middleware: (getDefaultMiddleware) =>
@@ -48,7 +49,7 @@ export const initializeStore = (preloadedState?: any): EnhancedStore => {
48
49
  if (preloadedState && store) {
49
50
  _store = initStore({
50
51
  ...store.getState(),
51
- ...preloadedState
52
+ ...preloadedState,
52
53
  })
53
54
  store = undefined
54
55
  }