This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathGruntfile.js
260 lines (224 loc) · 8.02 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
/* global module, require */
var path = require('path');
module.exports = function (grunt) {
'use strict';
var jasSrc = grunt.file.readJSON('config.json').platypus_source.slice();
jasSrc.unshift(
"node_modules/springroll/components/preloadjs/lib/preloadjs.combined.js",
"node_modules/springroll/components/soundjs/lib/soundjs.combined.js",
"node_modules/pixi.js/dist/pixi.js",
"node_modules/springroll/dist/core.js",
"node_modules/springroll/dist/modules/pixi-display.js",
"node_modules/springroll/dist/modules/states.js"
);
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Default values
version: 'NEXT',
name: 'platypus',
// Setup doc names / paths.
docsName: '<%= pkg.name %>_docs-<%= version %>',
docsZip: "<%= docsName %>.zip",
// Setup tests
jasmine: {
src: jasSrc,
options: {
specs: "spec/**/*.js",
vendor: "vendor/**/*.js",
version: '2.0.0'
}
},
// Setup Uglify for JS minification.
uglify: {
options: {
banner: "/*!\n * @license PLATYPUS v<%= version %>\n *\n * Distributed under the terms of the MIT license.\n * http://www.opensource.org/licenses/mit-license.html\n *\n * This notice shall be included in all copies or substantial portions of the Software.\n */\n\n",
preserveComments: "some",
compress: {
global_defs: {
"DEBUG": false
}
}
},
build: {
files: {
'./build/output/<%= pkg.name.toLowerCase() %>.min.js': getConfigValue('platypus_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 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: {
'./build/output/<%= pkg.name.toLowerCase() %>.combined.js': combineSource([{
cwd: '',
config: 'config.json',
source: 'platypus_source'
}])
}
}
},
// Build docs using yuidoc
yuidoc: {
compile: {
name: '<%= pkg.name %>',
version: '<%= version %>',
description: '<%= pkg.description %>',
url: '<%= pkg.url %>',
logo: '<%= pkg.logo %>',
options: {
paths: ['./src/'],
outdir: '<%= docsFolder %>',
linkNatives: true,
attributesEmit: true,
selleck: true,
helpers: ["./build/path.js"],
themedir: "./build/platypusTheme/"
}
}
},
compress: {
build: {
options: {
mode: 'zip',
archive: 'output/<%= docsZip %>'
},
files: [{
expand: true,
src: '**',
cwd: '<%= docsFolder %>'
}]
}
},
copy: {
docsSite: {
files: [{
expand: true,
cwd: '<%= docsFolder %>',
src: '**',
dest: getConfigValue('docs_out_path')
}]
},
src: {
files: [{
expand: true,
cwd: './build/output/',
src: '*.js',
dest: './lib/'
}]
}
},
updateversion: {
platypus: {
file: './src/platypus.js',
version: '<%= version %>'
}
},
clearversion: {
platypus: {
file: './src/platypus.js'
}
}
});
function getConfigValue (name) {
var config = grunt.file.readJSON('config.json');
grunt.config.set('buildConfig', config);
return config[name];
}
function combineSource (configs) {
var handle = function (item, index, array) {
array[index] = path.resolve(this.cwd, item);
},
i = 0,
json = null,
o = null,
sourcePaths = [],
sources = null;
// Pull out all the source paths.
for (i = 0; i < configs.length; i++) {
o = configs[i];
json = grunt.file.readJSON(path.resolve(o.cwd, o.config));
sources = json[o.source];
sources.forEach(handle.bind(o));
sourcePaths = sourcePaths.concat(sources);
}
return sourcePaths;
}
// 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.loadTasks('tasks/');
grunt.file.setBase('.');
grunt.config.set('docsFolder', "./build/output/<%= docsName %>/");
/**
* Build the docs using YUIdocs.
*/
grunt.registerTask('docs', [
"yuidoc", "compress", "copy:docsSite"
]);
/**
* 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);
});
/**
* Task for exporting a next build.
*
*/
grunt.registerTask('next', function () {
grunt.config("buildArgs", this.args || []);
grunt.config("concat.options.banner", "/*!\n * PLATYPUS v<%= pkg.version %>-next\n *\n */");
grunt.task.run(["updateversion", "combine", "uglify", "clearversion", "copy:src", "clearBuildArgs"]);
});
/**
* Task for exporting only the next lib.
*
*/
grunt.registerTask('nextlib', [
"updateversion", "combine", "uglify", "clearversion", "copy:src"
]);
/**
* Task for exporting a release build (version based on package.json)
*
*/
grunt.registerTask('build', function () {
grunt.config("buildArgs", this.args || []);
grunt.config("concat.options.banner", "/*!\n * PLATYPUS v<%= pkg.version %>\n *\n */");
grunt.task.run(["setVersion", "updateversion", "combine", "uglify", "clearversion", "docs", "copy:src", "updatebower", "copy:docsSite", "clearBuildArgs"]);
});
grunt.registerTask('clearBuildArgs', function () {
grunt.config("buildArgs", []);
});
/**
* Task for exporting combined view.
*
*/
grunt.registerTask('combine', 'Combine all source into a single, un-minified file.', [
"concat"
]);
};