Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const fs = require('fs');
class Client {
constructor(serverless, options){
this.serverless = serverless;
this.options=options;
this.stage = options.stage || _.get(serverless, 'service.provider.stage')
this.region = options.region || _.get(serverless, 'service.provider.region');
this.provider = 'aws';
Expand All @@ -27,13 +28,21 @@ class Client {
usage: 'Deploy serverless client code',
lifecycleEvents:[
'deploy'
]
],
options: {
file: {
usage: 'Specify the file(s) to deploy, whitespace separated',
shortcut: 'f',
default: undefined
}
}
}
}
}
};



this.hooks = {
'client:client': () => {
this.serverless.cli.log(this.commands.client.usage);
Expand Down Expand Up @@ -210,8 +219,26 @@ class Client {

return this.aws.request('S3', 'putBucketCors', params, this.stage, this.region);
}

return this.aws.request('S3', 'listBuckets', {}, this.stage, this.region)
if(this.options.file){
var list = '' + this.options.file
console.log(list)
var arr=list.split(/\s+/).filter((str)=>{return str!==''})
if(arr.length===0)
return console.log("Nothing to upload!")
return this.aws.request('S3', 'listBuckets', {}, this.stage, this.region)
.bind(this)
.then(listBuckets)
.then(listObjectsInBucket)
.then(createBucket)
.then(configureBucket)
.then(configurePolicyForBucket)
.then(configureCorsForBucket)
.then(function(){
console.log(arr)
return this._uploadFiles(arr,this.clientPath)
});
}else{
return this.aws.request('S3', 'listBuckets', {}, this.stage, this.region)
.bind(this)
.then(listBuckets)
.then(listObjectsInBucket)
Expand All @@ -221,8 +248,32 @@ class Client {
.then(configurePolicyForBucket)
.then(configureCorsForBucket)
.then(function(){
return this._uploadDirectory(this.clientPath)
return this._uploadDirectory(this.clientPath)
});
}
}

_uploadFiles(fileNames, directoryPath) {
let _this = this,
readDirectory = _.partial(fs.readdir, directoryPath);

async.waterfall([readDirectory, function (files) {
files = _.map(fileNames, function(file) {
return path.join(directoryPath, file);
});

async.each(files, function(path) {
fs.stat(path, _.bind(function (err, stats) {
if(err){
console.log(err)
return
}
return stats.isDirectory()
? _this._uploadDirectory(path)
: _this._uploadFile(path);
}, _this));
});
}]);
}

_uploadDirectory(directoryPath) {
Expand Down