-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (44 loc) · 1.06 KB
/
index.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
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
const yargs = require('yargs').option('r', {
alias: 'random',
default: true,
describe: 'Use random file names',
type: 'boolean',
});
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const Upload = require('./lib/Upload');
const files = yargs.argv._;
const fileList = [];
const useRandomName = yargs.argv.random;
files.forEach((file) => {
const filePath = path.resolve(process.cwd(), file);
if (fs.existsSync(filePath)) {
fileList.push({
fileName: path.basename(file),
filePath,
});
}
});
if (fileList.length === 0) {
console.log(chalk.yellowBright('这里没有文件可以上传哦!'));
process.exit();
}
console.log(chalk.blueBright('准备上传的文件有:'));
fileList.forEach(({ filePath }) => {
console.log(filePath);
});
// 空行
console.log('');
const upload = new Upload({
random: useRandomName,
});
upload
.uploadFiles(fileList)
.then(() => {
console.log(chalk.greenBright('全部文件上传成功!'));
})
.catch(() => {
process.exit(-1);
});