forked from piqnt/planck.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
78 lines (72 loc) · 2.36 KB
/
gulpfile.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
var fs = require('fs');
var browserify = require('browserify');
var gulp = require('gulp');
var gutil = require('gulp-util');
var uglify = require('gulp-uglify');
var header = require('gulp-header');
var rename = require('gulp-rename');
var transform = require('vinyl-transform');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var pkg = require('./package.json');
gulp.task('default', ['main', 'testbed']);
gulp.task('main', function() {
var task = browserify({
entries : [ './lib/index.js' ],
standalone : 'planck'
});
task = task.transform({
fromString : true,
compress : false,
mangle : false,
output : {
beautify : true,
comments : /^((?!Copyright)[\s\S])*$/i
}
}, 'uglifyify');
task = task.bundle();
task.on('error', function(err) {
console.log(gutil.colors.red(err.message));
this.emit('end');
});
task = task.pipe(source('planck.js')).pipe(buffer()); // vinylify
task = task.pipe(header(fs.readFileSync('lib/license.js'), { pkg : pkg }));
task = task.pipe(gulp.dest('dist'));
task = task.pipe(rename('planck.min.js'));
task = task.pipe(uglify({compress: {dead_code: true, global_defs: {DEBUG: false, ASSERT: false}}}));
task = task.pipe(header(fs.readFileSync('lib/license.js'), { pkg : pkg }));
task = task.pipe(gulp.dest('dist'));
return task;
});
gulp.task('testbed', function() {
var task = browserify({
entries : [ './testbed/index.js' ],
standalone : 'planck'
});
task = task.transform({
fromString : true,
compress : false,
mangle : false,
output : {
beautify : true,
comments : /license/i
},
preserveComments: 'license',
}, 'uglifyify');
task = task.bundle();
task.on('error', function(err) {
console.log(gutil.colors.red(err.message));
this.emit('end');
});
task = task.pipe(source('planck-with-testbed.js')).pipe(buffer()); // vinylify
task = task.pipe(header(fs.readFileSync('node_modules/stage-js/lib/license.js'), { pkg : {} }));
task = task.pipe(header(fs.readFileSync('lib/license.js'), { pkg : pkg }));
task = task.pipe(gulp.dest('dist'));
task = task.pipe(rename('planck-with-testbed.min.js'));
task = task.pipe(uglify({
compress: {dead_code: true, global_defs: {DEBUG: false, ASSERT: true}},
output : {comments : 'all'}
}));
task = task.pipe(gulp.dest('dist'));
return task;
});