-
Notifications
You must be signed in to change notification settings - Fork 57
/
gulpfile.js
72 lines (61 loc) · 1.84 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
const { src, dest, series, watch } = require('gulp');
const uitest = require('gulp-uitest');
const replace = require('gulp-replace');
const concat = require('gulp-concat');
const pkg = require('./package.json');
const testBuildTask = () => {
return src('test/spec/**/*.js')
.pipe(replace(/^/, '(function(){\n'))
.pipe(replace(/$/, '\n})();\n'))
.pipe(concat('hilo3d.test.js'))
.pipe(dest('test/'));
};
const testTask = () => {
return src('test/index.html')
.pipe(uitest({
width: 600,
height: 480,
hidpi: false,
useContentSize: true,
show: false
}));
};
const hilo3dTSDHeader = `export = hilo3d;
export as namespace hilo3d;
declare namespace hilo3d {
type TypedArray =
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array;
`;
const hilo3dTSDFooter = `
}
`;
const addHilo3dTSD = () => {
return src('./types/index.d.ts')
.pipe(replace(/declare\s/g, ''))
// Fix Hilo3d.log.func return namespace bug
.pipe(replace(/:\slog;/g, ': typeof log;'))
.pipe(replace(/^/, hilo3dTSDHeader))
.pipe(replace(/$/, hilo3dTSDFooter))
.pipe(dest('types'));
};
const readmeTask = () => {
return src(['./README.md', './README_ZH.md'])
// //cdn.jsdelivr.net/npm/[email protected]/build/Hilo3d.js
.pipe(replace(/\/hilo3d@[\d\.\w\-]+\/build\/Hilo3d\.js/g, `/hilo3d@${pkg.version}/build/Hilo3d.js`))
.pipe(dest('./'));
};
const watchTask = () => {
watch(['test/spec/**/*.js'], series(testBuildTask, testTask));
};
exports.test = series(testBuildTask, testTask);
exports.watch = series(testBuildTask, testTask, watchTask);
exports.readme = readmeTask;
exports.addHilo3dTSD = addHilo3dTSD;