Skip to content

Commit 581ccbf

Browse files
committed
feat: First commit
1 parent 994a721 commit 581ccbf

20 files changed

+1609
-0
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
# Lock files
6+
package-lock.json
7+
8+
# Log files
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Editor directories and files
14+
.idea
15+
.vscode
16+
*.suo
17+
*.ntvs*
18+
*.njsproj
19+
*.sln
20+
*.sw*

README.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# 七牛云操作工具
2+
> 基于 [qiniu](https://github.com/qiniu/nodejs-sdk) 封装
3+
4+
## 安装
5+
6+
从 npm 安装
7+
8+
```markdown
9+
$ npm install qiniu-shell --save-dev
10+
```
11+
12+
## 功能
13+
- [上传](#上传)
14+
- [下载](#下载)
15+
- [删除](#删除)
16+
- [文件刷新](#文件刷新)
17+
- [目录刷新](#目录刷新)
18+
- [文件预取](#文件预取)
19+
- [查看帮助](#查看帮助)
20+
21+
---
22+
- **<a id="上传">上传</a>**
23+
```markdown
24+
$ cshell upload -a accessKey -s secretKey -b bucket -p prefix/ -o originDirectoryPath -f -z huan
25+
```
26+
上传originDirectoryPath目录下文件到bucket下的prefix目录下
27+
28+
**options:**
29+
```markdown
30+
-a, --accessKey [value] AccessKey
31+
-s, --secretKey [value] SecretKey
32+
-b, --bucket [value] Bucket
33+
-p, --prefix [value] Prefix of files
34+
-f, --force Whether to overwrite upload.
35+
-z --zone [value] Online zone. one of "huad"、"huab"、"huan"、"beim"、"z0"、"z1"、"z2"、"na0"
36+
-o, --originDirectoryPath [value] Directory's path of the files to upload, default is "dist"
37+
-h, --help output usage information
38+
```
39+
40+
注:"huad"、"z0"为华东;"huab"、"z1"为华北;"huan"、"z2"为华南;"beim"、"na0"为北美
41+
42+
---
43+
- **<a id="下载">下载</a>**
44+
```markdown
45+
$ cshell download -a accessKey -s secretKey -b bucket -p prefix -o originDirectoryPath -d publicDomain
46+
```
47+
下载publicDomain或privateDomain域名下prefix开头的文件到originDirectoryPath目录
48+
49+
**options:**
50+
```markdown
51+
-a, --accessKey [value] AccessKey
52+
-s, --secretKey [value] SecretKey
53+
-b, --bucket [value] Bucket
54+
-d, --publicDomain [value] Public domain of bucket
55+
--privateDomain [value] Private domain of bucket. If set this, "-d" will be useless
56+
-p, --prefix [value] Prefix of files
57+
-o, --outputDirectoryPath [value] The path of the downloaded file, default is "dist"
58+
-h, --help output usage information
59+
```
60+
61+
---
62+
- **<a id="删除">删除</a>**
63+
```markdown
64+
$ cshell delete -a accessKey -s secretKey -b bucket -p prefix
65+
```
66+
删除bucket下以prefix开头的文件
67+
68+
**options:**
69+
70+
```markdown
71+
-a, --accessKey [value] AccessKey
72+
-s, --secretKey [value] SecretKey
73+
-b, --bucket [value] Bucket
74+
-p, --prefix [value] Prefix of files. If don't set it, all files of buckt will be deleted.
75+
-h, --help output usage information
76+
```
77+
78+
---
79+
- **<a id="文件刷新">文件刷新</a>**
80+
81+
1.使用cmd
82+
```markdown
83+
$ cshell refresh -a accessKey -s secretKey -u https://xxx/demo/a.js,https://xxx/demo/b.js
84+
```
85+
<p>
86+
刷新https://xxx/demo/a.js, https://xxx/demo/b.js 两个文件
87+
</p>
88+
89+
90+
2.使用配置文件
91+
```markdown
92+
$ cshell refresh -a accessKey -s secretKey -c ./refreshFiles.js
93+
```
94+
95+
refreshFiles.js:(CommonJs;String or Array)
96+
```js
97+
module.exports = ['https://xxx/demo/a.js','https://xxx/demo/b.js' ]
98+
```
99+
100+
<p>
101+
刷新https://xxx/demo/a.js, https://xxx/demo/b.js 两个文件.
102+
</p>
103+
104+
105+
**options:**
106+
107+
```markdown
108+
-a, --accessKey [value] AccessKey
109+
-s, --secretKey [value] SecretKey
110+
-u, --urls [value] Urls of refresh files. Split by ","
111+
-c, --configFile [path] Path of refresh urls file. If set this, "-u" will be useless
112+
-h, --help output usage information
113+
```
114+
115+
---
116+
- **<a id="目录刷新">目录刷新</a>**
117+
118+
操作同文件刷新,命令为: refreshDir
119+
120+
---
121+
- **<a id="文件预取">文件预取</a>**
122+
123+
操作同文件刷新,命令为: prefetch
124+
125+
---
126+
- **<a id="查看帮助">查看帮助</a>**
127+
128+
```markdown
129+
$ cshell -h
130+
$ cshell [command] -h
131+
```

bin/cshell-delete.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
const program = require("commander");
3+
const colors = require("colors");
4+
const { log, isEmpty } = require("../lib/utils");
5+
6+
program
7+
.usage("[option]")
8+
.option("-a, --accessKey [value]", "AccessKey")
9+
.option("-s, --secretKey [value]", "SecretKey")
10+
.option("-b, --bucket [value]", "Bucket")
11+
.option("-p, --prefix [value]", "Prefix of files. If don't set it, all files of buckt will be deleted.")
12+
.parse(process.argv);
13+
14+
if (isEmpty(program.accessKey)) {
15+
log.failAndExit("AccessKey is null");
16+
}
17+
if (isEmpty(program.secretKey)) {
18+
log.failAndExit("SecretKey is null");
19+
}
20+
if (isEmpty(program.bucket)) {
21+
log.failAndExit("Bucket is null");
22+
}
23+
24+
require("../lib/scripts/delete.js")(program);

bin/cshell-download.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
const program = require("commander");
3+
const colors = require("colors");
4+
const { log, isEmpty } = require("../lib/utils");
5+
6+
program
7+
.usage("[option]")
8+
.option("-a, --accessKey [value]", "AccessKey")
9+
.option("-s, --secretKey [value]", "SecretKey")
10+
.option("-b, --bucket [value]", "Bucket")
11+
.option("-d, --publicDomain [value]", "Public domain of bucket")
12+
.option("--privateDomain [value]", 'Private domain of bucket. If set this, "-d" will be useless')
13+
.option("-p, --prefix [value]", "Prefix of files")
14+
.option(
15+
"-o, --outputDirectoryPath [value]",
16+
'The path of the downloaded file, default is "dist"'
17+
)
18+
.parse(process.argv);
19+
20+
if (isEmpty(program.accessKey)) {
21+
log.failAndExit("AccessKey is null");
22+
}
23+
if (isEmpty(program.secretKey)) {
24+
log.failAndExit("SecretKey is null");
25+
}
26+
if (isEmpty(program.bucket)) {
27+
log.failAndExit("Bucket is null");
28+
}
29+
if (isEmpty(program.publicDomain) && isEmpty(program.privateDomain)) {
30+
log.failAndExit(
31+
"You should set at least one parameter in publicDomain and privateDomain"
32+
);
33+
}
34+
35+
require("../lib/scripts/download.js")(program);

bin/cshell-prefetch.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
const program = require("commander");
3+
const colors = require("colors");
4+
const { log, isEmpty } = require("../lib/utils");
5+
6+
program
7+
.usage("[option]")
8+
.option("-a, --accessKey [value]", "AccessKey")
9+
.option("-s, --secretKey [value]", "SecretKey")
10+
.option("-u, --urls [value]", 'Urls of prefetch files. Split by ","')
11+
.option(
12+
"-c, --configFile [value]",
13+
'Path of prefetch urls file. If set this, "-u" will be useless'
14+
)
15+
.parse(process.argv);
16+
17+
if (isEmpty(program.accessKey)) {
18+
log.failAndExit("AccessKey is null");
19+
}
20+
if (isEmpty(program.secretKey)) {
21+
log.failAndExit("SecretKey is null");
22+
}
23+
if (isEmpty(program.urls) && isEmpty(program.config)) {
24+
log.failAndExit("You should set at least one parameter in urls and config");
25+
}
26+
27+
require("../lib/scripts/prefetch.js")(program);

bin/cshell-refresh.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
const program = require("commander");
3+
const colors = require("colors");
4+
const { log, isEmpty } = require("../lib/utils");
5+
6+
program
7+
.usage("[option]")
8+
.option("-a, --accessKey [value]", "AccessKey")
9+
.option("-s, --secretKey [value]", "SecretKey")
10+
.option("-u, --urls [value]", 'Urls of refresh files. Split by ","')
11+
.option(
12+
"-c, --configFile [path]",
13+
'Path of refresh urls file. If set this, "-u" will be useless'
14+
)
15+
.parse(process.argv);
16+
17+
if (isEmpty(program.accessKey)) {
18+
log.failAndExit("AccessKey is null");
19+
}
20+
if (isEmpty(program.secretKey)) {
21+
log.failAndExit("SecretKey is null");
22+
}
23+
if (isEmpty(program.urls) && isEmpty(program.configFile)) {
24+
log.failAndExit("You should set at least one parameter in urls and config");
25+
}
26+
27+
require("../lib/scripts/refresh.js")(program);

bin/cshell-refreshDir.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
const program = require("commander");
3+
const colors = require("colors");
4+
const { log, isEmpty } = require("../lib/utils");
5+
6+
program
7+
.usage("[option]")
8+
.option("-a, --accessKey [value]", "AccessKey")
9+
.option("-s, --secretKey [value]", "SecretKey")
10+
.option("-u, --urls [value]", 'Urls of refresh directory. Split by ","')
11+
.option(
12+
"-c, --configFile [path]",
13+
'Path of refresh directory file. If set this, "-u" will be useless'
14+
)
15+
.parse(process.argv);
16+
17+
if (isEmpty(program.accessKey)) {
18+
log.failAndExit("AccessKey is null");
19+
}
20+
if (isEmpty(program.secretKey)) {
21+
log.failAndExit("SecretKey is null");
22+
}
23+
if (isEmpty(program.urls) && isEmpty(program.configFile)) {
24+
log.failAndExit("You should set at least one parameter in urls and config");
25+
}
26+
27+
require("../lib/scripts/refreshDir.js")(program);

bin/cshell-upload.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
const program = require("commander");
3+
const colors = require("colors");
4+
const { log, isEmpty } = require("../lib/utils");
5+
6+
program
7+
.usage("[option]")
8+
.option("-a, --accessKey [value]", "AccessKey")
9+
.option("-s, --secretKey [value]", "SecretKey")
10+
.option("-b, --bucket [value]", "Bucket")
11+
.option("-p, --prefix [value]", "Prefix of files")
12+
.option("-f, --force", "Whether to overwrite upload.")
13+
.option(
14+
"-z --zone [value]",
15+
'Online zone. one of "huad"、"huab"、"huan"、"beim"、"z0"、"z1"、"z2"、"na0"'
16+
)
17+
.option(
18+
"-o, --originDirectoryPath [value]",
19+
'Directory\'s path of the files to upload, default is "dist"'
20+
)
21+
.parse(process.argv);
22+
23+
if (isEmpty(program.accessKey)) {
24+
log.failAndExit("AccessKey is null");
25+
}
26+
if (isEmpty(program.secretKey)) {
27+
log.failAndExit("SecretKey is null");
28+
}
29+
if (isEmpty(program.bucket)) {
30+
log.failAndExit("Bucket is null");
31+
}
32+
33+
require("../lib/scripts/upload.js")(program);

bin/cshell.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
var program = require("commander");
3+
var colors = require("colors");
4+
5+
program
6+
.version("2.0.3")
7+
.usage("[command] [option]")
8+
.command("upload", "upload files")
9+
.command("download", "download files")
10+
.command("refresh", "refresh files")
11+
.command("refreshDir", "refresh directory")
12+
.command("prefetch", "refresh files")
13+
.command("delete", "delete files of the bucket");
14+
15+
program.parse(process.argv);
16+
17+
if (
18+
["upload", "download", "delete", "refresh", "refreshDir", "prefetch"].indexOf(
19+
program.args[0]
20+
) === -1
21+
) {
22+
console.log(
23+
colors.red(
24+
"expect command be upload、download、refresh or delete, but received " +
25+
program.args[0]
26+
)
27+
);
28+
}

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports=require('./lib')

0 commit comments

Comments
 (0)