-
Notifications
You must be signed in to change notification settings - Fork 2
/
ucdn
executable file
·84 lines (79 loc) · 1.76 KB
/
ucdn
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
const yargs = require("yargs")
const pkg = require("./package")
const utils = require("./utils")
const upload = require("./upload")
const yargsOptions = {
config: {
alias: "c",
describe: "path to config file",
default: "./ucdn.yml",
type: "string",
},
region: {
alias: "r",
describe: "AWS geographical area",
default: "eu-west-1",
type: "string",
},
dir: {
alias: "d",
describe: "assets directory",
default: "dist/",
type: "string",
},
bucket: {
alias: "b",
describe: "AWS bucket for upload",
type: "string",
default: null,
},
exclude: {
alias: "e",
describe: "excluded extenstions",
default: ["html", "gz"],
type: "array",
},
accessKeyId: {
alias: "access-key-id",
describe: "AWS access key ID",
type: "string",
demand: true,
},
secretAccessKey: {
alias: "secret-access-key",
describe: "AWS secret access key",
type: "string",
demand: true,
},
"config-key": {
alias: "C",
describe: "root config key",
},
targetDir: {
alias: "target-dir",
describe: "AWS bucket target directory",
type: "string",
default: "",
},
}
yargs
.env("UCDN")
.command("upload", "upload assets to AWS S3", {}, upload)
.options(yargsOptions)
.demandCommand(1)
.help()
.version(pkg.version)
.strict()
.middleware(argv => {
const config = utils.loadYamlFile(argv.config)
const configObject = argv.C ? (config[argv.C] || {}) : config
Object
.entries(configObject)
.filter(([_, value]) => value !== null)
.forEach(([key, value]) => {
// eslint-disable-next-line no-param-reassign
if (argv[key] === yargsOptions[key].default) argv[key] = value
})
}, true)
.parse()