UNPKG

vt2

Version:

vt2

80 lines (79 loc) 3.17 kB
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-combiner2'); const paths = { static: ['./**', '!./bin/**/*', '!./**/action.js', '!./**/*.npcf', '!./**/*.json', '!./index.js', '!./gulpfile.js', '!./node_modules/**/*', '!./log/**/*', '!./ngnix/**/*', '!./tmp/**/*', '!./nginx/**/*'], dest: 'bin', babel: ['./**/action.js', './logic/**/*', '!./bin/**/*', '!./node_modules/**/*'] }; 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('babel', ['clean'], function(cb) { cb.force = true; gulp.src(paths.babel).pipe(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); })).pipe(babel({ presets: ['es2015', 'es2016', 'es2017', 'stage-0'], plugins: ["transform-decorators-legacy", "transform-class-properties"] })).pipe(rename(function(file) { file.extname = '.njs' })).pipe(gulp.dest(paths.dest)); }); gulp.task('babel2', ['clean'], function(cb) { const combined = combiner.obj([ 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); }), babel({ "presets": [ "es2015", 'es2016', 'es2017', 'stage-0' ], "plugins": [ [ "transform-runtime", //"add-module-exports", "transform-decorators-legacy", "transform-class-properties", { "helpers": false, "polyfill": false, "regenerator": true, "moduleName": "babel-runtime" } ] ] }), //{ presets: ['es2015', 'stage-0'] }, rename(function(file) { file.extname = '.njs' }), gulp.dest(paths.dest) ]); // any errors in the above streams will get caught // by this listener, instead of being thrown: combined.on('error', console.error.bind(console)); return combined; }); gulp.task('default', ['static', 'babel2']); //todo action ni view moduler check vesh-cli pm2 ngnix cmds