-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathGruntfile.js
More file actions
384 lines (332 loc) · 9.02 KB
/
Gruntfile.js
File metadata and controls
384 lines (332 loc) · 9.02 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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
var path = require('path');
var _ = require('lodash');
module.exports = function (grunt) {
grunt.initConfig(
{
pkg: grunt.file.readJSON('package.json'),
// Default values
version: 'NEXT',
fileVersion: "-<%= version %>",
name: 'easeljs',
// Setup doc names / paths.
docsName: '<%= pkg.name %>_docs<%= fileVersion %>',
docsZip: "<%= docsName %>.zip",
// Setup watch to watch the source and rebuild when it changes. Also livereload
watch: {
js: {
files: [
getConfigValue('easel_source'),
getConfigValue('watch_exclude_files')
],
tasks: ['sourceBuild'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
livereload: {
files: getConfigValue('livereload_watch'),
options: {
livereload: '<%= connect.options.livereload %>'
}
}
},
// Setup the connect webserver with livereload
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' for non-local access.
hostname: '127.0.0.1',
livereload: 35729
},
test: {
options: {
base: getConfigValue('connect_root'),
open: true
}
}
},
// Setup Uglify for JS minification.
uglify: {
options: {
banner: grunt.file.read('LICENSE'),
preserveComments: "some",
compress: {
global_defs: {
"DEBUG": false
}
}
},
build: {
files: {
'output/<%= pkg.name.toLowerCase() %><%= fileVersion %>.min.js': getConfigValue('easel_source')
}
}
},
concat: {
options: {
separator: '',
process: function(src, filepath) {
// Remove a few things from each file, they will be added back at the end.
// Strip the license header.
var file = src.replace(/^(\/\*\s)[\s\S]+?\*\//, "")
// Strip namespace
// file = file.replace(/(this.createjs)\s=\s\1.*/, "");
// Strip namespace label
file = file.replace(/\/\/\s*namespace:/, "");
// Strip @module
file = file.replace(/\/\*\*[\s\S]+?@module[\s\S]+?\*\//, "");
// Clean up white space
file = file.replace(/^\s*/, "");
file = file.replace(/\s*$/, "");
// Append on the class name
file =
"\n\n//##############################################################################\n"+
"// " + path.basename(filepath) + "\n" +
"//##############################################################################\n\n"+
file;
return file;
}
},
build: {
files: {
'output/<%= pkg.name.toLowerCase() %><%= fileVersion %>.js': combineSource(
[
{cwd: '', config:'config.json', source:'easel_source'}
]
)
}
}
},
// Build docs using yuidoc
yuidoc: {
compile: {
name: '<%= pkg.name %>',
version: '<%= version %>',
description: '<%= pkg.description %>',
url: '<%= pkg.url %>',
logo: '<%= pkg.logo %>',
options: {
paths: ['./'],
outdir: '<%= docsFolder %>',
linkNatives: true,
attributesEmit: true,
selleck: true,
helpers: ["../build/path.js"],
themedir: "../build/createjsTheme/"
}
}
},
compress: {
build: {
options: {
mode:'zip',
archive:'output/<%= docsZip %>'
},
files: [
{expand:true, src:'**', cwd:'<%= docsFolder %>'}
]
}
},
sass: {
docs: {
options: {
style: 'compressed'
},
files: {
'createjsTheme/assets/css/main.css': 'createjsTheme/assets/scss/main.scss'
}
}
},
clean: {
docs: {
src: ["<%= docsFolder %>/assets/scss"]
}
},
copy: {
docsZip: {
files: [
{expand: true, cwd:'output/', src:'<%= docsZip %>', dest:'../docs/'}
]
},
docsSite: {
files: [
{expand:true, cwd:'<%= docsFolder %>', src:'**', dest:getConfigValue('docs_out_path')}
]
},
src: {
files: [
{expand: true, cwd:'./output/', src: '*<%=fileVersion %>*.js', dest: '../lib/'}
]
}
},
updateversion: {
easel: {
file: '../src/easeljs/version.js',
version: '<%= version %>'
}
},
clearversion: {
easel: {
file: '../src/easeljs/version.js'
}
}
}
);
function getBuildConfig() {
// Read the global settings file first.
var config = grunt.file.readJSON('config.json');
// If we have a config.local.json .. prefer its values.
if (grunt.file.exists('config.local.json')) {
var config2 = grunt.file.readJSON('config.local.json');
_.extend(config, config2);
}
return config;
}
function getConfigValue(name) {
var config = grunt.config.get('buildConfig');
if (config == null) {
config = getBuildConfig();
grunt.config.set('buildConfig', config);
}
return config[name];
}
function getCombinedSource() {
var configs = [
{cwd: '', config:'config.json', source:'source'}
];
return combineSource(configs);
}
function combineSource(configs) {
// Pull out all the source paths.
var sourcePaths = [];
for (var i=0;i<configs.length;i++) {
var o = configs[i];
var json = grunt.file.readJSON(path.resolve(o.cwd, o.config));
var sources = json[o.source];
sources.forEach(function(item, index, array) {
array[index] = path.resolve(o.cwd, item);
});
sourcePaths = sourcePaths.concat(sources);
}
// Remove duplicates (Like EventDispatcher)
var dups = {};
var clean = [];
for (i=0;i<sourcePaths.length;i++) {
var src = sourcePaths[i];
var cleanSrc = src.substr(src.lastIndexOf('src' + path.sep));
if (dups[cleanSrc] == null) {
clean.push(src);
dups[cleanSrc] = true;
}
}
return clean;
}
function getBuildArgs() {
var banner = grunt.file.read("BANNER");
grunt.config("concat.options.banner", banner);
}
// Load all the tasks we need
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadTasks('tasks/');
grunt.registerTask('exportScriptTags', function() {
var source = grunt.option("path") || "";
var config = getBuildConfig();
var scripts = config.easel_source;
var tags = [];
for (var i = 0; i < scripts.length; i++) {
var script = '<script src="<%=src %>"></script>';
var realPath = scripts[i].replace("../src/", "");
tags.push(grunt.template.process(script, {data: {src: source + realPath}}));
}
console.log(tags.join("\n"));
});
grunt.registerTask('setDocsBase', "Internal utility task to set a correct base for YUIDocs.", function() {
grunt.file.setBase('../src');
grunt.config.set('docsFolder', "../build/output/<%= docsName %>/");
});
grunt.registerTask('resetBase', "Internal utility task to reset the base, after setDocsBase", function() {
grunt.file.setBase('../build');
grunt.config.set('docsFolder', "./output/<%= docsName %>/");
});
/**
* Build the docs using YUIdocs.
*/
grunt.registerTask('docs', [
"sass", "setDocsBase", "yuidoc", "resetBase", "clean:docs", "compress", "copy:docsZip"
]);
/**
* Sets out version to the version in package.json (defaults to NEXT)
*/
grunt.registerTask('setVersion', function () {
grunt.config.set('version', grunt.config.get('pkg').version);
grunt.config.set("fileVersion", "");
});
/**
* Task for exporting a next build.
*
*/
grunt.registerTask('next', function() {
grunt.config("buildArgs", this.args || []);
getBuildArgs();
grunt.task.run(["coreBuild", "clearBuildArgs"]);
});
/**
* Task for exporting only the next lib.
*
*/
grunt.registerTask('nextlib', [
"sourceBuild"
]);
/** Aliased task for WebStorm quick-run */
grunt.registerTask('_next_easel', ["next"]);
/**
* Task for exporting a release build (version based on package.json)
*
*/
grunt.registerTask('build', function() {
grunt.config("buildArgs", this.args || []);
getBuildArgs();
grunt.task.run(["setVersion", "coreBuild", "updatebower", "copy:docsSite", "clearBuildArgs"]);
});
grunt.registerTask('clearBuildArgs', function() {
grunt.config("buildArgs", []);
});
/**
* Main build task, always runs after next or build.
*
*/
grunt.registerTask('coreBuild', [
"docs", "sourceBuild"
]);
/**
* Main source build task
*
*/
grunt.registerTask('sourceBuild', [
"updateversion", "combine", "uglify", "clearversion", "copy:src"
]);
/**
* Task for exporting combined view.
*
*/
grunt.registerTask('combine', 'Combine all source into a single, un-minified file.', [
"concat"
]);
/**
* Task for starting a webserver, watching source files and livereloading.
*
*/
grunt.registerTask('serve', 'Start a webserver and watch the source files for changes.', [
"sourceBuild",
"connect:test",
"watch"
]);
};