diff --git a/bin/node-lambda b/bin/node-lambda index ad755f49..95ada64a 100755 --- a/bin/node-lambda +++ b/bin/node-lambda @@ -22,6 +22,7 @@ var AWS_TIMEOUT = process.env.AWS_TIMEOUT || 60; var AWS_DESCRIPTION = process.env.AWS_DESCRIPTION || ''; var AWS_RUNTIME = process.env.AWS_RUNTIME || 'nodejs'; var AWS_FUNCTION_VERSION = process.env.AWS_FUNCTION_VERSION || ''; +var LOCAL_WIN_PLATFORM = !!process.env.LOCAL_WIN_PLATFORM; var EVENT_FILE = process.env.EVENT_FILE || 'event.json'; program @@ -43,6 +44,7 @@ program .option('-d, --description [' + AWS_DESCRIPTION + ']', 'Lambda Description', AWS_DESCRIPTION) .option('-u, --runtime [' + AWS_RUNTIME + ']', 'Lambda Runtime', AWS_RUNTIME) .option('-v, --version [' + AWS_FUNCTION_VERSION + ']', 'Lambda Function Version', AWS_FUNCTION_VERSION) + .option('-w, --win-platform [' + LOCAL_WIN_PLATFORM.toString() + ']', 'Is your local machine under Windows OS', LOCAL_WIN_PLATFORM) .option('-f, --configFile [' + CONFIG_FILE + ']', 'Path to file holding secret environment variables (e.g. "deploy.env")', CONFIG_FILE) .action(function (prg) { diff --git a/lib/main.js b/lib/main.js index 8e147765..2ae90b5b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -6,7 +6,9 @@ var fs = require('fs'); var os = require('os'); var packageJson = require('./../package.json'); var path = require('path'); +var ncp = require('ncp'); var async = require('async'); +var rimraf = require('rimraf'); var zip = new require('node-zip')(); var wrench = require('wrench'); var dotenv = require('dotenv'); @@ -97,22 +99,78 @@ Lambda.prototype._zipfileTmpPath = function (program) { }; Lambda.prototype._rsync = function (program, codeDirectory, callback) { - exec('rsync -r --exclude=.git --exclude=*.log --exclude=node_modules . ' + codeDirectory, function (err) { + ncp.limit = 16; + var options = { filter : /^((?!\.idea|.git|.env|node_modules|^(.*?)\.log).)*$/i }; // filter out files + + ncp(process.cwd(), codeDirectory, options, function (err) { if (err) { - throw err; + console.error(err); + return callback(err) } + return callback(null, true); + }); +}; + +Lambda.prototype._replaceNative = function (program, codeDirectory, callback) { + var _this = this; + var nativesDir = codeDirectory + '/native_packages'; + var modulesDir = codeDirectory + '/node_modules'; + async.waterfall([ + function (taskCallback) { + fs.readdir(nativesDir, taskCallback); + }, + function (contents, taskCallback) { + async.filter( + contents, + function (element, filterCallback) { + return fs.stat(path.join(nativesDir, element), function (err, stats) { + filterCallback(stats.isDirectory()) + }); + }, + function (dirs) { + return taskCallback(null, dirs); + } + ); + }, + function (dirs, taskCallback) { + var dirIndex = 0; + async.whilst( + function () { + return dirIndex < dirs.length; + }, + function (whilstCallback) { + rimraf(path.join(modulesDir, dirs[dirIndex]), whilstCallback); + dirIndex++; + }, + taskCallback + ); + }, + function (taskCallback) { + ncp(codeDirectory + '/native_packages', codeDirectory + '/node_modules', taskCallback); + } + ], function (err) { + if (err) { + console.error(err); + return callback(err) + } return callback(null, true); }); + }; Lambda.prototype._npmInstall = function (program, codeDirectory, callback) { - exec('npm install --production --prefix ' + codeDirectory, function (err) { + var _this = this; + exec('npm install --production --msvs_version=2015 --prefix ' + codeDirectory, function (err) { if (err) { throw err; } - return callback(null, true); + if (program.winPlatform) { + _this._replaceNative(program, codeDirectory, callback) + } else { + return callback(null, true); + } }); }; diff --git a/package.json b/package.json index 3a76904e..0eef88be 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "aws-sdk": "^2.1.24", "commander": "^2.5.0", "dotenv": "^0.4.0", + "ncp": "~2.0.0", "node-uuid": "^1.4.2", "node-zip": "^1.1.0", "rimraf": "^2.2.8",