-
Notifications
You must be signed in to change notification settings - Fork 11
/
Gruntfile.js
286 lines (256 loc) · 6.93 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*global module:false */
module.exports = function( grunt ) {
'use strict';
var SOURCES = [ 'src/**/*.js' ];
var DEMOSOURCES = [ 'demo/scripts/**/*.js' ];
var TESTSOURCES = [ 'test/spec/**/*.js' ];
var DISTSOURCES = [
'src/module.js',
'src/tree-repeat.js'
];
var DISTDIR = 'dist';
var TASK_IMPORTS = [
'grunt-contrib-concat',
'grunt-contrib-uglify',
'grunt-contrib-jshint',
'grunt-contrib-watch',
'grunt-contrib-connect',
'grunt-contrib-copy',
'grunt-contrib-clean',
'grunt-bowerful'
];
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
dist: [DISTDIR],
site: ['site']
},
copy: {
demo: {
expand: true,
cwd: 'demo/',
src: ['**/*'],
dest: 'site/'
},
concat: {
expand: true,
flatten: true,
src: [ '<%= concat.dist.dest %>' ],
dest: 'site/components/angular-tree-repeat/'
}
},
concat: {
options: {
stripBanners: {
line: true
},
banner: '// <%= pkg.name %> - v<%= pkg.version %>\n\n'
},
dist: {
src: DISTSOURCES,
dest: DISTDIR + '/<%= pkg.name %>.js'
}
},
uglify: {
options: {
banner: '/* <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */ ',
mangle: {
topleve: true,
defines: {
NDEBUG: true
}
},
squeeze: {},
codegen: {}
},
dist: {
src: [ '<%= concat.dist.dest %>' ],
dest: DISTDIR + '/<%= pkg.name %>.min.js'
}
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
grunt: {
src: [ 'Gruntfile.js' ],
options: {node:true}
},
source: {
src: SOURCES.concat(DEMOSOURCES),
options: {
globals: {
angular: true
}
}
},
test: {
src: TESTSOURCES,
options: {
globals: {
angular: true,
inject: true,
_: false,
_V_: false,
afterEach: false,
beforeEach: false,
confirm: false,
context: false,
describe: false,
expect: false,
it: false,
jasmine: false,
mostRecentAjaxRequest: false,
qq: false,
runs: false,
spyOn: false,
spyOnEvent: false,
waitsFor: false,
xdescribe: false,
xit: false,
setFixtures: false,
sandbox: false
}
}
}
},
docco: {
tree: {
src: SOURCES,
dest: 'docs/',
options: {
layout: "parallel"
}
}
},
bowerful: {
site: {
directory: 'site/components',
packages: {
'angular': "1.2.x",
'angular-route': "1.2.x",
jquery: "1.9.x",
json3: "3.2.x",
"es5-shim": "2.0.x",
"bootstrap.css": "2.1.1",
"jasmine-jquery": "1.x"
}
}
},
connect: {
site: {
options: {
port: 8000,
hostname: '*',
base: 'site',
livereload: true
}
},
docs: {
options: {
port: 9001,
base: 'docs',
livereload: true
}
}
},
watch: {
options: {
livereload: true
},
sources: {
files: SOURCES,
tasks: ['jshint:source', 'concat', 'copy:concat']
},
demo: {
files: ['demo/**/*'],
tasks: ['jshint:source', 'copy:demo']
},
tests: {
files: TESTSOURCES,
tasks: ['test', 'jshint:test']
},
gruntFile: {
files: ['Gruntfile.js'],
tasks: ['jshint:grunt']
}
}
});
TASK_IMPORTS.forEach(grunt.loadNpmTasks);
grunt.registerTask('default', ['jshint', 'doc']);
grunt.registerTask('dist', ['jshint', 'concat', 'min']);
grunt.registerTask('doc', ['docco']);
grunt.registerTask('min', ['uglify']);
// 'demo' task - stage demo system into 'site' and watch for source changes
grunt.registerTask('build-site', ['bowerful', 'copy:demo', 'concat', 'copy:concat']);
grunt.registerTask('demo', ['clean:site', 'build-site', 'connect:site', 'watch']);
var shell = require('shelljs');
var semver = require('semver');
function run(cmd, msg){
shell.exec(cmd, {silent:true});
if( msg ){
grunt.log.ok(msg);
}
}
grunt.registerTask('release-prepare', 'Set up submodule to receive a new release', function(){
// Make sure we have the submodule in dist
run("git submodule init");
run("git submodule update");
run("cd dist; git checkout master");
// Bump version
var newVer = grunt.config('pkg').version;
var comp = grunt.file.readJSON(DISTDIR+"/bower.json");
grunt.log.writeln("Package version: " + newVer);
grunt.log.writeln("Component version: " + comp.version);
if( !semver.gt( newVer, comp.version ) ){
grunt.warn("Need to up-version package.json first!");
}
});
grunt.registerTask('release-commit', 'push new build to bower component repo', function(){
// Stamp version
var newVer = grunt.config('pkg').version;
var comp = grunt.file.readJSON(DISTDIR+"/bower.json");
grunt.log.writeln("Package version: " + newVer);
grunt.log.writeln("Component version: " + comp.version);
if( !semver.gt( newVer, comp.version ) ){
grunt.warn("Need to up-version package.json first!");
}
comp.version = newVer;
grunt.file.write(DISTDIR+"/bower.json", JSON.stringify(comp, null, ' ')+'\n');
// Commit submodule
// Tag submodule
run('cd dist; git commit -a -m"Build version '+ newVer +'"', "Commited to bower repo");
run('cd dist; git tag ' + newVer + ' -m"Release version '+ newVer +'"', "Tagged bower repo");
// Commit and tag this.
run('git commit -a -m"Build version '+ newVer +'"', "Commited to source repo");
run('git tag ' + newVer + ' -m"Release version '+ newVer +'"', "Tagged source repo");
run("git submodule update");
// push?
grunt.log.ok("DON'T FORGET TO PUSH BOTH!");
});
grunt.registerTask('release', 'build and push to the bower component repo',
['release-prepare', 'dist', 'release-commit']);
var docco = require('docco');
grunt.registerMultiTask('docco', 'Docco processor.', function() {
var task = this,
fdone = 0,
flength = this.files.length,
done = this.async();
this.files.forEach(function(file) {
docco.document(task.options({ output: file.dest, args: file.src }), function(){
if(++fdone === flength){
done();
}
});
});
});
};