jjb-cmd 1.0.11 → 1.0.12

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/bin/command.js CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  const commander = require('commander');
4
4
  const cliScripts = require('../src/cli.pull.js');
5
+ const cliScripts2 = require('../src/cli.pull2.js');
6
+ const cliScripts3 = require('../src/cli.install/index.js');
5
7
  const MergeScripts = require('../src/cli.merge.js');
6
8
 
7
9
  commander.command('v').description('-- 查看版本').action(() => {
8
- console.log('当前版本 v1.0.0');
10
+ console.log('当前版本 v1.0.12');
9
11
  });
10
12
 
11
13
  commander.command('help').description('-- 帮助').action(() => {
@@ -13,7 +15,7 @@ commander.command('help').description('-- 帮助').action(() => {
13
15
  console.log('1.jjb-cmd v -- 查看版本。');
14
16
  console.log('2.jjb-cmd help -- 帮助。');
15
17
  console.log('3.jjb-cmd view res -- 预览资源。');
16
- console.log('4.jjb-cmd [actionName (有效值 pull)] [...args] -- 基础功能。');
18
+ console.log('4.jjb-cmd [actionName (有效值 pull | pull2)] [...args] -- 基础功能。');
17
19
  });
18
20
 
19
21
  commander.command('view res').description('-- 预览资源').action(() => {
@@ -23,13 +25,24 @@ commander.command('view res').description('-- 预览资源').action(() => {
23
25
 
24
26
  // pull 命令
25
27
  commander.command('pull -- <文件夹名称必填。>').description('-- 文件名称').action(res => {
28
+ console.log('pull命令已过时,新项目请使用pull2.');
26
29
  cliScripts(res);
27
30
  });
28
31
 
32
+ // pull 命令
33
+ commander.command('pull2 -- <文件夹名称必填。>').description('-- 文件名称').action(res => {
34
+ cliScripts2(res);
35
+ });
36
+
37
+ // install 安装
38
+ commander.command('install').description('-- 安装').action(res => {
39
+ cliScripts3(res);
40
+ });
41
+
29
42
  //多省多应用命令
30
43
  commander.command('mp -- <multi prov多省多应用启动dev>').description('-- multi prov多省多应用合并').action(res => {
31
44
  MergeScripts(res, 'mp');
32
- console.log('start test')
45
+ console.log('start test');
33
46
  });
34
47
 
35
48
  //多省单应用
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jjb-cmd",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "jjb脚手架工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,39 @@
1
+ import dva from 'dva';
2
+ import ReactDOM from 'react-dom';
3
+ import { createBrowserHistory } from 'history';
4
+ import 'antd/dist/antd.less';
5
+
6
+ /**
7
+ * @description 注册app
8
+ * @param selector {string}
9
+ * @returns {{unmount: Function, mount: Function, bootstrap: Function}}
10
+ */
11
+ export const registerApplication = (selector = '#root') => {
12
+ const createHistory = createBrowserHistory();
13
+
14
+ const app = dva({ history: createHistory });
15
+ require('./models').automaticModels(app);
16
+
17
+ app.router(config => require('./router').AutomaticRouter({
18
+ ...config,
19
+ basename: process.env.app.basename
20
+ }));
21
+
22
+ const render = () => app.start(selector);
23
+
24
+ if (!window.__POWERED_BY_QIANKUN__) {
25
+ render();
26
+ }
27
+
28
+ return {
29
+ mount: () => render(),
30
+ unmount: props => {
31
+ const { container } = props;
32
+ const element = container
33
+ ? container.querySelector('#root')
34
+ : document.querySelector('#root');
35
+ ReactDOM.unmountComponentAtNode(element);
36
+ },
37
+ bootstrap: props => props
38
+ };
39
+ };
@@ -0,0 +1,16 @@
1
+ import dva from 'dva';
2
+ import ReactDOM from 'react-dom';
3
+ import { createBrowserHistory } from 'history';
4
+ import 'antd/dist/antd.less';
5
+
6
+ /**
7
+ * @description 注册app
8
+ * @param selector {string}
9
+ * @returns {{unmount: Function, mount: Function, bootstrap: Function}}
10
+ */
11
+ export const registerApplication = (selector = '#app-root') => {
12
+ const app = dva({ history: createBrowserHistory() });
13
+ require('./models').automaticModels(app);
14
+ app.router(config => require('./router').AutomaticRouter(config));
15
+ app.start(selector);
16
+ };
@@ -0,0 +1,124 @@
1
+ import React from 'react';
2
+ import { ConfigProvider, Result } from 'antd';
3
+ import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
4
+
5
+ /**
6
+ * @description react路由扫描器
7
+ * @param props {{app: object}}
8
+ */
9
+ function ReactRouterScanner (props) {
10
+ const paths = require.context('~/pages', true, /\.(jsx|js)$/).keys();
11
+ const symbolByEntry = 'Entry_index.js';
12
+ const symbolByContainer = 'Container_index.js';
13
+
14
+ /**
15
+ * @description 路由处理
16
+ * @param path {string}
17
+ * @return string
18
+ */
19
+ function routeHandle (path) {
20
+ return `/${path.replace(/\/index.js$/, '').split(/\//).map(a => {
21
+ a = a.replace(a[ 0 ], a[ 0 ].toLowerCase());
22
+ return a;
23
+ }).map(a => {
24
+ if (/^[a-zA-Z]+_[a-zA-Z]+$/.test(a)) {
25
+ return `:${a.split(/_/).join('')}`;
26
+ }
27
+ return a;
28
+ }).join('/')}`;
29
+ }
30
+
31
+ const routerMap = paths.map(path => {
32
+ const pure = path.replace(/^\.\//, '');
33
+ return {
34
+ path: pure === 'index.js'
35
+ ? '/'
36
+ : pure === symbolByContainer
37
+ ? '/container'
38
+ : path === symbolByEntry
39
+ ? '/entry'
40
+ : routeHandle(pure),
41
+ suffix: 'index.js',
42
+ component: require(`~/pages/${pure}`).default,
43
+ componentName: pure.replace(/\//g, '_')
44
+ };
45
+ });
46
+
47
+ const Main = routerMap.find(item => item.componentName === 'index.js');
48
+ const Entry = routerMap.find(item => item.componentName === symbolByEntry);
49
+ const Container = routerMap.find(item => item.componentName === symbolByContainer);
50
+ const ChildrenRoute = routerMap.filter(item => item.componentName.match(new RegExp('Container_')) && item.path !== '/container');
51
+ const ContainerComponent = Container
52
+ ? Container.component
53
+ : null;
54
+ return (
55
+ <Router
56
+ basename={window.__POWERED_BY_QIANKUN__
57
+ ? props.basename
58
+ : '/'}
59
+ >
60
+ <Switch>
61
+ {Main && (
62
+ <Route
63
+ exact
64
+ path={Main.path}
65
+ component={Main.component}
66
+ />
67
+ )}
68
+ {Entry && (
69
+ <Route
70
+ exact
71
+ path={Entry.path}
72
+ component={Entry.component}
73
+ />
74
+ )}
75
+ {Container && (
76
+ <Route
77
+ path={Container.path}
78
+ render={$props => (
79
+ <ContainerComponent {...$props}>
80
+ <Switch>
81
+ {ChildrenRoute.map((route, key) => (
82
+ <Route
83
+ exact
84
+ key={key}
85
+ path={route.path}
86
+ component={route.component}
87
+ />
88
+ ))}
89
+ </Switch>
90
+ </ContainerComponent>
91
+ )}
92
+ />
93
+ )}
94
+ <Route
95
+ path="*"
96
+ component={() => <Result title="非常抱歉您访问的地址暂时无法显示,请确认后再试!" />}
97
+ />
98
+ </Switch>
99
+ </Router>
100
+ );
101
+ }
102
+
103
+ /**
104
+ * @description 自动化路由组件
105
+ * @param app {object}
106
+ * @param basename {string}
107
+ * @return {JSX.Element}
108
+ */
109
+ export const AutomaticRouter = ({
110
+ app,
111
+ basename
112
+ }) => {
113
+ return (
114
+ <ConfigProvider
115
+ locale={require('antd/lib/locale/zh_CN').default}
116
+ prefixCls={require('../../../../package.json').antPrefix || 'ant'}
117
+ >
118
+ <ReactRouterScanner
119
+ app={app}
120
+ basename={basename}
121
+ />
122
+ </ConfigProvider>
123
+ );
124
+ };
@@ -0,0 +1,113 @@
1
+ import React from 'react';
2
+ import { ConfigProvider } from 'antd';
3
+ import { Route, Router, Switch } from 'dva/router';
4
+
5
+ /**
6
+ * @description react路由扫描器
7
+ * @param props {{app: object, history: any}}
8
+ */
9
+ function ReactRouterScanner (props) {
10
+ const paths = require.context('~/pages', true, /\.(jsx|js)$/).keys().filter(item => !item.match(/components/));
11
+ const symbolByEntry = 'Entry_index.js';
12
+ const symbolByContainer = 'Container_index.js';
13
+
14
+ /**
15
+ * @description 路由处理
16
+ * @param path {string}
17
+ * @return string
18
+ */
19
+ function routeHandle (path) {
20
+ return `/${path.replace(/\/index.js$/, '').split(/\//).map(a => {
21
+ a = a.replace(a[ 0 ], a[ 0 ].toLowerCase());
22
+ return a;
23
+ }).map(a => {
24
+ if (/^[a-zA-Z]+_[a-zA-Z]+$/.test(a)) {
25
+ return `:${a.split(/_/).join('')}`;
26
+ }
27
+ return a;
28
+ }).join('/')}`;
29
+ }
30
+
31
+ const routerMap = paths.map(path => {
32
+ const pure = path.replace(/^\.\//, '');
33
+ return {
34
+ path: pure === 'index.js'
35
+ ? '/'
36
+ : pure === symbolByContainer
37
+ ? '/container'
38
+ : path === symbolByEntry
39
+ ? '/entry'
40
+ : routeHandle(pure),
41
+ suffix: 'index.js',
42
+ component: require(`~/pages/${pure}`).default,
43
+ componentName: pure.replace(/\//g, '_')
44
+ };
45
+ });
46
+
47
+ const Main = routerMap.find(item => item.componentName === 'index.js');
48
+ const Entry = routerMap.find(item => item.componentName === symbolByEntry);
49
+ const Container = routerMap.find(item => item.componentName === symbolByContainer);
50
+ const ChildrenRoute = routerMap.filter(item => item.componentName.match(new RegExp('Container_')) && item.path !== '/container');
51
+ const ContainerComponent = Container
52
+ ? Container.component
53
+ : null;
54
+ return (
55
+ <Router history={props.history}>
56
+ <Switch location={history.location}>
57
+ {Main && (
58
+ <Route
59
+ exact
60
+ path={Main.path}
61
+ component={Main.component}
62
+ />
63
+ )}
64
+ {Entry && (
65
+ <Route
66
+ exact
67
+ path={Entry.path}
68
+ component={Entry.component}
69
+ />
70
+ )}
71
+ {Container && (
72
+ <Route
73
+ path={Container.path}
74
+ render={$props => (
75
+ <ContainerComponent {...$props}>
76
+ <Switch location={history.location}>
77
+ {ChildrenRoute.map((route, key) => (
78
+ <Route
79
+ exact
80
+ key={key}
81
+ path={route.path}
82
+ component={route.component}
83
+ />
84
+ ))}
85
+ </Switch>
86
+ </ContainerComponent>
87
+ )}
88
+ />
89
+ )}
90
+ </Switch>
91
+ </Router>
92
+ );
93
+ }
94
+
95
+ /**
96
+ * @description 自动化路由组件
97
+ * @param app {object}
98
+ * @param history {history}
99
+ * @return {JSX.Element}
100
+ */
101
+ export const AutomaticRouter = ({
102
+ app,
103
+ history
104
+ }) => {
105
+ return (
106
+ <ConfigProvider locale={require('antd/lib/locale/zh_CN').default}>
107
+ <ReactRouterScanner
108
+ app={app}
109
+ history={history}
110
+ />
111
+ </ConfigProvider>
112
+ );
113
+ };
@@ -0,0 +1,190 @@
1
+ const os = require('os');
2
+
3
+ exports.GIT_HOST = 'http://192.168.1.242:10985';
4
+ exports.GIT_TEMP_DIR = `jjbAssembly_${Date.now()}`;
5
+ exports.CLOUD_PROJECT = {
6
+ 'common': {
7
+ token: 'G4HJRsHr9D7Ssmixegw2',
8
+ projectId: 279
9
+ },
10
+ 'react-admin-component': {
11
+ token: 'FT3pKzxpRynFkmddJ9Bs',
12
+ projectId: 340
13
+ }
14
+ };
15
+ exports.TEMPLATE_FOLDER = `${os.tmpdir()}\\${exports.GIT_TEMP_DIR}`;
16
+ exports.CLI_DVA_ROUTER_SPA = `${__dirname}\\..\\cli.dva.router.spa.txt`;
17
+ exports.CLI_DVA_ROUTER_SAAS = `${__dirname}\\..\\cli.dva.router.saas.txt`;
18
+ exports.CLI_DVA_REGISTER_SPA = `${__dirname}\\..\\cli.dva.register.spa.txt`;
19
+ exports.CLI_DVA_REGISTER_SAAS = `${__dirname}\\..\\cli.dva.register.saas.txt`;
20
+ exports.CLI_DVA_ROUTER_PATH = '\\dva\\automatic\\router.js';
21
+ exports.CLI_DVA_REGISTER_PATH = '\\dva\\automatic\\register.js';
22
+
23
+ exports.COMMON_CONTENT_NOR_REPLACE = [
24
+ {
25
+ path: `\\tools\\index.js`,
26
+ replace: [
27
+ [
28
+ 'components',
29
+ 'jjb-react-admin-component'
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ path: `\\website\\index.js`,
35
+ replace: [
36
+ [
37
+ /const\srelation\s=\srequire\(`~\/application\/\${module.code}\/enumerate\/menu`\)\.default;/,
38
+ 'const relation = require(\'~/enumerate/menu\').default;'
39
+ ],
40
+ [
41
+ 'components',
42
+ 'jjb-react-admin-component'
43
+ ]
44
+ ]
45
+ }
46
+ ];
47
+
48
+ /**
49
+ * @description 需要替换的文本(单应用)
50
+ * @type {[{path: string, replace: string[][]}]}
51
+ */
52
+ exports.COMMON_CONTENT_SPA_REPLACE = [
53
+ {
54
+ path: `\\tools\\index.js`,
55
+ replace: [
56
+ [
57
+ 'return __planA();',
58
+ 'return process.env;'
59
+ ]
60
+ ]
61
+ }
62
+ ];
63
+
64
+ /**
65
+ * @description 需要替换的文本(微应用)
66
+ * @type {[{path: string, replace: string[][]}]}
67
+ */
68
+ exports.COMMON_CONTENT_MICRO_REPLACE = [
69
+ {
70
+ path: `\\tools\\index.js`,
71
+ replace: [
72
+ [
73
+ 'return __planA();',
74
+ 'return process.env.app;'
75
+ ]
76
+ ]
77
+ }
78
+ ];
79
+
80
+ /**
81
+ * @description react-admin-component 需要替换的文本
82
+ * @type {[{path: string, replace: string[][]},{path: string, replace: string[][]},{path: string, replace: string[][]},{path: string, replace: string[][]},{path: string, replace: string[][]},null,null,null,null]}
83
+ */
84
+ exports.COMPONENTS_CONTENT_REPLACE = [
85
+ {
86
+ path: `\\Editor\\index.js`,
87
+ replace: [
88
+ [
89
+ 'common/http',
90
+ 'jjb-common/http'
91
+ ],
92
+ [
93
+ 'common/crypto',
94
+ 'jjb-common/crypto'
95
+ ],
96
+ [
97
+ 'common/tools',
98
+ 'jjb-common/tools'
99
+ ]
100
+ ]
101
+ },
102
+ {
103
+ path: `\\RejectText\\index.js`,
104
+ replace: [
105
+ [
106
+ 'common/color',
107
+ 'jjb-common/color'
108
+ ]
109
+ ]
110
+ },
111
+ {
112
+ path: `\\RouterMenu\\index.js`,
113
+ replace: [
114
+ [
115
+ 'common/tools',
116
+ 'jjb-common/tools'
117
+ ]
118
+ ]
119
+ },
120
+ {
121
+ path: `\\FileUploader\\index.js`,
122
+ replace: [
123
+ [
124
+ 'common/http',
125
+ 'jjb-common/http'
126
+ ],
127
+ [
128
+ 'common/tools',
129
+ 'jjb-common/tools'
130
+ ]
131
+ ]
132
+ },
133
+ {
134
+ path: `\\ImageCropper\\index.js`,
135
+ replace: [
136
+ [
137
+ 'common/http',
138
+ 'jjb-common/http'
139
+ ],
140
+ [
141
+ 'common/tools',
142
+ 'jjb-common/tools'
143
+ ]
144
+ ]
145
+ },
146
+ {
147
+ path: `\\ImageUploader\\index.js`,
148
+ replace: [
149
+ [
150
+ 'common/http',
151
+ 'jjb-common/http'
152
+ ],
153
+ [
154
+ 'common/tools',
155
+ 'jjb-common/tools'
156
+ ]
157
+ ]
158
+ },
159
+ {
160
+ path: `\\PageHeaderBar\\index.js`,
161
+ replace: [
162
+ [
163
+ 'common/color',
164
+ 'jjb-common/color'
165
+ ]
166
+ ]
167
+ },
168
+ {
169
+ path: `\\RouterContainer\\index.js`,
170
+ replace: [
171
+ [
172
+ 'common/tools',
173
+ 'jjb-common/tools'
174
+ ]
175
+ ]
176
+ },
177
+ {
178
+ path: `\\RouterContainer\\components\\NavigationTab\\index.js`,
179
+ replace: [
180
+ [
181
+ 'common/website',
182
+ 'jjb-common/website'
183
+ ],
184
+ [
185
+ 'common/tools',
186
+ 'jjb-common/tools'
187
+ ]
188
+ ]
189
+ }
190
+ ];