From 2ed7ee1e2d526526848c6fb6d4b2733f2d85b461 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 25 Nov 2015 19:39:51 +0600 Subject: [PATCH 1/5] add --msvs_version for npm install and use ncp --- lib/main.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8e147765..fad5a934 100644 --- a/lib/main.js +++ b/lib/main.js @@ -6,6 +6,7 @@ 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 zip = new require('node-zip')(); var wrench = require('wrench'); @@ -97,17 +98,20 @@ 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._npmInstall = function (program, codeDirectory, callback) { - exec('npm install --production --prefix ' + codeDirectory, function (err) { + exec('npm install --production --msvs_version=2015 --prefix ' + codeDirectory, function (err) { if (err) { throw err; } From 07af4618c5ecfa55aaae859b396a54cbfe5036df Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 25 Nov 2015 18:41:53 +0500 Subject: [PATCH 2/5] Add ncp to dependencies --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3a76904e..3db29b82 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", From 4eb0685ce38d7fdd951e779ca42a2e1bf2a0931f Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 25 Nov 2015 18:46:03 +0500 Subject: [PATCH 3/5] add comma --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3db29b82..0eef88be 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "aws-sdk": "^2.1.24", "commander": "^2.5.0", "dotenv": "^0.4.0", - "ncp": "~2.0.0" + "ncp": "~2.0.0", "node-uuid": "^1.4.2", "node-zip": "^1.1.0", "rimraf": "^2.2.8", From 1d01ac8f5c7c9f8640dfca4ebe2b9ff1c7f73b58 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 25 Nov 2015 22:46:05 +0600 Subject: [PATCH 4/5] Add handling of Windows platfrom and compiled libs --- lib/main.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index fad5a934..2ae90b5b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -8,6 +8,7 @@ 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'); @@ -110,13 +111,66 @@ Lambda.prototype._rsync = function (program, codeDirectory, callback) { }); }; +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) { + 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); + } }); }; From c3c344ada0e66e4e67e7418d16707db094f82dbc Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 25 Nov 2015 22:46:53 +0600 Subject: [PATCH 5/5] add win platform option --- bin/node-lambda | 2 ++ 1 file changed, 2 insertions(+) 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) {