jjb-cmd 1.0.13 → 1.0.14
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 +4 -37
- package/package.json +1 -1
- package/src/cli.rm-rf.js +86 -0
package/bin/command.js
CHANGED
@@ -1,16 +1,10 @@
|
|
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');
|
14
8
|
const MergeScripts = require('../src/cli.merge.js');
|
15
9
|
|
16
10
|
commander.command('v').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,38 +36,11 @@ commander.command('pull2 -- <文件夹名称必填。>').description('-- 文件
|
|
42
36
|
cliScripts2(res);
|
43
37
|
});
|
44
38
|
|
39
|
+
// rm-rf 命令
|
45
40
|
commander.command('rm-rf').description('-- 删除全部').action(res => {
|
46
|
-
|
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
|
-
});
|
41
|
+
cliScripts4(res);
|
57
42
|
});
|
58
43
|
|
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
|
-
|
77
44
|
// install 安装
|
78
45
|
commander.command('install').description('-- 安装').action(res => {
|
79
46
|
cliScripts3(res);
|
package/package.json
CHANGED
package/src/cli.rm-rf.js
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
const path = require('path');
|
3
|
+
const readline = require('readline');
|
4
|
+
const ProgressBar = require('./progress-bar');
|
5
|
+
const io = readline.createInterface({
|
6
|
+
input: process.stdin,
|
7
|
+
output: process.stdout
|
8
|
+
});
|
9
|
+
const progress = new ProgressBar('删除进度', 50);
|
10
|
+
|
11
|
+
let f_total = 0;
|
12
|
+
let f_number = 0;
|
13
|
+
|
14
|
+
module.exports = function () {
|
15
|
+
const root_path = path.resolve('./');
|
16
|
+
|
17
|
+
io.question('是否确认删除?删除后不可恢复![y/n]:', function (answer) {
|
18
|
+
if (answer.trim() === 'y') {
|
19
|
+
console.log('正在计算项目数,请稍等...');
|
20
|
+
setTimeout(() => {
|
21
|
+
scanner(root_path);
|
22
|
+
console.log(`计算完成共计[${f_total}]项目。`);
|
23
|
+
setTimeout(() => {
|
24
|
+
console.clear();
|
25
|
+
exec(root_path);
|
26
|
+
setTimeout(() => {
|
27
|
+
console.log('删除完成。');
|
28
|
+
console.clear();
|
29
|
+
process.exit(0);
|
30
|
+
}, 500);
|
31
|
+
}, 500);
|
32
|
+
}, 500);
|
33
|
+
} else if (answer.trim() === 'n') {
|
34
|
+
console.log('取消删除。');
|
35
|
+
} else {
|
36
|
+
console.log('无效操作。');
|
37
|
+
}
|
38
|
+
});
|
39
|
+
};
|
40
|
+
|
41
|
+
function exec (path) {
|
42
|
+
if (fs.existsSync(path)) {
|
43
|
+
const list = fs.readdirSync(path);
|
44
|
+
for (let i = 0; i < list.length; i++) {
|
45
|
+
const item = list[ i ];
|
46
|
+
const vPath = `${path}/${item}`;
|
47
|
+
try {
|
48
|
+
if (fs.statSync(vPath).isDirectory()) {
|
49
|
+
exec(vPath);
|
50
|
+
fs.rmdirSync(vPath, { recursive: true });
|
51
|
+
f_number = f_number + 1;
|
52
|
+
// console.log('删除文件夹:' + vPath);
|
53
|
+
} else {
|
54
|
+
fs.unlinkSync(vPath);
|
55
|
+
f_number = f_number + 1;
|
56
|
+
// console.log('删除文件:' + vPath);
|
57
|
+
}
|
58
|
+
progress.render({
|
59
|
+
completed: f_number,
|
60
|
+
total: f_total
|
61
|
+
});
|
62
|
+
} catch (e) {
|
63
|
+
// console.log('删除异常:' + vPath);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
function scanner (path) {
|
70
|
+
if (fs.existsSync(path)) {
|
71
|
+
const list = fs.readdirSync(path);
|
72
|
+
for (let i = 0; i < list.length; i++) {
|
73
|
+
const item = list[ i ];
|
74
|
+
const vPath = `${path}/${item}`;
|
75
|
+
try {
|
76
|
+
if (fs.statSync(vPath).isDirectory()) {
|
77
|
+
scanner(vPath);
|
78
|
+
f_total = f_total + 1;
|
79
|
+
} else {
|
80
|
+
f_total = f_total + 1;
|
81
|
+
}
|
82
|
+
} catch (e) {
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|