This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.js
107 lines (98 loc) · 2.87 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
// Includes
const fs = require('fs');
const _ = require('lodash');
// Constants
const CONFIG_FILE = './restApi/config.json';
const DESCRIPTOR_FILE = './restApi/atlassian-connect.json';
const FILE_ENCODING = 'utf8';
const joinConfig = (configs) => {
let master = {};
configs.forEach((config) => {
Object.keys(config).forEach((key) => {
master[key] = config[key];
});
});
return master;
};
const getDescriptorWithConfigSubstituted = (config) => {
let data = fs.readFileSync(DESCRIPTOR_FILE, { encoding: FILE_ENCODING });
let substitutedData = _.template(data)(config);
return JSON.parse(substitutedData);
};
const substituteConfigAndDescriptorInTemplate = (data, env) => {
let config = getEnvironmentConfig(env);
let descriptor = getDescriptorWithConfigSubstituted(config);
let joinedConfig = joinConfig([config, descriptor]);
return _.template(data)(joinedConfig);
};
const getEnvironmentConfig = (env) => {
let data = fs.readFileSync(CONFIG_FILE, { encoding: FILE_ENCODING });
let jsonData = JSON.parse(data);
return jsonData[env];
};
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
dev: {
expand: true,
cwd: 'client/src/',
src: '**',
dest: 'client/dist/',
options: {
noProcess: ['**/*.{png,gif,jpg,ico,psd}'],
process: function (content, srcpath) {
return substituteConfigAndDescriptorInTemplate(content, 'dev');
}
}
},
beta: {
expand: true,
cwd: 'client/src/',
src: '**',
dest: 'client/dist/',
options: {
process: function (content, srcpath) {
return substituteConfigAndDescriptorInTemplate(content, 'beta');
}
}
},
prod: {
expand: true,
cwd: 'client/src/',
src: '**',
dest: 'client/dist/',
options: {
process: function (content, srcpath) {
return substituteConfigAndDescriptorInTemplate(content, 'prod');
}
}
}
},
run: {
babel: {
exec: 'node node_modules/babel-cli/bin/babel --presets es2015 -d restApi/lib --watch restApi/src'
},
'babel-once': {
exec: 'node node_modules/babel-cli/bin/babel --presets es2015 -d restApi/lib restApi/src'
},
's3-local': {
exec: 'grunt copy:dev && pushd client/dist && python -m SimpleHTTPServer 8010 && popd'
},
'create-local-dynamodb-tables': {
exec: 'bash create_dynamo_db_local_tables.sh',
options: {
passArgs: [
'region'
]
}
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-run');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask('default', ['copy']);
};