-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgulpfile.js
118 lines (106 loc) · 3.46 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
const gulp = require('gulp');
const bro = require('gulp-bro');
const uglify = require('gulp-uglify');
const rename = require("gulp-rename");
const header = require('gulp-header');
const jsdoc = require('gulp-jsdoc3');
const jeditor = require('gulp-json-editor');
const glsl = require('gulp-glsl');
const sourcemaps = require('gulp-sourcemaps');
const babel = require("gulp-babel");
const eslint = require('gulp-eslint');
const addsrc = require('gulp-add-src');
const fs = require('fs-extra');
const buildConfig = require('./build.json');
const packageConfig = require('./package.json');
gulp.task('doc', (cb) => {
let config = require('./jsdoc.json');
config.opts.destination = `./docs/${/^[0-9]*.[0-9]*/.exec(packageConfig.version)}`;
gulp.src(['README.md', 'src/**/*.js', '!src/lib/**/*', '!src/renderers/**/*'], { read: false })
.pipe(jsdoc(config, cb));
});
gulp.task('es6', gulp.series(gulp.parallel(() => {
return gulp.src("./build.json")
.pipe(jeditor({
'buildDate': new Date().toUTCString(),
'version': packageConfig.version
}))
.pipe(gulp.dest('dist'))
}, () => {
return gulp.src('src/lib/resources.json')
.pipe(gulp.dest('dist/lib'))
}),
() => {
return gulp.src('src/**/*.glsl')
.pipe(sourcemaps.init())
.pipe(glsl({
es6: true
}))
.pipe(addsrc([
'src/**/*.js',
'!src/lib/JS-Interpreter/acorn_interpreter.js',
'!src/lib/JS-Interpreter/demos/**/*']))
.pipe(babel({
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: 3
}
]
],
shouldPrintComment: (val) => /^\*/.test(val)
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'));
}));
gulp.task('browserify', () => {
let license = fs.readFileSync('./LICENSE').toString();
return gulp.src('dist/app.js')
.pipe(bro({
debug: true
}))
.pipe(rename(`${buildConfig.name}.all.js`))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(header('/*!\n${license}\nHome: ${home}\n*/\n', { license: license, home: buildConfig.home }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist'))
});
gulp.task('min', () => {
return gulp.src(`dist/${buildConfig.name}.all.js`)
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify({
compress: {
passes: 10
},
output: {
comments: '/^!/'
}
}))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist'))
});
gulp.task('eslint', () => {
return gulp.src(['src/*.js', 'src/*.ts'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
});
gulp.task('copy', () => {
return gulp.src('src/openBSE.d.ts')
.pipe(gulp.dest('dist'))
});
gulp.task('build', gulp.parallel(
gulp.series('es6', 'browserify', 'min'),
gulp.series('copy'))
);
gulp.task('changename', () => {
return gulp.src("./package.json")
.pipe(jeditor({
'name': "@iamscottxu/openbse"
}))
.pipe(gulp.dest('./'))
});
gulp.task('default', gulp.parallel('build', 'doc'));