From e4451fc67c782b596d248f51d33c53291d5caa2e Mon Sep 17 00:00:00 2001 From: dhleong Date: Thu, 9 Jul 2015 09:33:59 -0400 Subject: [PATCH] Add `include_files` option to lambda_package This lets you keep credential files, for example, out of git and npm, but still package them when you deploy --- .npmignore | 2 +- Gruntfile.js | 3 ++- README.md | 6 ++++++ tasks/lambda_package.js | 14 +++++++++++++- test/fixtures/package_custom/.npmignore | 1 + test/fixtures/package_custom/custom.json | 1 + test/lambda_package_test.js | 4 +++- 7 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/package_custom/.npmignore create mode 100644 test/fixtures/package_custom/custom.json diff --git a/.npmignore b/.npmignore index cc126f3..51bb0c3 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,3 @@ .idea *.iml -tmp \ No newline at end of file +tmp diff --git a/Gruntfile.js b/Gruntfile.js index 588970c..8186e73 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -62,7 +62,8 @@ module.exports = function (grunt) { options: { dist_folder: 'tmp/dist', include_time: false, - package_folder: 'test/fixtures/package_custom' + package_folder: 'test/fixtures/package_custom', + include_files: ['custom.json'] } } }, diff --git a/README.md b/README.md index 41721af..986ff34 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,12 @@ grunt.initConfig({ #### Options +##### options.include_files +Type: `Array` +Default value: `[]` + +List of files to explicitly include in the package, even if they would be ignored by NPM + ##### options.include_time Type: `Boolean` Default value: `true` diff --git a/tasks/lambda_package.js b/tasks/lambda_package.js index 8353129..19ae916 100644 --- a/tasks/lambda_package.js +++ b/tasks/lambda_package.js @@ -28,7 +28,8 @@ module.exports = function (grunt) { var options = this.options({ 'dist_folder': 'dist', 'include_time': true, - 'package_folder': './' + 'package_folder': './', + 'include_files': [] }); var pkg = grunt.file.readJSON(path.resolve(options.package_folder + '/package.json')); @@ -91,6 +92,17 @@ module.exports = function (grunt) { } ]); + if (options.include_files.length) { + zipArchive.bulk([ + { + src: options.include_files, + dot: true, + expand: true, + cwd: options.package_folder + } + ]); + } + zipArchive.finalize(); output.on('close', function () { diff --git a/test/fixtures/package_custom/.npmignore b/test/fixtures/package_custom/.npmignore new file mode 100644 index 0000000..4fb5bce --- /dev/null +++ b/test/fixtures/package_custom/.npmignore @@ -0,0 +1 @@ +custom.json diff --git a/test/fixtures/package_custom/custom.json b/test/fixtures/package_custom/custom.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/test/fixtures/package_custom/custom.json @@ -0,0 +1 @@ +{} diff --git a/test/lambda_package_test.js b/test/lambda_package_test.js index b8689f0..2f76d31 100644 --- a/test/lambda_package_test.js +++ b/test/lambda_package_test.js @@ -59,11 +59,12 @@ exports.lambda_package = { }); }, custom_options: function (test) { - test.expect(5); + test.expect(6); var zip = new AdmZip("tmp/dist/another-lambda-function_0-0-1_latest.zip"); var zipEntries = zip.getEntries(); var required = [ + 'custom.json', 'index.js', 'package.json', 'node_modules/', @@ -79,4 +80,5 @@ exports.lambda_package = { test.done(); } + };