-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGruntfile.js
More file actions
84 lines (77 loc) · 2.89 KB
/
Gruntfile.js
File metadata and controls
84 lines (77 loc) · 2.89 KB
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
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'www/js/services.js',
dest: 'target/services.min.js'
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['uglify']);
var customizeJSON = function(original, custom) {
for(var key in custom) { if (custom.hasOwnProperty(key)) {
if (original.hasOwnProperty(key)) {
var customValue = custom[key];
var originalValue = original[key];
if (typeof customValue === "object" && typeof originalValue == "object") {
customizeJSON(originalValue, customValue);
} else {
original[key] = custom[key];
}
} else {
original[key] = custom[key];
}
}}
}
var customizeJSONFile = function(original, customFile) {
if (typeof customFile !== "undefined") {
var custom = grunt.file.readJSON(customFile);
customizeJSON(original, custom);
}
}
grunt.registerTask('cfg-custom', 'Customize FireREST JSON config file',
function(config, custom1, custom2, custom3, custom4, custom5, customEnd) {
if (typeof config === "undefined") {
throw grunt.util.error(this.name + " expected path of FireREST configuration file");
}
if (typeof custom1 === "undefined") {
throw grunt.util.error(this.name + " expected path of FireREST custom configuration file(s)");
}
if (typeof customEnd !== "undefined") {
throw grunt.util.error(this.name + " too many customization filess");
}
var json = grunt.file.readJSON(config);
customizeJSONFile(json, custom1);
customizeJSONFile(json, custom2);
customizeJSONFile(json, custom3);
customizeJSONFile(json, custom4);
customizeJSONFile(json, custom5);
grunt.file.write(config, JSON.stringify(json, null, " "));
}
);
grunt.registerTask('cfg-version', 'Add version to given FireREST JSON config file', function(src, dst, major, minor, patch) {
if (typeof src === "undefined") {
throw grunt.util.error(this.name + " expected path of source FireREST configuration file");
}
if (typeof dst === "undefined") {
throw grunt.util.error(this.name + " expected path of destination FireREST configuration file");
}
if (typeof patch === "undefined") {
throw grunt.util.error(this.name + " expected major, minor and patch version numbers");
}
var json = grunt.file.readJSON(src);
json.FireREST.version.major = major;
json.FireREST.version.minor = minor;
json.FireREST.version.patch = patch;
grunt.file.write(dst, JSON.stringify(json, null, " "));
grunt.log.writeln("VERSION\t: " + dst + " v" + major + "." + minor + "." + patch);
});
}