diff --git a/dist/deploy.js b/dist/deploy.js index 56eef52..19351dc 100644 --- a/dist/deploy.js +++ b/dist/deploy.js @@ -7,7 +7,8 @@ fs = require('fs'), Q = require('q'), _ = require('lodash'), - s3 = require('s3'), + s3sync = require('s3-sync-aws'), + readdirp = require('readdirp'), loginFile = path.join(process.cwd(), '.chcplogin'); module.exports = { @@ -57,35 +58,39 @@ // console.log('Credentials: ', credentials); // console.log('Config: ', config); - var client = s3.createClient({ - maxAsyncS3: 20, - s3RetryCount: 3, - s3RetryDelay: 1000, - multipartUploadThreshold: 20971520, - multipartUploadSize: 15728640, - s3Options: { - accessKeyId: credentials.key, - secretAccessKey: credentials.secret, - region: config.s3region - } + var files = readdirp({ + root: context.sourceDirectory }); - var params = { - localDir: context.sourceDirectory, - deleteRemoved: true, - s3Params: { - Bucket: config.s3bucket, - ACL: 'public-read', + + var uploader = s3sync({ + key: credentials.key, + secret: credentials.secret, + region: config.s3region, + bucket: config.s3bucket, + acl: 'public-read', + headers: { CacheControl: 'no-cache, no-store, must-revalidate', Expires: 0 + }, + concurrency: 20 + }).on('data', function (file) { + if (file.fresh) { + console.log("Updated " + file.fullPath + ' -> ' + file.url); } - }; + }); + + files.pipe(uploader); console.log('Deploy started'); - var uploader = client.uploadDir(params); uploader.on('error', function (err) { console.error("unable to sync:", err.stack); executeDfd.reject(); }); + uploader.on('fail', function (err) { + console.error("unable to sync:", err); + executeDfd.reject(); + }); + //uploader.on('progress', function() { // var progress = uploader.progressTotal - uploader.progressAmount; // console.log("progress", progress, uploader.progressTotal, uploader.progressAmount); diff --git a/package.json b/package.json index b9ff445..fa7bc65 100644 --- a/package.json +++ b/package.json @@ -38,17 +38,18 @@ "es6-promise": "^2.3.0", "express": "^4.13.1", "fs-extra": "^0.22.1", + "hidefile": "^1.1.0", "lodash": "^3.10.0", + "minimatch": "^3.0.0", "ngrok": "^0.1.99", "prompt": "^0.2.14", "q": "^1.4.1", + "readdirp": "^2.0.0", "recursive-readdir": "^1.2.1", - "s3": "^4.4.0", + "s3-sync-aws": "^1.1.0", "socket.io": "^1.3.6", "watch": "^0.16.0", - "yargs": "^3.16.1", - "minimatch": "^3.0.0", - "hidefile": "^1.1.0" + "yargs": "^3.16.1" }, "devDependencies": { "babel": "^5.8.19", diff --git a/src/deploy.js b/src/deploy.js index ccecd78..f6da4a5 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -5,7 +5,8 @@ fs = require('fs'), Q = require('q'), _ = require('lodash'), - s3 = require('s3'), + s3sync = require('s3-sync-aws'), + readdirp = require('readdirp'), loginFile = path.join(process.cwd(), '.chcplogin'); module.exports = { @@ -55,35 +56,39 @@ // console.log('Credentials: ', credentials); // console.log('Config: ', config); - var client = s3.createClient({ - maxAsyncS3: 20, - s3RetryCount: 3, - s3RetryDelay: 1000, - multipartUploadThreshold: 20971520, - multipartUploadSize: 15728640, - s3Options: { - accessKeyId: credentials.key, - secretAccessKey: credentials.secret, - region: config.s3region - }, + var files = readdirp({ + root: context.sourceDirectory }); - var params = { - localDir: context.sourceDirectory, - deleteRemoved: true, - s3Params: { - Bucket: config.s3bucket, - ACL: 'public-read', + + var uploader = s3sync({ + key: credentials.key, + secret: credentials.secret, + region: config.s3region, + bucket: config.s3bucket, + acl: 'public-read', + headers: { CacheControl: 'no-cache, no-store, must-revalidate', Expires: 0 }, - }; + concurrency: 20 + }).on('data', function(file) { + if (file.fresh) { + console.log("Updated " + file.fullPath + ' -> ' + file.url) + } + }); + + files.pipe(uploader); console.log('Deploy started'); - var uploader = client.uploadDir(params); uploader.on('error', function(err) { console.error("unable to sync:", err.stack); executeDfd.reject(); }); + uploader.on('fail', function(err) { + console.error("unable to sync:", err); + executeDfd.reject(); + }); + //uploader.on('progress', function() { // var progress = uploader.progressTotal - uploader.progressAmount; // console.log("progress", progress, uploader.progressTotal, uploader.progressAmount);