-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
executable file
·50 lines (44 loc) · 1.42 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module.exports = function(grunt) {
grunt.initConfig({
uglify: {
dist: {
files: [
{
src: 'lambda/**/*.js',
ext: '.min.js',
expand: true
}
]
}
},
cfninit: {
src: 'cfn/replicator.cfn.json',
dest: 'dist/replicator.cfn.json'
},
clean: [ 'lambda/**/*.min.js' ]
});
//Load plugins for creating and removing minified javascript files
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
//Register task for compiling cfn template
grunt.registerTask('cfn-include', 'Build cloudformation template using cfn-include', function(){
var compileTemplate = require('cfn-include');
var path = require('path');
var config = grunt.config.get('cfninit');
var getAbsolutePath = function(filePath){
if(!path.isAbsolute(filePath))
filePath = path.join(process.cwd(), filePath);
return filePath;
};
//Build source and destination URLS for cfn templates
var srcUrl = "file://" + getAbsolutePath(config.src);
//Compile source template
var done = this.async();
compileTemplate({ url: srcUrl }).then(function(template){
//Write compiled template to dest
grunt.file.write(getAbsolutePath(config.dest), JSON.stringify(template, null, 2));
done();
});
});
grunt.registerTask('default', ['uglify', 'cfn-include', 'clean']);
};