jjb-cmd 1.0.13 → 1.0.15
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 +11 -39
- package/package.json +1 -1
- package/src/cli.dva.register.saas.txt +31 -26
- package/src/cli.dva.register.spa.txt +6 -0
- package/src/cli.dva.router.saas.txt +167 -93
- package/src/cli.dva.router.spa.txt +6 -0
- package/src/cli.init/jjb.config.json +37 -0
- package/src/cli.init/jjb.script/build.js +11 -0
- package/src/cli.init/jjb.script/config.js +214 -0
- package/src/cli.init/jjb.script/proxy.js +19 -0
- package/src/cli.init/jjb.script/server.js +29 -0
- package/src/cli.init/jjb.script/utils.js +13 -0
- package/src/cli.init/package.json +62 -0
- package/src/cli.init/public/index.html +15 -0
- package/src/cli.init/src/enumerate/menu/index.js +1 -0
- package/src/cli.init/src/enumerate/namespace/index.js +3 -0
- package/src/cli.init/src/index.js +24 -0
- package/src/cli.init/src/models/demo/index.js +10 -0
- package/src/cli.init/src/pages/index.js +14 -0
- package/src/cli.init/webstorm.config.js +18 -0
- package/src/cli.init.js +29 -0
- package/src/cli.install/config.js +5 -1
- package/src/cli.install/index.js +329 -214
- package/src/cli.install/tools.js +5 -3
- package/src/cli.rm-rf.js +88 -0
- package/src/progress-bar.js +23 -0
package/bin/command.js
CHANGED
@@ -1,21 +1,15 @@
|
|
1
1
|
#! /usr/bin/env node
|
2
2
|
|
3
|
-
const fs = require('fs');
|
4
|
-
const path = require('path');
|
5
|
-
const readline = require('readline');
|
6
3
|
const commander = require('commander');
|
7
|
-
const io = readline.createInterface({
|
8
|
-
input: process.stdin,
|
9
|
-
output: process.stdout
|
10
|
-
});
|
11
4
|
const cliScripts = require('../src/cli.pull.js');
|
12
5
|
const cliScripts2 = require('../src/cli.pull2.js');
|
13
6
|
const cliScripts3 = require('../src/cli.install/index.js');
|
7
|
+
const cliScripts4 = require('../src/cli.rm-rf.js');
|
8
|
+
const cliScripts6 = require('../src/cli.init');
|
14
9
|
const MergeScripts = require('../src/cli.merge.js');
|
15
10
|
|
16
11
|
commander.command('v').description('-- 查看版本').action(() => {
|
17
|
-
|
18
|
-
console.log(`当前版本 ${package.version}`)
|
12
|
+
console.log('当前版本 v1.0.12');
|
19
13
|
});
|
20
14
|
|
21
15
|
commander.command('help').description('-- 帮助').action(() => {
|
@@ -23,7 +17,7 @@ commander.command('help').description('-- 帮助').action(() => {
|
|
23
17
|
console.log('1.jjb-cmd v -- 查看版本。');
|
24
18
|
console.log('2.jjb-cmd help -- 帮助。');
|
25
19
|
console.log('3.jjb-cmd view res -- 预览资源。');
|
26
|
-
console.log('4.jjb-cmd [actionName (有效值 pull | pull2)] [...args] -- 基础功能。');
|
20
|
+
console.log('4.jjb-cmd [actionName (有效值 pull | pull2 | install | rm-rf)] [...args] -- 基础功能。');
|
27
21
|
});
|
28
22
|
|
29
23
|
commander.command('view res').description('-- 预览资源').action(() => {
|
@@ -42,37 +36,15 @@ commander.command('pull2 -- <文件夹名称必填。>').description('-- 文件
|
|
42
36
|
cliScripts2(res);
|
43
37
|
});
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
exec(path.resolve('./'));
|
49
|
-
console.log('删除完成。');
|
50
|
-
} else if (answer.trim() === 'n') {
|
51
|
-
console.log('取消删除。');
|
52
|
-
} else {
|
53
|
-
console.log('无效操作。');
|
54
|
-
}
|
55
|
-
process.exit(0);
|
56
|
-
});
|
39
|
+
// pull 命令
|
40
|
+
commander.command('init').description('-- 初始化项目').action(res => {
|
41
|
+
cliScripts6(res);
|
57
42
|
});
|
58
43
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
const item = list[ i ];
|
64
|
-
const vPath = `${path}/${item}`;
|
65
|
-
if (fs.statSync(vPath).isDirectory()) {
|
66
|
-
exec(vPath);
|
67
|
-
fs.rmdirSync(vPath);
|
68
|
-
console.log('删除文件夹:' + vPath);
|
69
|
-
} else {
|
70
|
-
fs.unlinkSync(vPath);
|
71
|
-
console.log('删除文件:' + vPath);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
};
|
44
|
+
// rm-rf 命令
|
45
|
+
commander.command('rm-rf').description('-- 删除全部').action(res => {
|
46
|
+
cliScripts4(res);
|
47
|
+
});
|
76
48
|
|
77
49
|
// install 安装
|
78
50
|
commander.command('install').description('-- 安装').action(res => {
|
package/package.json
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* @author XiWell
|
3
|
+
* @version 2.0.1
|
4
|
+
* @description 基于QianKun框架的APP注册文件,请勿修改!
|
5
|
+
*/
|
6
|
+
|
7
|
+
import 'moment/locale/zh-cn';
|
1
8
|
import dva from 'dva';
|
2
|
-
import ReactDOM from 'react-dom';
|
3
9
|
import { createBrowserHistory } from 'history';
|
4
|
-
import '
|
10
|
+
import { unmountComponentAtNode } from 'react-dom';
|
5
11
|
|
6
12
|
/**
|
7
13
|
* @description 注册app
|
@@ -9,31 +15,30 @@ import 'antd/dist/antd.less';
|
|
9
15
|
* @returns {{unmount: Function, mount: Function, bootstrap: Function}}
|
10
16
|
*/
|
11
17
|
export const registerApplication = (selector = '#root') => {
|
12
|
-
|
18
|
+
try {
|
19
|
+
const app = dva({ history: createBrowserHistory() });
|
20
|
+
require('./models').automaticModels(app);
|
21
|
+
app.router(config => require('./router').AutomaticRouter(config));
|
13
22
|
|
14
|
-
|
15
|
-
|
23
|
+
const render = () => app.start(selector);
|
24
|
+
if (!window.__POWERED_BY_QIANKUN__) render();
|
16
25
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
return {
|
27
|
+
mount: () => render(),
|
28
|
+
unmount: props => {
|
29
|
+
if (window.__POWERED_BY_QIANKUN__) {
|
30
|
+
const { container } = props;
|
31
|
+
const element = container
|
32
|
+
? container.querySelector(selector)
|
33
|
+
: document.querySelector(selector);
|
34
|
+
unmountComponentAtNode(element);
|
35
|
+
} else {
|
36
|
+
console.error('卸载APP失败,原因:', '当前环境非QianKun');
|
37
|
+
}
|
38
|
+
},
|
39
|
+
bootstrap: props => props
|
40
|
+
};
|
41
|
+
} catch (e) {
|
42
|
+
console.error('注册APP失败,原因:', e.message);
|
26
43
|
}
|
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
44
|
};
|
@@ -1,100 +1,177 @@
|
|
1
|
+
/**
|
2
|
+
* @author XiWell
|
3
|
+
* @version 2.0.1
|
4
|
+
* @description 此文件为dva/router自动化文件,无需配置路由,请勿修改!
|
5
|
+
*/
|
6
|
+
|
1
7
|
import React from 'react';
|
2
|
-
import { ConfigProvider
|
3
|
-
import {
|
8
|
+
import { ConfigProvider } from 'antd';
|
9
|
+
import { Route, Router, Switch } from 'dva/router';
|
4
10
|
|
5
11
|
/**
|
6
|
-
* @description
|
7
|
-
* @param
|
12
|
+
* @description 是否匹配页面
|
13
|
+
* @param name {string}
|
14
|
+
* @return {{stat: boolean, param: null}}
|
8
15
|
*/
|
9
|
-
function
|
10
|
-
const
|
11
|
-
|
12
|
-
|
16
|
+
function isParamPage (name) {
|
17
|
+
const result = {
|
18
|
+
stat: false,
|
19
|
+
param: null
|
20
|
+
};
|
21
|
+
if (/^_/.test(name)) {
|
22
|
+
const match = name.replace(/\.js$/, '').split(/_/).filter(item => !!item && item !== 'index');
|
23
|
+
result.stat = match.length !== 0;
|
24
|
+
result.param = match.join('_');
|
25
|
+
}
|
26
|
+
return result;
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @description 首字母转小写
|
31
|
+
* @param value {string}
|
32
|
+
* @return {string}
|
33
|
+
*/
|
34
|
+
function toLowerCase (value) {
|
35
|
+
return `${value[ 0 ].toLowerCase()}${value.substring(1)}`;
|
36
|
+
}
|
13
37
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
38
|
+
/**
|
39
|
+
* @description 获取初始路由集合
|
40
|
+
* @return {{path: string, file: string}[]}
|
41
|
+
*/
|
42
|
+
function getRoutes () {
|
43
|
+
const routes = [];
|
44
|
+
const fileList = require.context('~/pages', true, /\.js$/).keys();
|
45
|
+
for (let i = 0; i < fileList.length; i++) {
|
46
|
+
const route = {};
|
47
|
+
const file = fileList[ i ];
|
48
|
+
const fileSplit = file.split(/\//);
|
49
|
+
const fileName = fileSplit[ fileSplit.length - 1 ];
|
50
|
+
const {
|
51
|
+
stat: fileState,
|
52
|
+
param: fileParam
|
53
|
+
} = isParamPage(fileName);
|
54
|
+
const filePathArray = fileSplit.slice(1, fileSplit.length - 1).map(item => {
|
55
|
+
const {
|
56
|
+
stat,
|
57
|
+
param
|
58
|
+
} = isParamPage(item);
|
59
|
+
return stat
|
60
|
+
? `:${param}`
|
61
|
+
: item;
|
62
|
+
});
|
63
|
+
if (fileState || fileName === 'index.js') {
|
64
|
+
if (filePathArray.length) {
|
65
|
+
const path = filePathArray.map(item => toLowerCase(item)).join('/');
|
66
|
+
route.path = (`/${path}${fileState
|
67
|
+
? `/:${fileParam}`
|
68
|
+
: ''}`);
|
69
|
+
} else {
|
70
|
+
route.path = `/${fileState
|
71
|
+
? `:${fileParam}`
|
72
|
+
: ''}`;
|
26
73
|
}
|
27
|
-
|
28
|
-
|
74
|
+
route.file = file;
|
75
|
+
routes.push(route);
|
76
|
+
}
|
29
77
|
}
|
78
|
+
return routes.reverse();
|
79
|
+
}
|
30
80
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
});
|
81
|
+
/**
|
82
|
+
* @typedef {object} TreeRoutes
|
83
|
+
* @property {string} path
|
84
|
+
* @property {string} file
|
85
|
+
* @property {TreeRoutes[]} children
|
86
|
+
*/
|
46
87
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
88
|
+
/**
|
89
|
+
* @description 优化tree
|
90
|
+
* @param tree {TreeRoutes[]}
|
91
|
+
* @return {TreeRoutes[]}
|
92
|
+
*/
|
93
|
+
function optimizationTree (tree = []) {
|
94
|
+
function deep (array = []) {
|
95
|
+
const inner = [];
|
96
|
+
for (let i = 0; i < array.length; i++) {
|
97
|
+
const item = array[ i ];
|
98
|
+
const newItem = {};
|
99
|
+
newItem.children = item.children.length
|
100
|
+
? deep(item.children)
|
101
|
+
: [];
|
102
|
+
newItem.path = item.path;
|
103
|
+
newItem.Component = require(`~/pages${item.file.replace(/^\./, '')}`).default;
|
104
|
+
inner.push(newItem);
|
105
|
+
}
|
106
|
+
return inner;
|
107
|
+
}
|
108
|
+
|
109
|
+
return deep(tree);
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* @description 将初始routes转换为tree结构
|
114
|
+
* @param routes {{path: string, file: string}[]}
|
115
|
+
* @return {TreeRoutes[]}
|
116
|
+
*/
|
117
|
+
function treeRoutes (routes = []) {
|
118
|
+
const dataSource = [];
|
119
|
+
const indexItem = routes.find(item => item.path === '/');
|
120
|
+
for (let i = 0; i < routes.length; i++) {
|
121
|
+
const route = routes[ i ];
|
122
|
+
if (route.path === '/') {
|
123
|
+
continue;
|
124
|
+
}
|
125
|
+
const pathArray = route.path.split('/').slice(1);
|
126
|
+
route.parentFile = pathArray.length === 1
|
127
|
+
? null
|
128
|
+
: routes[ i - 1 ].file;
|
129
|
+
dataSource.push(route);
|
130
|
+
}
|
131
|
+
if (indexItem) {
|
132
|
+
Object.assign(indexItem, { parentFile: null });
|
133
|
+
dataSource.push(indexItem);
|
134
|
+
}
|
135
|
+
let len;
|
136
|
+
for (let i = 0; len = dataSource.length, i < len; i++) {
|
137
|
+
const arrTemp = [];
|
138
|
+
for (let j = 0; j < dataSource.length; j++) {
|
139
|
+
if (dataSource[ i ].file === dataSource[ j ].parentFile) {
|
140
|
+
dataSource[ i ].children = arrTemp;
|
141
|
+
arrTemp.push(dataSource[ j ]);
|
142
|
+
} else {
|
143
|
+
dataSource[ i ].children = arrTemp;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}
|
147
|
+
const result = [];
|
148
|
+
for (let i = 0; i < dataSource.length; i++) {
|
149
|
+
if (dataSource[ i ].parentFile === null) {
|
150
|
+
result.push(dataSource[ i ]);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
return optimizationTree(result);
|
154
|
+
}
|
155
|
+
|
156
|
+
function RenderRouter (routes = [], inProps = {}) {
|
54
157
|
return (
|
55
|
-
<Router
|
56
|
-
basename={window.__POWERED_BY_QIANKUN__
|
57
|
-
? props.basename
|
58
|
-
: '/'}
|
59
|
-
>
|
158
|
+
<Router history={inProps.history}>
|
60
159
|
<Switch>
|
61
|
-
{
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
/>
|
67
|
-
)}
|
68
|
-
{Entry && (
|
69
|
-
<Route
|
70
|
-
exact
|
71
|
-
path={Entry.path}
|
72
|
-
component={Entry.component}
|
73
|
-
/>
|
74
|
-
)}
|
75
|
-
{Container && (
|
160
|
+
{routes.map(({
|
161
|
+
path,
|
162
|
+
children,
|
163
|
+
Component
|
164
|
+
}, index) => (
|
76
165
|
<Route
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
exact
|
84
|
-
key={key}
|
85
|
-
path={route.path}
|
86
|
-
component={route.component}
|
87
|
-
/>
|
88
|
-
))}
|
89
|
-
</Switch>
|
90
|
-
</ContainerComponent>
|
166
|
+
key={index}
|
167
|
+
path={`${(process.env.app || {}).basename || ''}${path}`}
|
168
|
+
render={props => (
|
169
|
+
<Component {...props}>
|
170
|
+
{RenderRouter(children, inProps)}
|
171
|
+
</Component>
|
91
172
|
)}
|
92
173
|
/>
|
93
|
-
)}
|
94
|
-
<Route
|
95
|
-
path="*"
|
96
|
-
component={() => <Result title="非常抱歉您访问的地址暂时无法显示,请确认后再试!" />}
|
97
|
-
/>
|
174
|
+
))}
|
98
175
|
</Switch>
|
99
176
|
</Router>
|
100
177
|
);
|
@@ -103,22 +180,19 @@ function ReactRouterScanner (props) {
|
|
103
180
|
/**
|
104
181
|
* @description 自动化路由组件
|
105
182
|
* @param app {object}
|
106
|
-
* @param
|
183
|
+
* @param history {history}
|
107
184
|
* @return {JSX.Element}
|
108
185
|
*/
|
109
186
|
export const AutomaticRouter = ({
|
110
187
|
app,
|
111
|
-
|
188
|
+
history
|
112
189
|
}) => {
|
113
190
|
return (
|
114
|
-
<ConfigProvider
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
app={app}
|
120
|
-
basename={basename}
|
121
|
-
/>
|
191
|
+
<ConfigProvider locale={require('antd/lib/locale/zh_CN').default}>
|
192
|
+
{RenderRouter(treeRoutes(getRoutes()), {
|
193
|
+
app,
|
194
|
+
history
|
195
|
+
})}
|
122
196
|
</ConfigProvider>
|
123
197
|
);
|
124
198
|
};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"projectType": "micro-spa",
|
3
|
+
"installTarget": "node_modules",
|
4
|
+
"installResources": [
|
5
|
+
"common",
|
6
|
+
"react-admin-component"
|
7
|
+
],
|
8
|
+
"environment": {
|
9
|
+
"development": {
|
10
|
+
"API_HOSE": ""
|
11
|
+
},
|
12
|
+
"test": {
|
13
|
+
"API_HOSE": ""
|
14
|
+
},
|
15
|
+
"release": {
|
16
|
+
"API_HOSE": ""
|
17
|
+
},
|
18
|
+
"production": {
|
19
|
+
"API_HOSE": ""
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"contextInject": {},
|
23
|
+
"windowInject": {
|
24
|
+
"title": "JJB Micro APP"
|
25
|
+
},
|
26
|
+
"server": {
|
27
|
+
"port": "8088",
|
28
|
+
"host": "127.0.0.1"
|
29
|
+
},
|
30
|
+
"framework": {
|
31
|
+
"antd": {
|
32
|
+
"link-color": "red",
|
33
|
+
"primary-color": "red",
|
34
|
+
"border-radius-base": "2px"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
const { hasEnvironment } = require('./utils');
|
2
|
+
|
3
|
+
if (!hasEnvironment()) {
|
4
|
+
throw Error('jjb.script[build]: 启动build需要提供NODE_ENV变量,请确认你所运行的脚本是否正确?');
|
5
|
+
}
|
6
|
+
|
7
|
+
require('webpack')(require('./config')('production').webpack).run(err => {
|
8
|
+
if (!err) {
|
9
|
+
console.log('项目打包完成!');
|
10
|
+
}
|
11
|
+
});
|