jjb-cmd 1.0.0
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/.idea/jjb-cli.iml +12 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/LICENSE +21 -0
- package/bin/command.js +28 -0
- package/package.json +19 -0
- package/src/cli.pull.js +88 -0
- package/src/util.js +103 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="WEB_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager">
|
4
|
+
<content url="file://$MODULE_DIR$">
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
8
|
+
</content>
|
9
|
+
<orderEntry type="inheritedJdk" />
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
11
|
+
</component>
|
12
|
+
</module>
|
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 jjb-front-team <https://www.cqjjb.cn>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/bin/command.js
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#! /usr/bin/env node
|
2
|
+
|
3
|
+
const commander = require('commander');
|
4
|
+
const cliScripts = require('../src/cli.pull.js');
|
5
|
+
|
6
|
+
commander.command('v').description('-- 查看版本').action(() => {
|
7
|
+
console.log('当前版本 v1.0.0');
|
8
|
+
});
|
9
|
+
|
10
|
+
commander.command('help').description('-- 帮助').action(() => {
|
11
|
+
console.log('使用方法:');
|
12
|
+
console.log('1.jjb-cli v -- 查看版本。');
|
13
|
+
console.log('2.jjb-cli help -- 帮助。');
|
14
|
+
console.log('3.jjb-cli view res -- 预览资源。');
|
15
|
+
console.log('4.jjb-cli [actionName (有效值 pull)] [...args] -- 基础功能。');
|
16
|
+
});
|
17
|
+
|
18
|
+
commander.command('view res').description('-- 预览资源').action(() => {
|
19
|
+
console.log('当前可资源:');
|
20
|
+
console.log('[common, admin-components]');
|
21
|
+
});
|
22
|
+
|
23
|
+
// pull 命令
|
24
|
+
commander.command('pull -- <文件夹名称必填。>').description('-- 文件名称').action(res => {
|
25
|
+
cliScripts(res);
|
26
|
+
});
|
27
|
+
|
28
|
+
commander.parse(process.argv);
|
package/package.json
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"name": "jjb-cmd",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "node bin/command.js help"
|
8
|
+
},
|
9
|
+
"bin": {
|
10
|
+
"jjb-cli": "bin/command.js"
|
11
|
+
},
|
12
|
+
"author": "jjb-front-team",
|
13
|
+
"license": "MIT",
|
14
|
+
"dependencies": {
|
15
|
+
"request": "2.88.2",
|
16
|
+
"commander": "1.3.2",
|
17
|
+
"compressing": "^1.5.1"
|
18
|
+
}
|
19
|
+
}
|
package/src/cli.pull.js
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const fs = require('fs');
|
4
|
+
const os = require('os');
|
5
|
+
const path = require('path');
|
6
|
+
const utils = require('./util');
|
7
|
+
const request = require('request');
|
8
|
+
const compressing = require('compressing');
|
9
|
+
|
10
|
+
//临时存放目录
|
11
|
+
const GIT_TEMP_DIR = 'jjbAssembly';
|
12
|
+
//GIT仓库
|
13
|
+
const GIT_HOST = 'http://192.168.1.242:10985';
|
14
|
+
//项目列表,后期可存库
|
15
|
+
const CLOUD_PROJECT = {
|
16
|
+
'common': {
|
17
|
+
token: 'G4HJRsHr9D7Ssmixegw2',
|
18
|
+
projectId: 279
|
19
|
+
},
|
20
|
+
'admin-components': {
|
21
|
+
token: '9S83hVV4PKDbsPY9yT5D',
|
22
|
+
projectId: 280
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
module.exports = input => {
|
27
|
+
const dirName = input;
|
28
|
+
const currDir = path.resolve('./');
|
29
|
+
try {
|
30
|
+
if (fs.statSync(currDir + '\\src')) {
|
31
|
+
const srcDir = currDir + '\\src';
|
32
|
+
const cloudObj = CLOUD_PROJECT[ dirName ] || undefined;
|
33
|
+
if (cloudObj) {
|
34
|
+
const tmpDir = os.tmpdir();
|
35
|
+
const dirPath = tmpDir + `/${GIT_TEMP_DIR}/${dirName}.zip`;
|
36
|
+
const dirUnzip = `${tmpDir}/${GIT_TEMP_DIR}/unzip/`;
|
37
|
+
utils.DeleteDirAllFile(`${tmpDir}/${GIT_TEMP_DIR}`, () => {
|
38
|
+
fs.mkdirSync(`${tmpDir}/${GIT_TEMP_DIR}`);
|
39
|
+
let stream = fs.createWriteStream(dirPath);
|
40
|
+
request(`${GIT_HOST}/api/v4/projects/${cloudObj.projectId}/repository/archive.zip?private_token=${cloudObj.token}&ref=master`).pipe(stream)
|
41
|
+
.on('close', () => {
|
42
|
+
fs.mkdirSync(dirUnzip);
|
43
|
+
compressing.zip.uncompress(dirPath, dirUnzip)
|
44
|
+
.then(() => {
|
45
|
+
setTimeout(() => {
|
46
|
+
const srcAll = fs.readdirSync(dirUnzip);
|
47
|
+
srcAll.forEach(dirName => {
|
48
|
+
if (dirName.indexOf('-master-') !== -1) {
|
49
|
+
const nowName = dirName.split('-')[ 0 ];
|
50
|
+
const nowPath = srcDir + '\\' + nowName;
|
51
|
+
utils.DeleteDirAllFile(nowPath, () => {
|
52
|
+
fs.mkdirSync(nowPath);
|
53
|
+
console.log(nowPath);
|
54
|
+
utils.CopyFolder(dirUnzip + dirName, nowPath);
|
55
|
+
setTimeout(() => {
|
56
|
+
const isMutilate = fs.existsSync(srcDir + '\\' + 'application');
|
57
|
+
if (!isMutilate) {
|
58
|
+
const commonToolsPath = srcDir + '\\' + 'common\\tools\\index.js';
|
59
|
+
const commonWebsitePath = srcDir + '\\' + 'common\\website\\index.js';
|
60
|
+
let commonToolsFile = fs.readFileSync(commonToolsPath).toString();
|
61
|
+
let commonWebsiteFile = fs.readFileSync(commonWebsitePath).toString();
|
62
|
+
commonToolsFile = commonToolsFile.replace('return __planA();', 'return process.env;');
|
63
|
+
commonWebsiteFile = commonWebsiteFile.replace(/const\srelation\s=\srequire\(`\/src\/application\/\${mainMenu.code}\/enumerate\/menu`\)\.default;/g, 'const relation = require(`/src/enumerate/menu`).default;');
|
64
|
+
fs.writeFileSync(commonToolsPath, commonToolsFile);
|
65
|
+
fs.writeFileSync(commonWebsitePath, commonWebsiteFile);
|
66
|
+
} else {
|
67
|
+
fs.readdirSync(srcDir + '\\' + 'common\\dva\\automatic').forEach(p => {
|
68
|
+
fs.unlinkSync(srcDir + '\\' + 'common\\dva\\automatic\\' + p);
|
69
|
+
});
|
70
|
+
fs.rmdirSync(srcDir + '\\' + 'common\\dva\\automatic');
|
71
|
+
}
|
72
|
+
}, 1000);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
});
|
76
|
+
console.log(dirName + '文件下载完毕');
|
77
|
+
}, 2000);
|
78
|
+
});
|
79
|
+
});
|
80
|
+
});
|
81
|
+
} else {
|
82
|
+
console.error('【Error】: 未获取到项目 ' + dirName);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
} catch (e) {
|
86
|
+
console.error('【Error】: 当前目录不存在src子目录,无法完成pull操作。');
|
87
|
+
}
|
88
|
+
};
|
package/src/util.js
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const fs = require('fs');
|
4
|
+
const path = require('path');
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @description 清空当前目录
|
8
|
+
* @param filePath
|
9
|
+
* @param callback
|
10
|
+
* @constructor
|
11
|
+
*/
|
12
|
+
exports.DeleteDirAllFile = (filePath, callback) => {
|
13
|
+
let files = [];
|
14
|
+
const that = this;
|
15
|
+
if(fs.existsSync(filePath)) {
|
16
|
+
files = fs.readdirSync(filePath);
|
17
|
+
files.forEach(function(file, index) {
|
18
|
+
let curPath = filePath + "/" + file;
|
19
|
+
if(fs.statSync(curPath).isDirectory()) {
|
20
|
+
that.DeleteDirAllFile(curPath);
|
21
|
+
} else {
|
22
|
+
fs.unlinkSync(curPath);
|
23
|
+
}
|
24
|
+
});
|
25
|
+
fs.rmdirSync(filePath);
|
26
|
+
callback && callback();
|
27
|
+
} else {
|
28
|
+
callback && callback();
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @description 复制文件夹及子目录文件
|
34
|
+
* @param srcDir
|
35
|
+
* @param tarDir
|
36
|
+
* @param cb
|
37
|
+
*/
|
38
|
+
exports.CopyFolder = (srcDir, tarDir, cb) => {
|
39
|
+
const that = this;
|
40
|
+
fs.readdir(srcDir, function(err, files) {
|
41
|
+
|
42
|
+
let count = 0
|
43
|
+
const checkEnd = function() {
|
44
|
+
++count === files.length && cb && cb()
|
45
|
+
}
|
46
|
+
|
47
|
+
if (err) {
|
48
|
+
checkEnd()
|
49
|
+
return
|
50
|
+
}
|
51
|
+
|
52
|
+
files.forEach(function(file) {
|
53
|
+
const srcPath = path.join(srcDir, file)
|
54
|
+
const tarPath = path.join(tarDir, file)
|
55
|
+
|
56
|
+
fs.stat(srcPath, function(err, stats) {
|
57
|
+
if (stats.isDirectory()) {
|
58
|
+
fs.mkdir(tarPath, function(err) {
|
59
|
+
if (err) {
|
60
|
+
console.log(err)
|
61
|
+
return
|
62
|
+
}
|
63
|
+
|
64
|
+
that.CopyFolder(srcPath, tarPath, checkEnd)
|
65
|
+
})
|
66
|
+
} else {
|
67
|
+
that.CopyFile(srcPath, tarPath, checkEnd)
|
68
|
+
}
|
69
|
+
})
|
70
|
+
})
|
71
|
+
//为空时直接回调
|
72
|
+
files.length === 0 && cb && cb()
|
73
|
+
})
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* @description 复制文件
|
78
|
+
* @param srcPath
|
79
|
+
* @param tarPath
|
80
|
+
* @param cb
|
81
|
+
*/
|
82
|
+
exports.CopyFile = (srcPath, tarPath, cb) => {
|
83
|
+
const rs = fs.createReadStream(srcPath)
|
84
|
+
rs.on('error', function(err) {
|
85
|
+
if (err) {
|
86
|
+
console.log('read error', srcPath)
|
87
|
+
}
|
88
|
+
cb && cb(err)
|
89
|
+
})
|
90
|
+
|
91
|
+
const ws = fs.createWriteStream(tarPath)
|
92
|
+
ws.on('error', function(err) {
|
93
|
+
if (err) {
|
94
|
+
console.log('write error', tarPath)
|
95
|
+
}
|
96
|
+
cb && cb(err)
|
97
|
+
})
|
98
|
+
ws.on('close', function(ex) {
|
99
|
+
cb && cb(ex)
|
100
|
+
})
|
101
|
+
|
102
|
+
rs.pipe(ws)
|
103
|
+
}
|