nsgm-cli 1.0.27 → 2.0.1

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 (70) hide show
  1. package/.babelrc +13 -0
  2. package/LICENSE +201 -201
  3. package/README.md +160 -162
  4. package/client/layout/index.tsx +245 -0
  5. package/client/redux/reducers.ts +5 -0
  6. package/{generation/client → client}/redux/store.ts +50 -44
  7. package/{generation/client → client}/redux/template/manage/actions.ts +190 -190
  8. package/{generation/client → client}/redux/template/manage/reducers.ts +118 -118
  9. package/{generation/client → client}/redux/template/manage/types.ts +24 -24
  10. package/client/service/template/manage.ts +97 -0
  11. package/{generation/client → client}/styled/common.ts +27 -28
  12. package/client/styled/layout/index.ts +26 -0
  13. package/{generation/client → client}/styled/template/manage.ts +51 -51
  14. package/client/utils/common.ts +86 -0
  15. package/client/utils/cookie.ts +52 -0
  16. package/{generation/client → client}/utils/fetch.ts +25 -25
  17. package/client/utils/menu.tsx +27 -0
  18. package/generation/.DS_Store +0 -0
  19. package/generation/.babelrc +3 -2
  20. package/generation/README.md +19 -18
  21. package/generation/app.js +2 -2
  22. package/generation/client/redux/reducers.ts +5 -5
  23. package/generation/client/utils/menu.tsx +27 -26
  24. package/generation/gitignore +5 -4
  25. package/generation/mysql.config.js +13 -12
  26. package/generation/next.config.js +6 -6
  27. package/generation/package.json +25 -20
  28. package/generation/project.config.js +12 -12
  29. package/generation/server/rest.js +20 -20
  30. package/generation/server/utils/common.js +7 -0
  31. package/generation/tsconfig.json +30 -29
  32. package/index.js +10 -10
  33. package/lib/args.d.ts +6 -6
  34. package/lib/args.js +47 -47
  35. package/lib/generate.d.ts +3 -3
  36. package/lib/generate.js +733 -590
  37. package/lib/index.d.ts +2 -2
  38. package/lib/index.js +259 -182
  39. package/lib/server/db.d.ts +5 -5
  40. package/lib/server/db.js +110 -47
  41. package/lib/server/graphql.d.ts +7 -7
  42. package/lib/server/graphql.js +119 -119
  43. package/lib/server/plugins/date.d.ts +5 -5
  44. package/lib/server/plugins/date.js +16 -16
  45. package/lib/tsconfig.build.tsbuildinfo +1 -0
  46. package/mysql.config.js +14 -14
  47. package/next-env.d.ts +6 -0
  48. package/next.config.js +194 -174
  49. package/package.json +125 -113
  50. package/{generation/pages → pages}/_app.tsx +44 -44
  51. package/{generation/pages → pages}/_document.tsx +4 -2
  52. package/pages/index.tsx +68 -0
  53. package/{generation/pages → pages}/template/manage.tsx +278 -280
  54. package/project.config.js +14 -14
  55. package/public/slbhealthcheck.html +10 -0
  56. package/scripts/shutdown.sh +10 -0
  57. package/scripts/startup.sh +35 -0
  58. package/{generation/server → server}/apis/template.js +17 -18
  59. package/{generation/server → server}/modules/template/resolver.js +29 -35
  60. package/{generation/server → server}/modules/template/schema.js +33 -33
  61. package/server/rest.js +20 -0
  62. package/{generation/server → server}/sql/template.sql +8 -8
  63. package/server/utils/common.js +7 -0
  64. package/generation/client/layout/index.tsx +0 -223
  65. package/generation/client/service/template/manage.ts +0 -74
  66. package/generation/client/styled/layout/index.ts +0 -14
  67. package/generation/client/utils/common.ts +0 -45
  68. package/generation/next-env.d.ts +0 -2
  69. package/generation/pages/index.tsx +0 -55
  70. /package/{generation/public → public}/images/zhizuotu_1.png +0 -0
@@ -0,0 +1,97 @@
1
+ import { getLocalGraphql } from '../../utils/fetch'
2
+ import _ from 'lodash'
3
+
4
+ export const getTemplateService = (page=0, pageSize=10) => {
5
+ const getTemplateQuery = `query ($page: Int, $pageSize: Int) { template(page: $page, pageSize: $pageSize) {
6
+ totalCounts items {
7
+ id name
8
+ }
9
+ }
10
+ }`
11
+
12
+ return getLocalGraphql(getTemplateQuery, {
13
+ page,
14
+ pageSize
15
+ })
16
+ }
17
+
18
+ export const searchTemplateByIdService = (id: number) => {
19
+
20
+ const searchTemplateByIdQuery = `query ($id: Int) { templateGet(id: $id){
21
+ id name
22
+ }
23
+ }`
24
+
25
+ return getLocalGraphql(searchTemplateByIdQuery, {
26
+ id
27
+ })
28
+ }
29
+
30
+ export const searchTemplateService = (page = 0, pageSize = 10, data: any) => {
31
+ const { name } = data
32
+
33
+ const searchTemplateQuery = `query ($page: Int, $pageSize: Int, $data: TemplateSearchInput) {
34
+ templateSearch(page: $page, pageSize: $pageSize, data: $data) {
35
+ totalCounts items {
36
+ id name
37
+ }
38
+ }
39
+ }`
40
+
41
+ return getLocalGraphql(searchTemplateQuery, {
42
+ page,
43
+ pageSize,
44
+ data: {
45
+ name
46
+ }
47
+ })
48
+ }
49
+
50
+ export const addTemplateService = (data: any) => {
51
+ const { name } = data
52
+
53
+ const addTemplateQuery = `mutation ($data: TemplateAddInput) { templateAdd(data: $data) }`
54
+
55
+ return getLocalGraphql(addTemplateQuery, {
56
+ data: {
57
+ name
58
+ }
59
+ })
60
+ }
61
+
62
+ export const updateTemplateService = (id: number, data: any) => {
63
+ const { name } = data
64
+
65
+ const updateTemplateQuery = `mutation ($id: Int, $data: TemplateAddInput) { templateUpdate(id: $id, data: $data) }`
66
+
67
+ return getLocalGraphql(updateTemplateQuery, {
68
+ id,
69
+ data: {
70
+ name
71
+ }
72
+ })
73
+ }
74
+
75
+ export const deleteTemplateService = (id: number) => {
76
+ const deleteTemplateQuery = `mutation ($id: Int) { templateDelete(id: $id) }`
77
+
78
+ return getLocalGraphql(deleteTemplateQuery, {
79
+ id
80
+ })
81
+ }
82
+
83
+ export const batchAddTemplateService = (datas: any) => {
84
+ const batchAddTemplateQuery = `mutation ($datas: [TemplateAddInput]) { templateBatchAdd(datas: $datas) }`
85
+
86
+ return getLocalGraphql(batchAddTemplateQuery, {
87
+ datas
88
+ })
89
+ }
90
+
91
+ export const batchDeleteTemplateService = (ids: any) => {
92
+ const batchDeleteTemplateQuery = `mutation ($ids: [Int]) { templateBatchDelete(ids: $ids) }`
93
+
94
+ return getLocalGraphql(batchDeleteTemplateQuery, {
95
+ ids
96
+ })
97
+ }
@@ -1,28 +1,27 @@
1
- import styled, { createGlobalStyle } from 'styled-components'
2
-
3
- export const GlobalStyle = createGlobalStyle`
4
- html,body,#__next {
5
- height: 100%;
6
- border: 1px solid white;
7
- }
8
-
9
- body {
10
- background-color: ${(props: any) => (props.whiteColor ? 'white' : 'black')};
11
- font-family: Helvetica;
12
- margin: 0;
13
- }
14
- `
15
-
16
- export const Container = styled.div`
17
- margin: 20px;
18
- `
19
-
20
- export const Loading = styled.div`
21
- display: flex;
22
- flex: 1;
23
- flex-direction: row;
24
- justify-content: center;
25
- align-items: center;
26
- margin-top: 100px;
27
- `
28
-
1
+ import styled, { createGlobalStyle } from 'styled-components'
2
+
3
+ export const GlobalStyle = createGlobalStyle`
4
+ html,body,#__next {
5
+ height: 100%;
6
+ border: 1px solid white;
7
+ }
8
+
9
+ body {
10
+ background-color: ${(props: any) => (props.whiteColor ? 'white' : 'black')};
11
+ font-family: Helvetica;
12
+ margin: 0;
13
+ }
14
+ `
15
+
16
+ export const Container = styled.div`
17
+ margin: 20px;
18
+ `
19
+
20
+ export const Loading = styled.div`
21
+ display: flex;
22
+ flex: 1;
23
+ flex-direction: row;
24
+ justify-content: center;
25
+ align-items: center;
26
+ margin-top: 100px;
27
+ `
@@ -0,0 +1,26 @@
1
+ import styled from 'styled-components'
2
+
3
+ export const Container = styled.div`
4
+ .header {
5
+ position: relative;
6
+
7
+ .logo {
8
+ float: left;
9
+ width: 120px;
10
+ height: 31px;
11
+ // margin: 16px 24px 16px 0;
12
+ }
13
+
14
+ .site-layout-background {
15
+ background: #fff;
16
+ }
17
+
18
+ .user {
19
+ position: absolute;
20
+ right: 10px;
21
+ top: 0;
22
+ color: white;
23
+ }
24
+ }
25
+
26
+ `
@@ -1,52 +1,52 @@
1
- import styled from 'styled-components'
2
-
3
- export const Container = styled.div`
4
- margin: 20px;
5
- `
6
-
7
- export const SearchRow = styled.div`
8
- margin: 10px;
9
- display: flex;
10
- flex: 1;
11
- flex-direction: row;
12
- justify-content: space-between;
13
- align-items: center;
14
- `
15
-
16
- export const ModalContainer = styled.div`
17
- .line {
18
- display: flex;
19
- flex: 1;
20
- flex-direction: row;
21
- justify-content: flex-start;
22
- align-items: flex-start;
23
- height: 50px;
24
-
25
- label {
26
- display: flex;
27
- flex-direction: column;
28
- justify-content: center;
29
- align-items: flex-start;
30
- width: 80px;
31
- height: 32px;
32
- margin-right: 5px;
33
- }
34
-
35
- input {
36
- flex: 1;
37
- }
38
-
39
- .row {
40
- display: flex;
41
- flex-direction: row;
42
- justify-content: center;
43
- align-items: center;
44
-
45
- .item {
46
- flex-direction: row;
47
- justify-content: flex-start;
48
- align-items: center;
49
- }
50
- }
51
- }
1
+ import styled from 'styled-components'
2
+
3
+ export const Container = styled.div`
4
+ margin: 20px;
5
+ `
6
+
7
+ export const SearchRow = styled.div`
8
+ margin: 10px;
9
+ display: flex;
10
+ flex: 1;
11
+ flex-direction: row;
12
+ justify-content: space-between;
13
+ align-items: center;
14
+ `
15
+
16
+ export const ModalContainer = styled.div`
17
+ .line {
18
+ display: flex;
19
+ flex: 1;
20
+ flex-direction: row;
21
+ justify-content: flex-start;
22
+ align-items: flex-start;
23
+ height: 50px;
24
+
25
+ label {
26
+ display: flex;
27
+ flex-direction: column;
28
+ justify-content: center;
29
+ align-items: flex-start;
30
+ width: 80px;
31
+ height: 32px;
32
+ margin-right: 5px;
33
+ }
34
+
35
+ input {
36
+ flex: 1;
37
+ }
38
+
39
+ .row {
40
+ display: flex;
41
+ flex-direction: row;
42
+ justify-content: center;
43
+ align-items: center;
44
+
45
+ .item {
46
+ flex-direction: row;
47
+ justify-content: flex-start;
48
+ align-items: center;
49
+ }
50
+ }
51
+ }
52
52
  `
@@ -0,0 +1,86 @@
1
+ import getConfig from 'next/config'
2
+ import _ from 'lodash'
3
+
4
+ export const getLocalEnv = () => {
5
+ const nextConfig = getConfig()
6
+ const { publicRuntimeConfig } = nextConfig
7
+ let { env = 'uat' } = publicRuntimeConfig
8
+ env = env.toLowerCase()
9
+ return env
10
+ }
11
+
12
+ export const getLocalApiPrefix = () => {
13
+ const nextConfig = getConfig()
14
+ const { publicRuntimeConfig } = nextConfig
15
+ let { protocol, host, port, prefix, isExport } = publicRuntimeConfig
16
+
17
+ if(!isExport){
18
+ if (typeof window !== 'undefined') {
19
+ const location = window.location
20
+ // console.log('location', location)
21
+ protocol = location.protocol
22
+ if (protocol.indexOf(':') != -1) {
23
+ protocol = protocol.split(':')[0]
24
+ }
25
+ host = location.hostname
26
+ port = location.port
27
+ }
28
+ }
29
+
30
+ const localApiPrefix = protocol + '://' + host + ':' + port + prefix
31
+ // console.log('localApiPrefix', localApiPrefix)
32
+ return localApiPrefix
33
+ }
34
+
35
+ export const handleXSS = (content: string) => {
36
+ content = content || ''
37
+ return content.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;').replace(/\'/g, '&#x27;')
38
+ }
39
+
40
+ export const checkModalObj = (modalObj: {}, ignoreKeys: any = []) => {
41
+ let result: any = null
42
+ _.each(modalObj, (value: any, key: string) => {
43
+ // console.log('checkModalObj', ignoreKeys, key, ignoreKeys.join('.').indexOf(key))
44
+ if (ignoreKeys.length === 0 || (ignoreKeys.length !== 0 && ignoreKeys.join('.').indexOf(key) === -1)) {
45
+ if (_.trim(value) === '') {
46
+ result = {
47
+ key,
48
+ reason: '不能为空'
49
+ }
50
+ return false
51
+ }
52
+ }
53
+ })
54
+ return result
55
+ }
56
+
57
+ export const getUrlParamByKey = (key: string) => {
58
+ let result = ''
59
+ if (typeof window !== 'undefined') {
60
+ const locationHref = window.location.href
61
+ if (locationHref.indexOf('?') !== -1) {
62
+ const locationHrefArr = locationHref.split('?')
63
+ if (locationHrefArr.length > 1) {
64
+ const paramsStr = locationHrefArr[1]
65
+
66
+ let params:any = []
67
+ if (paramsStr.indexOf('&') !== -1) {
68
+ params = paramsStr.split('&')
69
+ } else {
70
+ params.push(paramsStr)
71
+ }
72
+
73
+ _.each(params, (item, index) => {
74
+ if (item.indexOf('=') !== -1) {
75
+ const itemArr = item.split('=')
76
+ if (itemArr[0] === key) {
77
+ result = itemArr[1]
78
+ return false
79
+ }
80
+ }
81
+ })
82
+ }
83
+ }
84
+ }
85
+ return result
86
+ }
@@ -0,0 +1,52 @@
1
+ import _ from 'lodash'
2
+
3
+ export const setCookie = (name: string, value:string, cookieExpire:any) => {
4
+ const currentDate = new Date()
5
+ const currentTime = currentDate.getTime()
6
+ let expiresTime = currentDate
7
+ expiresTime.setTime(currentTime + 60 * 1000 * 60 * 24 * 30)
8
+
9
+ if (typeof document !== 'undefined') {
10
+ let cookie = name + '=' + window.btoa(encodeURIComponent(value))
11
+ // let cookie = name + '=' + encodeURIComponent(value)
12
+ if (cookieExpire) {
13
+ cookie += ";expires=" + cookieExpire
14
+ } else {
15
+ cookie += ";expires=" + expiresTime.toUTCString()
16
+ }
17
+
18
+ cookie += ";path=/"
19
+ document.cookie = cookie
20
+ }
21
+ }
22
+
23
+ export const getCookie = (name: string) => {
24
+ let result = ''
25
+ if (typeof document !== 'undefined') {
26
+ const cookie = document.cookie
27
+ // console.log('cookie', cookie)
28
+
29
+ const cookieArr = cookie.split("; ")
30
+
31
+ _.each(cookieArr, (item, index) => {
32
+ const itemArr = item.split("=")
33
+ if (name === itemArr[0]) {
34
+ result = decodeURIComponent(window.atob(itemArr[1]))
35
+ // result = decodeURIComponent(itemArr[1])
36
+ return false
37
+ }
38
+ })
39
+ }
40
+ return result
41
+ }
42
+
43
+ export const delCookie = (name: string) => {
44
+ const currentDate = new Date()
45
+ const currentTime = currentDate.getTime()
46
+ let expiresTime = currentDate
47
+ expiresTime.setTime(currentTime - 1)
48
+
49
+ if (typeof document !== 'undefined') {
50
+ document.cookie = name + "=;expires=" + expiresTime.toUTCString() + ";path=/"
51
+ }
52
+ }
@@ -1,25 +1,25 @@
1
- import axios from 'axios'
2
- import { getLocalApiPrefix } from './common'
3
-
4
- export const getLocalGraphql = (query: string, variables: any = {}) => {
5
- return new Promise((resolve, reject) => {
6
- axios
7
- .post(getLocalApiPrefix() + '/graphql', {
8
- query,
9
- variables
10
- })
11
- .then((res) => {
12
- // console.log('axios_res', res)
13
- if (res) {
14
- const { data } = res
15
- resolve(data)
16
- } else {
17
- reject()
18
- }
19
- })
20
- .catch((_e) => {
21
- // console.error('axios_e', _e)
22
- reject(_e)
23
- })
24
- })
25
- }
1
+ import axios from 'axios'
2
+ import { getLocalApiPrefix } from './common'
3
+
4
+ export const getLocalGraphql = (query: string, variables: any = {}) => {
5
+ return new Promise((resolve, reject) => {
6
+ axios
7
+ .post(getLocalApiPrefix() + '/graphql', {
8
+ query,
9
+ variables
10
+ })
11
+ .then((res) => {
12
+ // console.log('axios_res', res)
13
+ if (res) {
14
+ const { data } = res
15
+ resolve(data)
16
+ } else {
17
+ reject()
18
+ }
19
+ })
20
+ .catch((_e) => {
21
+ // console.error('axios_e', _e)
22
+ reject(_e)
23
+ })
24
+ })
25
+ }
@@ -0,0 +1,27 @@
1
+ import { BookOutlined, SolutionOutlined } from '@ant-design/icons'
2
+ import React from 'react'
3
+
4
+ let key = 1
5
+
6
+ export default [
7
+ {
8
+ key: key.toString(),
9
+ text: '介绍',
10
+ url: '/',
11
+ icon: <BookOutlined />,
12
+ subMenus: null
13
+ },
14
+ {
15
+ key: (++key).toString(),
16
+ text: '模板',
17
+ url: '/template/manage',
18
+ icon: <SolutionOutlined />,
19
+ subMenus: [
20
+ {
21
+ key: key + '_1',
22
+ text: '模板1',
23
+ url: '/template/manage'
24
+ }
25
+ ]
26
+ }
27
+ ]
Binary file
@@ -2,9 +2,10 @@
2
2
  "presets": ["next/babel"],
3
3
  "plugins": [
4
4
  ["styled-components", {
5
- "ssr": true ,
5
+ "ssr": true,
6
6
  "displayName": true,
7
7
  "preprocess": false
8
8
  }]
9
9
  ]
10
- }
10
+ }
11
+
@@ -1,19 +1,20 @@
1
- # NSGM CLI PROJECT
2
-
3
- ## 命令
4
- - npm run init 初始化项目
5
- - npm run upgrade 升级项目基础文件
6
- - npm run create 创建模板页面
7
- - npm run delete 删除模板页面
8
- - npm run dev 开发模式
9
- - npm run start 生产模式
10
- - npm run build 编译
11
- - npm run export 导出静态页面
12
-
13
- ## 参数
14
- - dictionary: 在 export/init 的时候使用, 默认 webapp, 譬如: npm run init|export dictionary=webapp 或者 npm run init|export webapp
15
- - controller: 在 create/delete 的时候使用, 必须有。譬如: npm run create|delete math
16
- - action: 在 create/delete 的时候使用, 默认 manage, 跟在 controller 后面, 譬如 npm run create|delete math test
17
-
18
- ## 发布
1
+ # NSGM CLI PROJECT
2
+
3
+ ## 命令
4
+ - npm run init 初始化项目
5
+ - npm run upgrade 升级项目基础文件
6
+ - npm run create 创建模板页面
7
+ - npm run delete 删除模板页面
8
+ - npm run dev 开发模式
9
+ - npm run start 生产模式
10
+ - npm run build 编译
11
+ - npm run export 导出静态页面
12
+
13
+ ## 参数
14
+ - dictionary: 在 export/init 的时候使用, 默认 webapp, 譬如: npm run init|export dictionary=webapp 或者 npm run init|export webapp
15
+ - controller: 在 create/delete 的时候使用, 必须有。譬如: npm run create|delete math
16
+ - action: 在 create/delete 的时候使用, 默认 manage, 跟在 controller 后面, 譬如 npm run create|delete math test
17
+
18
+
19
+ ## 发布
19
20
  - npm version patch
package/generation/app.js CHANGED
@@ -1,3 +1,3 @@
1
- const { startExpress } = require('nsgm-cli/lib/index')
2
-
1
+ const { startExpress } = require('nsgm-cli/lib/index')
2
+
3
3
  startExpress({ dev: false })
@@ -1,5 +1,5 @@
1
- // import { templateManageReducer } from './template/manage/reducers'
2
-
3
- export default {
4
- // templateManage: templateManageReducer,
5
- }
1
+ //import { templateManageReducer } from './template/manage/reducers'
2
+
3
+ export default {
4
+ //templateManage: templateManageReducer,
5
+ }
@@ -1,26 +1,27 @@
1
- import { BookOutlined, SolutionOutlined } from '@ant-design/icons'
2
-
3
- let key = 0
4
-
5
- export default [
6
- {
7
- key: (++key).toString(),
8
- text: '介绍',
9
- url: '/',
10
- icon: <BookOutlined />,
11
- subMenus: null
12
- }
13
- /*{
14
- key: (++key).toString(),
15
- text: '模板',
16
- url: '/template/manage',
17
- icon: <SolutionOutlined />,
18
- subMenus: [
19
- {
20
- key: key + '_1',
21
- text: '模板1',
22
- url: '/template/manage'
23
- }
24
- ]
25
- },*/
26
- ]
1
+ import { BookOutlined, SolutionOutlined } from '@ant-design/icons'
2
+ import React from 'react'
3
+
4
+ let key = 1
5
+
6
+ export default [
7
+ {
8
+ key: key.toString(),
9
+ text: '介绍',
10
+ url: '/',
11
+ icon: <BookOutlined />,
12
+ subMenus: null
13
+ },
14
+ /*{
15
+ key: (++key).toString(),
16
+ text: '模板',
17
+ url: '/template/manage',
18
+ icon: <SolutionOutlined />,
19
+ subMenus: [
20
+ {
21
+ key: key + '_1',
22
+ text: '模板1',
23
+ url: '/template/manage'
24
+ }
25
+ ]
26
+ },*/
27
+ ]
@@ -1,4 +1,5 @@
1
- node_modules
2
- .next
3
- out
4
- build
1
+ node_modules
2
+ .next
3
+ out
4
+ build
5
+ scripts/dump.*
@@ -1,13 +1,14 @@
1
- const { mysqlConfig } = require('nsgm-cli')
2
- const { mysqlOptions } = mysqlConfig
3
- const { user, password, host, port, database } = mysqlOptions
4
-
5
- module.exports = {
6
- mysqlOptions: {
7
- user: 'root',
8
- password: 'password',
9
- host: '127.0.0.1',
10
- port: 3306,
11
- database: 'crm_demo'
12
- }
1
+ const { mysqlConfig } = require('nsgm-cli')
2
+ const { mysqlOptions, mysqlDBCluster } = mysqlConfig
3
+ const { user, password, host, port, database } = mysqlOptions
4
+
5
+ module.exports = {
6
+ mysqlOptions: {
7
+ user: 'root',
8
+ password: 'password',
9
+ host: '127.0.0.1',
10
+ port: 3306,
11
+ database: 'crm_demo'
12
+ },
13
+ mysqlDBCluster
13
14
  }
@@ -1,7 +1,7 @@
1
- const { nextConfig } = require('nsgm-cli')
2
-
3
- module.exports = (phase, defaultConfig) => {
4
- let configObj = nextConfig(phase, defaultConfig)
5
-
6
- return configObj
1
+ const { nextConfig } = require('nsgm-cli')
2
+
3
+ module.exports = (phase, defaultConfig) => {
4
+ let configObj = nextConfig(phase, defaultConfig)
5
+
6
+ return configObj
7
7
  }