UNPKG

mpc-cli

Version:

码农村nodejs版本myprocesscontroller框架脚手架搭建器

80 lines (79 loc) 2.66 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-combiner'); const notify = require('gulp-notify'); const paths = { static: ['./**/*.npcf', '!./bin/**/*', '!./node_modules/**/*'], dest: 'bin', babel: ['./src/**/*.js'], cleandest: 'bin/**/*.js' }; let timeout = 0; const restart = function() { if (!timeout) timeout = setTimeout(function() { gulp.stop('babel2'); gulp.start('babel2'); console.log('restart'); //if (timeout) restart(); }, 5000); }; 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); } }), 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: combined.on('error', e => { gulp.src(paths.babel).pipe(notify({ message: 'MPC 编译错误:' + e.message })); restart(); }); return combined; }); gulp.task('default', ['babel2', 'static']); //todo action ni view moduler check vesh-cli pm2 ngnix cmds