Skip to content

Added lambda_package option to map files into the zip archive (rename) #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion test/integ/lambda_package_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
10 changes: 9 additions & 1 deletion utils/package_task.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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 () {
Expand Down