-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
43 lines (42 loc) · 1.19 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fs = require(`fs`)
const util = require(`./util.js`)
new Promise(async () => {
const cliArg = util.parseArgv()
const [arg1] = process.argv.slice(2)
if([undefined, `--help`, `-h`].includes(arg1)) {
console.log(fs.readFileSync(`${__dirname}/readme.md`, `utf8`))
process.exit()
}
try {
const file = (cliArg.file || ``).split(`,`).filter(item => fs.existsSync(item))
const ignore = cliArg.noIgnore ? [] : cliArg.ignore ? cliArg.ignore.split(`,`).filter(item => item.trim()) : undefined
arg1 === `link` && await util.linkDir({
...cliArg,
file,
ignore,
})
arg1 === `copy` && await util.copy({
...cliArg,
file,
ignore,
})
arg1 === `zip` && await util.zip({
...cliArg,
file,
ignore,
})
arg1 === `sdelete` && await util.sdelete({
...cliArg,
file,
})
arg1 === `crush` && await util.crush({
...cliArg,
file,
})
arg1 === `size` && (file.length ? file : [process.cwd()]).forEach(item => util.treeSize(item))
arg1 === `handle` && (file.length ? file : [process.cwd()]).forEach(item => util.handleInfo(item))
} catch (error) {
console.info(error)
}
process.exit()
})