gulpfile.js 2.0 KB
var gulp = require('gulp');
var compass = require('gulp-compass');
var del = require('del');
var gulpFilter = require('gulp-filter');
// var webpack = require('webpack-stream');
// var webpackConfig = require('./tools/webpack.config.production.js');

var paths={
  sass:['./src/scss/*.scss','./src/scss/**/*.scss']
};

gulp.task('compass', function() {
  gulp.src(paths.sass)
    .pipe(compass({
      sourcemap:true,
      css: './src/public/css',
      sass: './src/scss',
      image:'./src/public/img'
    }))
    .pipe(gulp.dest('./build/public/css'));
});

gulp.task('watch',function(){
    gulp.watch(paths.sass,['compass']);
});



gulp.task('clean',function(){ 
  return del([
    '.tmp',
    'build/*',
    '!build/.git'
  ],{
    force: true
  });

});

gulp.task('copy',['clean'],function(){
	var f=gulpFilter(['src/public','src/public/**/*','package.json','src/content','src/content/**/*']);
	return gulp.src([
		'./package.json',
		'./src/**/*'
    ])
    .pipe(f)
    .pipe(gulp.dest('./build'));
});

/*copy vendor*/
gulp.task('copy-vendor',function(){ 
  return gulp.src([ 
    './src/public/vendor.*.js'
    ]) 
    .pipe(gulp.dest('./build/public'));
});

gulp.task('start',['copy'],function(done){
  runBundle('npm start', done);
});
 

gulp.task('build',['copy'],function(){ 
    return gulp.src(webpackConfig.entry.app)
    .pipe(webpack(webpackConfig))
    .pipe(gulp.dest('./build/public'));
});

gulp.task('deploy',['build'],function(done){
    runBundle('node ./server/app.js', done);
});


function runBundle(cmd, done) {
  var exec = require('child_process').exec;  
  var ls=exec(cmd, function(e, stdout) { 
    done();
  });

  ls.stdout.on('data', function (data) {
    console.log(data);
  });

  ls.stderr.on('data', function (data) {
    console.log(data);
  });

  ls.on('exit', function (code) {
    console.log('child process exited with code ' + code);
  });
      
  ls.on('uncaughtException', function (err) {
    console.log('Caught exception: ' + err);
  });
}