Created
April 28, 2015 21:10
-
-
Save captainill/057a9838c7a53198a9da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var gulp = require('gulp'); | |
var argv = require('yargs').argv; | |
var sass = require('gulp-sass'); | |
var gutil = require('gulp-util'); | |
var bless = require('gulp-bless'); | |
var insert = require('gulp-insert'); | |
var concat = require('gulp-concat'); | |
var rename = require('gulp-rename'); | |
var replace = require('gulp-replace'); | |
var uglify = require('gulp-uglifyjs'); | |
var webpack = require('webpack'); | |
var ttf2woff = require('gulp-ttf2woff'); | |
var cssfont64 = require('gulp-cssfont64'); | |
var minifycss = require('gulp-minify-css'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var runSequence = require('run-sequence'); | |
var package = require('./package.json'); | |
var production = argv.production ? true : false; | |
var port = argv.port ? argv.port : 8080; | |
/* file patterns to watch */ | |
var paths = { | |
js: ['app/**/*.js', 'app/**/*.jsx', 'appadmin/**/*.js', 'appadmin/**/*.jsx'], | |
mainscss: ['sass/main.scss', 'sass/pages/**/*.scss'], | |
adminscss: ['sass/admin.scss', 'sass/admin/**/*.scss'], | |
bootstrap: ['sass/vendor/*.scss', 'sass/vender/**/*.scss'] | |
}; | |
var banner = function() { | |
return '/*! '+package.name+' - v'+package.version+' - '+gutil.date(new Date(), "yyyy-mm-dd")+ | |
' [copyright: '+package.copyright+']'+' */'; | |
}; | |
function logData(data) { | |
gutil.log( | |
gutil.colors.blue( | |
gutil.colors.bold(data) | |
) | |
); | |
} | |
logData('PORT : '+ port); | |
logData('Environment : '+ (production ? 'Production':'Development')); | |
/* ---------------------------------- */ | |
/* --------- BEGIN SASS ---------- */ | |
/* ---------------------------------- */ | |
gulp.task('sass:main', function() { | |
return gulp.src('./sass/main.scss') | |
.pipe(sass({ | |
// sourceComments: 'normal' // uncomment when https://github.com/sass/node-sass/issues/337 is fixed | |
})) | |
.pipe(autoprefixer('last 2 versions', '> 1%', 'ie 9')) | |
.pipe(insert.prepend(banner()+'\n')) | |
.pipe(insert.prepend('@charset "UTF-8";\n')) | |
.pipe(gulp.dest('public/css/')); | |
}); | |
gulp.task('sass:admin', function() { | |
return gulp.src('./sass/admin.scss') | |
.pipe(sass({ | |
// sourceComments: 'normal' // uncomment when https://github.com/sass/node-sass/issues/337 is fixed | |
})) | |
.pipe(autoprefixer('last 2 versions', '> 1%', 'ie 9')) | |
.pipe(insert.prepend(banner()+'\n')) | |
.pipe(insert.prepend('@charset "UTF-8";\n')) | |
.pipe(gulp.dest('public/css/')); | |
}); | |
/*gulp.task('minifycss', function() { | |
return gulp.src(['public/css/*.css']) | |
.pipe(minifycss()) | |
.pipe(gulp.dest('public/css/min')); | |
}); | |
gulp.task('blesscss', function() { | |
return gulp.src(['public/css/*.css']) | |
.pipe(bless()) | |
.pipe(insert.prepend(banner()+'\n')) | |
.pipe(insert.prepend('@charset "UTF-8";\n')) | |
.pipe(gulp.dest('public/css/blessed')); | |
});*/ | |
/* -------------------------------- */ | |
/* --------- END SASS ---------- */ | |
/* -------------------------------- */ | |
/* ------------------------------- */ | |
/* --------- BEGIN BOOTSRAP SASS --------- */ | |
/* ------------------------------- */ | |
gulp.task('sass:bootstrap', function() { | |
//file used as entry point can not lead with _ (underscore) as they are ignored as partials | |
return gulp.src('./sass/vendor/bootstrap.scss') | |
.pipe(sass({ | |
// sourceComments: 'normal' // uncomment when https://github.com/sass/node-sass/issues/337 is fixed | |
})) | |
.pipe(gulp.dest('public/css/')); | |
}); | |
/* ------------------------------- */ | |
/* --------- END BOOTSRAP SASS --------- */ | |
/* ------------------------------- */ | |
/* ------------------------------- */ | |
/* --------- BEGIN WEBPACK --------- */ | |
/* ------------------------------- */ | |
gulp.task('webpack:build:js', function(callback) { | |
var webpackConfig = require('./webpack.config'); | |
var bundler = webpack(webpackConfig, function(err, stats) { | |
if(err) throw new gutil.PluginError("webpack", err); | |
/*gutil.log("[webpack]", stats.toString({ | |
// output options | |
}));*/ | |
//callback(); | |
}) | |
bundler.run(function(){ | |
return callback(); | |
}); | |
}); | |
gulp.task("build", ["webpack:build:js"]); | |
/* ------------------------------- */ | |
/* --------- END WEBPACK --------- */ | |
/* ------------------------------- */ | |
/* --------------------------------- */ | |
/* --------- BEGIN EXPRESS --------- */ | |
/* --------------------------------- */ | |
/*var child = null; | |
gulp.task('express', function() { | |
if(child) child.kill(); | |
child = child_process.spawn(process.execPath, ['./service.js'], { | |
env: { | |
NODE_ENV: process.env.NODE_ENV, | |
APP: defaultAppName, | |
//RTL: createRTL, | |
PORT: port | |
} | |
}); | |
child.stdout.on('data', function(data) { | |
gutil.log(gutil.colors.bgCyan(gutil.colors.blue(data.toString().trim()))); | |
}); | |
child.stderr.on('data', function(data) { | |
gutil.log(gutil.colors.bgRed(gutil.colors.white(data.toString().trim()))); | |
}); | |
process.on('uncaughtException', function(err) { | |
if(child) child.kill(); | |
throw new Error(err); | |
}); | |
});*/ | |
/* ------------------------------- */ | |
/* --------- END EXPRESS --------- */ | |
/* ------------------------------- */ | |
gulp.task('default', function(callback) { | |
runSequence('sass:main', 'sass:admin', 'sass:bootstrap', 'webpack:build:js', ['watch'], callback); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch(paths.js, ['webpack:build:js']); | |
gulp.watch(paths.mainscss, ['sass:main']); | |
gulp.watch(paths.adminscss, ['sass:admin']); | |
}); | |
function ready() { | |
gutil.log( | |
gutil.colors.bgMagenta( | |
gutil.colors.red( | |
gutil.colors.bold('[ STATUS: READY ]') | |
) | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment