-
Notifications
You must be signed in to change notification settings - Fork 79
/
GruntFile.js
184 lines (175 loc) · 5.35 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// GruntFile for building the final compiled files from the core.
// Run using NodeJS and the Grunt module
var fs = require("fs");
var dirs = {
core: "src/core",
i18n: "src/i18n",
build: "build"
};
var getI18NFiles = function () {
return fs.readdirSync(dirs.i18n);
};
var buildMinifyFileList = function (dev) {
var output_path = dev ? "" : "production/";
var output_ext = dev ? "." : ".min.";
var files = getI18NFiles();
var output = {};
files.map(function(item){
var file_core_name = "date-" + item.replace(".js", "");
var dest = dirs.build + "/"+output_path + file_core_name + output_ext + "js";
output[dest] = [dirs.build + "/" + file_core_name + ".js"];
return dest;
});
output[dirs.build + "/"+output_path + "date"+output_ext+"js"] = [dirs.build + "/" + "date.js"];
return output;
};
var banner = "/** \n" +
" * @overview <%= pkg.name %>\n" +
" * @version <%= pkg.version %>\n" +
" * @author <%= pkg.author.name %> <<%= pkg.author.email %>>\n" +
" * @copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" +
" * @license <%= pkg.license %>\n" +
" * @homepage <%= pkg.homepage %>\n" +
" */";
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
dirs: dirs,
build_dev: {
description: "Builds files designed for easy debugging on dev enviroments (non-minified)"
},
build_prod: {
description: "Builds production ready files (minified)"
},
closurecompiler: {
minify: {
files: buildMinifyFileList(),
options: {
"compilation_level": "SIMPLE_OPTIMIZATIONS",
"max_processes": 5,
"banner": banner
}
}
},
concat: {
options: {
separator: "\n",
banner: banner,
nonull: true
},
core: {
src: [
"<%= dirs.core %>/i18n.js",
"<%= dirs.core %>/core.js",
"<%= dirs.core %>/core-prototypes.js",
"<%= dirs.core %>/sugarpak.js",
"<%= dirs.core %>/format_parser.js",
"<%= dirs.core %>/parsing_operators.js",
"<%= dirs.core %>/parsing_translator.js",
"<%= dirs.core %>/parsing_grammar.js",
"<%= dirs.core %>/parser.js",
"<%= dirs.core %>/extras.js",
"<%= dirs.core %>/time_span.js",
"<%= dirs.core %>/time_period.js"
],
dest: "<%= dirs.build %>/date-core.js"
},
basic: {
src: [
"<%= dirs.core %>/i18n.js",
"<%= dirs.core %>/core.js",
"<%= dirs.core %>/core-prototypes.js",
"<%= dirs.core %>/sugarpak.js",
"<%= dirs.core %>/format_parser.js",
"<%= dirs.core %>/parsing_operators.js",
"<%= dirs.core %>/parsing_translator.js",
"<%= dirs.core %>/parsing_grammar.js",
"<%= dirs.core %>/parser.js",
"<%= dirs.core %>/extras.js",
"<%= dirs.core %>/time_span.js",
"<%= dirs.core %>/time_period.js"
],
dest: "<%= dirs.build %>/date.js"
}
},
i18n: {
core: {
core: "<%= dirs.build %>/date-core.js",
src: ["<%= dirs.i18n %>/*.js"],
dest: "<%= dirs.build %>/" // destination *directory*, probably better than specifying same file names twice
}
},
shell: {
updateCodeClimate: {
command: "codeclimate < reports/lcov.info",
options: {
stdout: true,
stderr: true,
failOnError: true
}
}
},
jasmine : {
src : [
"src/core/i18n.js",
"src/core/core.js",
"src/core/core-prototypes.js",
"src/core/sugarpak.js",
"src/core/format_parser.js",
"src/core/parsing_operators.js",
"src/core/parsing_translator.js",
"src/core/parsing_grammar.js",
"src/core/parser.js",
"src/core/extras.js",
"src/core/time_period.js",
"src/core/time_span.js"
],
options : {
specs : "specs/*-spec.js",
template : require("grunt-template-jasmine-istanbul"),
templateOptions: {
template: "specs/jasmine-2.0.3/specrunner.tmpl",
coverage: "reports/coverage.json",
report: {
type: "lcov",
options: {
replace: true,
dir: "reports/"
}
}
}
}
},
});
grunt.registerMultiTask("i18n", "Wraps DateJS core with Internationalization info.", function() {
var data = this.data,
path = require("path"),
dest = grunt.template.process(data.dest),
files = grunt.file.expand(data.src),
core = grunt.file.read(grunt.template.process(data.core)),
sep = grunt.util.linefeed,
banner_compiled = grunt.template.process(banner);
files.forEach(function(f) {
var p = dest + "/" + "date-" + path.basename(f),
contents = grunt.file.read(f);
grunt.file.write(p, banner_compiled + sep + contents + sep + core );
grunt.log.writeln("File \"" + p + "\" created.");
});
grunt.file.delete(dirs.build+"/date-core.js");
});
grunt.registerMultiTask("build_dev", "Builds compiled, non-minfied, files for development enviroments", function() {
grunt.task.run(["concat:core", "concat:basic", "i18n:core"]);
});
grunt.registerMultiTask("build_prod", "Rebuilds dev and minifies files for production enviroments", function() {
grunt.task.run(["concat:core", "concat:basic", "i18n:core", "closurecompiler:minify"]);
});
grunt.loadNpmTasks("grunt-contrib-jasmine");
// now set the default
grunt.registerTask("default", ["build_dev"]);
// Load the plugin that provides the "minify" task.
grunt.loadNpmTasks("grunt-shell");
grunt.loadNpmTasks("grunt-closurecompiler");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.registerTask("test", ["jasmine", "shell:updateCodeClimate"]);
};