This repository has been archived by the owner on Oct 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·59 lines (46 loc) · 1.55 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
var ghauth = require('ghauth')
var awsauth = require('awsauth')
var minimist = require('minimist')
var githubToS3 = require('./')
var argv = minimist(process.argv)
if (argv._.length < 4) {
console.error('Usage: github-to-s3 username/project bucket[/prefix]? [options]')
console.error()
console.error(' --install, -i to set install command [npm install]')
console.error(' --build, -b to set build command [npm run build]')
console.error(' --checkout, -c to set the tag to use [master]')
console.error(' --folder, -f to set the folder to upload [.]')
console.error()
process.exit(1)
}
var bucket = argv._[3]
var repo = argv._[2]
var prefix = ''
if (bucket.indexOf('/') > -1) {
prefix = bucket.split('/')[1]
bucket = bucket.split('/')[0]
}
var onerror = function(err) {
if (err) throw err
}
ghauth({configName: 'github-to-s3', scopes:['repo'], note:'This is for github-to-s3'}, function(err, github) {
if (err) return onerror(err)
awsauth({profile: 'github-to-s3'}, function(err, aws) {
if (err) return onerror(err)
var opts = {}
opts.folder = argv.folder || argv.f
opts.install = argv.install || argv.i
opts.build = argv.build || argv.b
opts.checkout = argv.checkout || argv.c
opts.prefix = prefix
opts.github = github
opts.s3 = aws
opts.s3.bucket = bucket
opts.github.repo = repo
githubToS3(opts, function(err) {
if (err) throw err
console.log(repo+' build and uploaded to https://'+opts.s3.bucket+'s3.amazonaws.com/'+prefix)
})
})
})