diff --git a/Gruntfile.js b/Gruntfile.js index 8b8d605..2eb23b3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -73,7 +73,8 @@ module.exports = function (grunt) { dist_folder: 'tmp/dist', include_time: false, package_folder: 'test/fixtures/package_custom', - include_files: ['custom.json'] + include_files: ['custom.json'], + include_files_mapped: {'custom.json': 'custom_mapped.json'} } } }, diff --git a/README.md b/README.md index cec1a5b..a530388 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,14 @@ Default value: `[]` List of files to explicitly include in the package, even if they would be ignored by NPM +##### options.include_files_mapped +Type: `Object` +Default value: `{}` + +Mapping of files to explicitly include in the package, even if they would be ignored by NPM. +The object contains the source as a key and the destination in the zip archive as value. +This is for example useful when using different environment configurations. + ##### options.include_time Type: `Boolean` Default value: `true` diff --git a/test/integ/lambda_package_test.js b/test/integ/lambda_package_test.js index 2f76d31..7c09a10 100644 --- a/test/integ/lambda_package_test.js +++ b/test/integ/lambda_package_test.js @@ -59,12 +59,13 @@ exports.lambda_package = { }); }, custom_options: function (test) { - test.expect(6); + test.expect(7); var zip = new AdmZip("tmp/dist/another-lambda-function_0-0-1_latest.zip"); var zipEntries = zip.getEntries(); var required = [ 'custom.json', + 'custom_mapped.json', 'index.js', 'package.json', 'node_modules/', diff --git a/utils/package_task.js b/utils/package_task.js index 4b3d751..825c92a 100644 --- a/utils/package_task.js +++ b/utils/package_task.js @@ -29,7 +29,8 @@ packageTask.getHandler = function (grunt) { 'include_time': true, 'include_version': true, 'package_folder': './', - 'include_files': [] + 'include_files': [], + 'include_files_mapped': {} }); var pkg = JSON.parse(fs.readFileSync(path.resolve(options.package_folder + '/package.json'), "utf8")); @@ -97,6 +98,13 @@ packageTask.getHandler = function (grunt) { ]); } + if (Object.keys(options.include_files_mapped).length !== 0) { + // maps: src -> destination + Object.keys(options.include_files_mapped).forEach(function (src) { + zipArchive.append(src, {name: options.include_files_mapped[src]}); + }); + } + zipArchive.finalize(); output.on('close', function () {