jjb-cmd 1.0.12 → 1.0.13
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 +41 -1
- package/package.json +1 -1
package/bin/command.js
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
#! /usr/bin/env node
|
2
2
|
|
3
|
+
const fs = require('fs');
|
4
|
+
const path = require('path');
|
5
|
+
const readline = require('readline');
|
3
6
|
const commander = require('commander');
|
7
|
+
const io = readline.createInterface({
|
8
|
+
input: process.stdin,
|
9
|
+
output: process.stdout
|
10
|
+
});
|
4
11
|
const cliScripts = require('../src/cli.pull.js');
|
5
12
|
const cliScripts2 = require('../src/cli.pull2.js');
|
6
13
|
const cliScripts3 = require('../src/cli.install/index.js');
|
7
14
|
const MergeScripts = require('../src/cli.merge.js');
|
8
15
|
|
9
16
|
commander.command('v').description('-- 查看版本').action(() => {
|
10
|
-
|
17
|
+
const package = JSON.parse(fs.readFileSync(path.resolve('./package.json'), 'utf-8').toString());
|
18
|
+
console.log(`当前版本 ${package.version}`)
|
11
19
|
});
|
12
20
|
|
13
21
|
commander.command('help').description('-- 帮助').action(() => {
|
@@ -34,6 +42,38 @@ commander.command('pull2 -- <文件夹名称必填。>').description('-- 文件
|
|
34
42
|
cliScripts2(res);
|
35
43
|
});
|
36
44
|
|
45
|
+
commander.command('rm-rf').description('-- 删除全部').action(res => {
|
46
|
+
io.question('是否确认删除?删除后不可恢复![y/n]:', function (answer) {
|
47
|
+
if (answer.trim() === 'y') {
|
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
|
+
});
|
57
|
+
});
|
58
|
+
|
59
|
+
function exec (path) {
|
60
|
+
if (fs.existsSync(path)) {
|
61
|
+
const list = fs.readdirSync(path);
|
62
|
+
for (let i = 0; i < list.length; i++) {
|
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
|
+
};
|
76
|
+
|
37
77
|
// install 安装
|
38
78
|
commander.command('install').description('-- 安装').action(res => {
|
39
79
|
cliScripts3(res);
|