-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
194 lines (174 loc) · 4.06 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
/* jshint camelcase: false */
module.exports = function(grunt) {
var _ = require("underscore");
_.str = require("underscore.string");
grunt.config.init({
// Expose underscore to the template processor.
_: _,
// Front-end dependency management
bowercopy: {
vendor: {
options: {
destPrefix: "vendor"
},
files: {
"require.js": "requirejs/require.js"
}
}
},
// Version management
bump: {
options: {
commitFiles: [
"dist/*",
"bower.json",
"package.json"
],
files: [
"bower.json",
"package.json"
],
pushTo: "origin master",
tagName: "%VERSION%",
updateConfigs: [
"pkg"
]
}
},
// Clean up files and folders before build
clean: {
dependencies: [
"bower_components",
"vendor"
],
build: [
"dist"
]
},
// Unit testing
jasmine: {
taskName: {
src: "src/**/*.js",
options: {
outfile: "spec/runner.html",
specs: "spec/*.js",
template: require("grunt-template-jasmine-requirejs"),
templateOptions: {
requireConfigFile: "build/config.js"
}
}
}
},
// TODO
//jscs: {},
// JavaScript linting. Configuration options are defined in .jshintrc
jshint: {
options: {
jshintrc: true
},
grunt: {
src: "Gruntfile.js"
},
source: {
src: "src/**/*.js"
}
},
// TODO
//jsonlint: {},
pkg: grunt.file.readJSON("package.json"),
// TODO
//spec
// Require.js optimization. Processes multiple AMD compliant files into one.
requirejs: {
compile: {
options: {
mainConfigFile: "build/config.js",
name: "build/main.js",
optimize: "none",
out: "dist/fixture.js",
skipModuleInsertion: true,
skipSemiColonInsertion: true,
wrap: {
start: "<%= templates.banner %><%= templates.start %>",
end: "<%= templates.end %>"
}
}
}
},
// Remove development-only code segments
strip_code: {
build: {
options: {
start_comment: "start-build-ignore",
end_comment: "end-build-ignore"
},
src: "dist/fixture.js"
}
},
// Build templates
templates: {
banner: grunt.file.read("build/banner.jst"),
end: grunt.file.read("build/end.jst"),
start: grunt.file.read("build/start.jst")
},
// JavaScript minification for distribution files.
uglify: {
options: {
banner: "<%= templates.banner %>",
preserveComments: false
},
dist: {
src: "<%= requirejs.compile.options.out %>",
dest: "dist/fixture.min.js"
}
},
// Run grunt tasks when files change.
watch: {
src: {
files: [
"Gruntfile.js",
"src/**/*.js"
],
tasks: [
"default"
]
}
}
});
// Load plugins from npm
grunt.loadNpmTasks("grunt-bowercopy");
grunt.loadNpmTasks("grunt-bump");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-jasmine");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-requirejs");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-strip-code");
// Dev testing
grunt.registerTask("test", [
"jshint",
"clean:dependencies",
"bowercopy",
"jasmine"
]);
// Build
grunt.registerTask("build", [
"default",
"clean:build",
"requirejs",
"strip_code",
"uglify"
]);
// Release
grunt.registerTask("release", function() {
var type = this.args.shift() || "patch";
grunt.task.run([
"bump:" + type + ":bump-only",
"build",
"bump:" + type + ":commit-only"
]);
});
// Default task
grunt.registerTask("default", "test");
};