owhat-job
Version:
owhat红包清理
84 lines (80 loc) • 2.74 kB
JavaScript
const gulp = require('gulp');
const del = require('del');
const rename = require('gulp-rename');
const watch = require('gulp-watch');
const babel = require('gulp-babel');
const combiner = require('stream-combiner');
const notify = require('gulp-notify');
const plumber = require('gulp-plumber');
const paths = {
static: ['./**/*.npcf', './**/*.html', '!./bin/**/*', '!./node_modules/**/*'],
dest: 'bin',
babel: ['./src/**/*.js'],
cleandest: 'bin/**/*.js'
};
gulp.task('clean', function(cb) {
return del([paths.dest], cb);
});
gulp.task('static', ['clean'], function(cb) {
cb.force = true;
gulp.src(paths.static).pipe(watch(paths.static, vinyl => {
if (!vinyl.stat || !vinyl.stat.nlink) {
vinyl.base = vinyl.cwd + '/bin';
console.log('删除:' + vinyl.path);
del([vinyl.path], cb);
} else console.log('同步:' + vinyl.path);
})).pipe(gulp.dest(paths.dest));
});
gulp.task('babel2', ['clean'], function(cb) {
const combined = combiner([
gulp.src(paths.babel),
watch(paths.babel, vinyl => {
if (!vinyl.stat || !vinyl.stat.nlink) {
vinyl.base = vinyl.cwd + '/bin';
//vinyl.extname = '.njs';
console.log('删除:' + vinyl.path);
del([vinyl.path], cb);
} else {
console.log('编译同步:' + vinyl.path);
}
}),
plumber(),
babel({
"presets": [
"env"
],
"plugins": [
[
"transform-runtime",
//"add-module-exports", "transform-decorators-legacy", "transform-class-properties",
{
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}
]
]
}),
gulp.dest(paths.dest),
notify({ message: 'MPC 编译成功!' }),
]);
// any errors in the above streams will get caught
// by this listener, instead of being thrown:
// plumber({
// errorHandler: function (error) {
// console.log(error.message);
// this.emit('end');
// }})
combined.on('error', function() {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: 'MPC 编译失败!',
message: '<%=error.message %>'
}).apply(this, args); //替换为当前对象
this.emit();
});
return combined;
});
gulp.task('default', ['babel2', 'static']);
//todo action ni view moduler check vesh-cli pm2 ngnix cmds