forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
89 lines (77 loc) · 2.38 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
79
80
81
82
83
84
85
86
87
88
const fs = require('fs');
const gulp = require('gulp');
const rename = require('gulp-rename');
const header = require('gulp-header');
const browserSync = require('browser-sync');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const pkg = require('./package.json');
const jsprettify = require('gulp-jsbeautifier');
const stripComments = require('gulp-strip-comments');
const merge = require('merge-stream');
gulp.task('build', function() {
const gpu = browserify('./src/browser.js')
.ignore('gl')
.bundle()
.pipe(source('gpu-browser.js'))
.pipe(buffer())
.pipe(stripComments())
.pipe(header(fs.readFileSync('./src/browser-header.txt', 'utf8'), { pkg : pkg }))
.pipe(gulp.dest('bin'))
.on('error', console.error);
const gpuCore = browserify('./src/browser.js')
.ignore('gl')
.ignore('acorn')
.bundle()
.pipe(source('gpu-browser-core.js'))
.pipe(buffer())
.pipe(stripComments())
.pipe(header(fs.readFileSync('./src/browser-header.txt', 'utf8'), { pkg : pkg }))
.pipe(gulp.dest('bin'))
.on('error', console.error);
return merge(gpu, gpuCore);
});
/// Minify the build script, after building it
gulp.task('minify', function() {
const gpu = gulp.src('bin/gpu-browser.js')
.pipe(rename('gpu-browser.min.js'))
.pipe(header(fs.readFileSync('./src/browser-header.txt', 'utf8'), { pkg : pkg }))
.pipe(gulp.dest('bin'))
.on('error', console.error);
const gpuCore = gulp.src('bin/gpu-browser-core.js')
.pipe(rename('gpu-browser-core.min.js'))
.pipe(header(fs.readFileSync('./src/browser-header.txt', 'utf8'), { pkg : pkg }))
.pipe(gulp.dest('bin'))
.on('error', console.error);
return merge(gpu, gpuCore);
});
/// The browser sync prototyping
gulp.task('bsync', function(){
// Syncs browser
browserSync.init({
server: {
baseDir: './'
},
open: true,
startPath: "./test/html/test-all.html",
// Makes it easier to test on external mobile devices
host: "0.0.0.0",
tunnel: true
});
// Detect change -> rebuild TS
gulp.watch(['src/**.js'], ['minify']);
});
/// Auto rebuild and host
gulp.task('default', gulp.series('minify','bsync'));
/// Beautify source code
/// Use before merge request
gulp.task('beautify', function() {
return gulp.src(['src/**/*.js'])
.pipe(jsprettify({
indent_size: 3,
indent_char: ' ',
indent_with_tabs: true
}))
.pipe(gulp.dest('src'));
});