gulp
gulp 将开发流程中让人痛苦或耗时的任务自动化,从而减少你所浪费的时间、创造更大价值。
网址:https://www.gulpjs.com.cn/docs/getting-started/quick-start/
来自我们项目中的代码,里面用了CoffeeScript
var gulp = require("gulp");
var coffee = require("gulp-coffee");
var nodemon = require("gulp-nodemon");
var clean = require('gulp-clean');
var path = require("path");
var aglio = require('gulp-aglio');
gulp.task("clean",function(){
var stream = gulp.src("dist")
.pipe(clean());
return stream;
});
gulp.task("copyBin",function(){
var stream = gulp.src("src/bin/**/*")
.pipe(gulp.dest('dist/bin'));
return stream;
});
gulp.task("copyConfig",function(){
var stream = gulp.src("src/config/**/*")
.pipe(gulp.dest('dist/config'));
return stream;
});
gulp.task("copyPublic",function(){
var stream = gulp.src("src/public/**/*")
.pipe(gulp.dest('dist/public'));
return stream;
});
gulp.task("copyViews",function(){
var stream = gulp.src("src/views/**/*")
.pipe(gulp.dest('dist/views'));
return stream;
});
gulp.task('docs', function () {
var stream = gulp.src('src/doc/*.apid')
.pipe(aglio({ template: 'default' }))
.pipe(gulp.dest('dist/public'));
return stream;
});
gulp.task("copyTemplate",function(){
var stream = gulp.src("src/template/**/*")
.pipe(gulp.dest('dist/template'));
return stream;
});
gulp.task("coffee",function(){
var stream = gulp.src("src/**/*.coffee")
.pipe(coffee())
.pipe(gulp.dest('dist'));
return stream;
});
gulp.task("coffee:w", ["coffee"], function () {
watch = gulp.watch("src/**/*.coffee");
watch.on("change",function(event){
file = event.path
dirname = path.dirname(file);
//mac下的改路径
//dirname = dirname.replace(__dirname,"").replace("/src","dist")
//Windows下的改路径
dirname = dirname.replace("src","dist")
gulp.src(event.path)
.pipe(coffee())
.pipe(gulp.dest(dirname));
});
});
gulp.task("start",function () {
nodemon({
script: 'dist/bin/www',
ext: 'js json',
"events": {
"restart": "echo 'display notification \"App restarted due to:\n'$FILENAME'\" with title \"nodemon\"'"
},
env: { 'NODE_ENV': 'development' }
// env: { 'NODE_ENV': 'production' }
});
});
gulp.task("release",["clean"],function(){
gulp.start(["copyBin","copyConfig","copyPublic","copyViews","copyTemplate","coffee"]);
});
gulp.task("dev",["docs","copyBin","copyConfig","copyPublic","copyViews","copyTemplate","coffee","coffee:w"],function(){
gulp.start("start");
});