forked from fluid-project/infusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
241 lines (227 loc) · 8.58 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
Copyright 2013-2014 OCAD University
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Licenses.
You may obtain a copy of the ECL 2.0 License and BSD License at
https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
*/
/* global require, module */
var _ = require("lodash");
var path = require("path");
module.exports = function(grunt) {
"use strict";
// Project configuration.
grunt.initConfig({
// Project package file destination.
pkg: grunt.file.readJSON("package.json"),
allBuildName: "<%= pkg.name %>-all",
customBuildName: "<%= pkg.name %>-" + (grunt.option("name") || "custom"),
stylusCompress: !grunt.option("source"),
clean: {
build: "build",
products: "products",
stylus: "src/framework/preferences/css/*.css"
},
copy: {
all: {
files: [{
expand: true,
src: ["src/**", "tests/**", "demos/**", "examples/**"],
dest: "build/"
}]
},
custom: {
files: [{
expand: true,
src: "<%= modulefiles.custom.output.dirs %>",
dest: "build/"
}]
},
necessities: {
files: [{
src: ["README.*", "ReleaseNotes.*", "Infusion-LICENSE.*"],
dest: "build/"
}, {
// The jQuery license file needs to be copied explicitly since
// "src/lib/jQuery" directory contains several jQuery modules
// that have individual dependencies.json files.
src: "src/lib/jQuery/jQuery-LICENSE.txt",
dest: "build/lib/jQuery/jQuery-LICENSE.txt",
filter: function() {
return grunt.file.exists("build/lib/jQuery/");
}
}]
}
},
uglify: {
options: {
mangle: false
},
all: {
files: [{
expand: true, // Enable dynamic expansion.
cwd: "./build/", // Src matches are relative to this path.
src: ["src/components/**/*.js", "src/framework/**/*.js", "src/lib/**/*.js"], // Actual pattern(s) to match.
dest: "./build/" // Destination path prefix.
}]
},
custom: {
files: [{
expand: true, // Enable dynamic expansion.
cwd: "./build", // Src matches are relative to this path.
src: ["src/**/*.js"], // Actual pattern(s) to match.
dest: "./build" // Destination path prefix.
}]
}
},
modulefiles: {
all: {
src: ["src/**/*Dependencies.json"]
},
custom: {
options: {
exclude: grunt.option("exclude"),
include: grunt.option("include")
},
src: ["src/**/*Dependencies.json"]
}
},
map: {
// append "/**" to the end of all of all of
// directory paths for copy:custom to ensure that
// all of the subdirectories and files are copied over
copyDirs: {
prop: "copy.custom.files.0.src",
fn: function (str) {
return str + "/**";
}
},
// prepend "build/" to all of the file paths for
// concat:all to rebase the paths to the build directory
concatAllFiles: {
prop: "concat.all.src",
fn: function (str) {
return "build/" + str;
}
},
// prepend "build/" to all of the file paths for
// concat:custom to rebase the paths to the build directory
concatCustomFiles: {
prop: "concat.custom.src",
fn: function (str) {
return "build/" + str;
}
}
},
concat: {
options: {
separator: ";",
banner: "/*! <%= pkg.name %> - v<%= pkg.version %> <%= grunt.template.today('dddd, mmmm dS, yyyy, h:MM:ss TT') %>*/\n"
},
all: {
src: "<%= modulefiles.all.output.files %>",
dest: "./build/<%= allBuildName %>.js"
},
custom: {
src: "<%= modulefiles.custom.output.files %>",
dest: "./build/<%= customBuildName %>.js"
}
},
compress: {
all: {
options: {
archive: "products/<%= allBuildName %>-<%= pkg.version %>.zip"
},
files: [{
expand: true, // Enable dynamic expansion.
cwd: "./build/", // Src matches are relative to this path.
src: ["**/*"], // Actual pattern(s) to match.
dest: "./infusion" // Destination path prefix in the zip package
}]
},
custom: {
options: {
archive: "products/<%= customBuildName %>-<%= pkg.version %>.zip"
},
files: "<%= compress.all.files %>"
}
},
jshint: {
all: ["**/*.js"],
buildScripts: ["Gruntfile.js"],
options: {
jshintrc: true
}
},
stylus: {
compile: {
options: {
compress: "<%= stylusCompress %>"
},
files: [{
expand: true,
src: ["src/**/css/stylus/*.styl"],
ext: ".css",
rename: function(dest, src) {
// Move the generated css files one level up out of the stylus directory
var dir = path.dirname(src);
var filename = path.basename(src);
return path.join(dir, "..", filename);
}
}]
}
},
jsonlint: {
all: ["src/**/*.json", "tests/**/*.json", "demos/**/*.json", "examples/**/*.json"]
}
});
// Load the plugin(s):
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-jsonlint");
grunt.loadNpmTasks("grunt-modulefiles");
grunt.loadNpmTasks("grunt-contrib-stylus");
// Custom tasks:
// Simple task for transforming a property
grunt.registerMultiTask("map", "a task wrapper around the map function from lodash", function () {
var transformed = _.map(grunt.config.get(this.data.prop), this.data.fn);
grunt.config.set(this.data.prop, transformed);
});
grunt.registerTask("pathMap", "Triggers the map task for the specified build target", function (target) {
if (target === "all") {
grunt.task.run("map:concatAllFiles");
} else if (target === "custom") {
grunt.task.run("map:copyDirs", "map:concatCustomFiles");
}
});
// Task for organizing the build
grunt.registerTask("build", "Generates a minified or source distribution for the specified build target", function (target) {
target = target || "all";
var tasks = [
"clean",
"stylus",
"modulefiles:" + target,
"pathMap:" + target,
"copy:" + target,
"copy:necessities",
"uglify:" + target,
"concat:" + target,
"compress:" + target,
"clean:build"
];
// remove the uglify task when creating a source build
if (grunt.option("source")) {
_.pull(tasks, "uglify:" + target);
}
grunt.task.run(tasks);
});
grunt.registerTask("buildStylus", ["clean:stylus", "stylus"]);
grunt.registerTask("default", ["build:all"]);
grunt.registerTask("custom", ["build:custom"]);
grunt.registerTask("lint", "Apply jshint and jsonlint", ["jshint", "jsonlint"]);
};