forked from schteppe/cannon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
94 lines (78 loc) · 2.99 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
var fs = require('fs')
module.exports = function(grunt) {
var bundlePath = "build/cannon.js",
minifiedBundlePath = "build/cannon.min.js";
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: '\n\n'
},
demo : {
src: ['src/demo/Demo.js'],
dest: 'build/cannon.demo.js'
},
},
browserify : {
cannon : {
src : ["src/Cannon.js"],
dest : bundlePath,
options : {
bundleOptions: {
standalone : "CANNON"
}
}
}
},
uglify : {
build : {
src : [bundlePath],
dest : minifiedBundlePath
}
},
yuidoc: {
compile: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options: {
outdir : "docs",
paths : ["./src/"],
},
}
},
nodeunit: {
all: ['test/**/*.js'],
},
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('default', ['test', 'concat', 'browserify', 'uglify', 'addLicense', 'addDate', 'requireJsFix']);
grunt.registerTask('test', ['nodeunit']);
grunt.registerTask('addDate','Adds the current date to the top of the built files',function(){
var text = '// ' + new Date().toUTCString() + '\n';
var dev = fs.readFileSync(bundlePath).toString();
var min = fs.readFileSync(minifiedBundlePath).toString();
fs.writeFileSync(bundlePath,text+"\n"+dev);
fs.writeFileSync(minifiedBundlePath,text+"\n"+min);
});
grunt.registerTask('addLicense','Adds the LICENSE to the top of the built files',function(){
var text = fs.readFileSync("LICENSE").toString();
var dev = fs.readFileSync(bundlePath).toString();
var min = fs.readFileSync(minifiedBundlePath).toString();
fs.writeFileSync(bundlePath,text+"\n"+dev);
fs.writeFileSync(minifiedBundlePath,text+"\n"+min);
});
// Not sure what flag Browserify needs to do this. Fixing it manually for now.
grunt.registerTask('requireJsFix','Modifies the browserify bundle so it works with RequireJS',function(){
[bundlePath, minifiedBundlePath].forEach(function(path){
var text = fs.readFileSync(path).toString();
text = text.replace('define.amd', 'false'); // This makes the bundle skip using define() from RequireJS
fs.writeFileSync(path, text);
});
});
};