@@ -8,11 +8,10 @@ const chalk = require('chalk');
8
8
const spinner = require ( 'ora' ) ( ) ;
9
9
const metadata = require ( '../package.json' ) ;
10
10
11
- aws . config . update ( {
11
+ const s3 = new aws . S3 ( {
12
12
s3ForcePathStyle : true ,
13
13
endpoint : 'https://s3.csh.rit.edu'
14
14
} ) ;
15
- const s3 = new aws . S3 ( ) ;
16
15
17
16
const config = {
18
17
root : path . resolve ( __dirname , '..' ) ,
@@ -22,10 +21,32 @@ const config = {
22
21
'src/*'
23
22
] ,
24
23
bucket : metadata . name ,
24
+ region : '' ,
25
25
dest : metadata . version ,
26
26
acl : 'public-read'
27
27
} ;
28
28
29
+ async function ensureBucket ( ) {
30
+ const params = {
31
+ Bucket : config . bucket
32
+ } ;
33
+
34
+ return s3 . headBucket ( params ) . promise ( )
35
+ . catch ( err => {
36
+ if ( err . code == 'NoSuchBucket' || err . code == 'NotFound' ) {
37
+ // Bucket does not exist, create it
38
+ params . CreateBucketConfiguration = {
39
+ LocationConstraint : config . region
40
+ } ;
41
+
42
+ return s3 . createBucket ( params ) . promise ( ) ;
43
+ }
44
+
45
+ // Unhandled error
46
+ throw err ;
47
+ } ) ;
48
+ }
49
+
29
50
function upload ( srcPath , destPath ) {
30
51
return fs . readFile ( srcPath )
31
52
. then ( data => {
@@ -48,6 +69,10 @@ function upload(srcPath, destPath) {
48
69
async function deploy ( ) {
49
70
const uploaders = [ ] ;
50
71
72
+ // Ensure the upload bucket exists
73
+ await ensureBucket ( ) ;
74
+
75
+ // Upload each artifact to the bucket
51
76
for ( let artifact of config . artifacts ) {
52
77
const filenames = await globby ( path . resolve ( config . root , artifact ) ) ;
53
78
@@ -71,7 +96,7 @@ function fail(error, message) {
71
96
if ( typeof error === 'string' ) {
72
97
spinner . fail ( chalk . bold . red ( error ) ) ;
73
98
} else {
74
- spinner . fail ( chalk . bold . red ( `${ message } \n${ error } ` ) )
99
+ spinner . fail ( chalk . bold . red ( `${ message } \n${ error } ${ error . code ? ": " + error . code : "" } ` ) )
75
100
}
76
101
77
102
shell . exit ( 1 ) ;
0 commit comments