forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
135 lines (114 loc) · 3.1 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
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
'use strict';
const fs = require('fs');
const gulp = require('gulp');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const gutil = require('gulp-util');
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 babel = require('gulp-babel');
const stripComments = require('gulp-strip-comments');
const merge = require('merge-stream');
/// Build the scripts
gulp.task('babelify', function () {
return gulp.src(['./src/**'])
.pipe(babel())
.pipe(gulp.dest('dist'));
});
gulp.task('build', gulp.series('babelify', function() {
const gpu = browserify('./dist/index.js')
.bundle()
.pipe(source('gpu.js'))
.pipe(buffer())
.pipe(stripComments())
.on('error', console.error)
.pipe(header(fs.readFileSync('./dist/wrapper/header.js', 'utf8'), { pkg : pkg }))
.pipe(gulp.dest('bin'));
const gpuCore = browserify('./dist/index-core.js')
.bundle()
.pipe(source('gpu-core.js'))
.pipe(buffer())
.pipe(stripComments())
.on('error', console.error)
.pipe(header(fs.readFileSync('./dist/wrapper/header.js', 'utf8'), { pkg : pkg }))
.pipe(gulp.dest('bin'));
return merge(gpu, gpuCore);
}));
/// Minify the build script, after building it
gulp.task('minify', function() {
const gpu = gulp.src('bin/gpu.js')
.pipe(rename('gpu.min.js'))
.pipe(
uglify({preserveComments: 'license'})
.on('error', gutil.log)
)
.pipe(gulp.dest('bin'));
const gpuCore = gulp.src('bin/gpu-core.js')
.pipe(rename('gpu-core.min.js'))
.pipe(
uglify({preserveComments: 'license'})
.on('error', gutil.log)
)
.pipe(gulp.dest('bin'));
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'));
});
gulp.task('injectCSS', function() {
let signatureColor = '#ff75cf';
let linkColor = '#4c7fbd';
let themeColor = '#186384';
// !important is used because the original rule is using it.
let cssRules = `
.signature, a {
color: ${signatureColor};
}
h4.name {
background: ${themeColor};
}
nav > ul > li > a, nav a:hover, nav > h2 > a {
color: ${linkColor} !important;
}
span.param-type, .params td .param-type {
color: ${themeColor};
}
`;
fs.appendFile('./doc/styles/jsdoc.css', cssRules, (err)=>{
if(err){
throw new Error(err);
}
console.log('CSS Injected');
});
});