10 Star 77 Fork 6

scottxu/openBSE

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gulpfile.js 3.46 KB
一键复制 编辑 原始数据 按行查看 历史
徐誉诚 提交于 2020-09-27 16:05 . 优化代码,分离glsl脚本
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'));
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/scott-xu/openBSE.git
[email protected]:scott-xu/openBSE.git
scott-xu
openBSE
openBSE
master

搜索帮助