Skip to content

Instantly share code, notes, and snippets.

@limdauto
Created December 30, 2014 08:43
Show Gist options
  • Save limdauto/2d77f4052b3d3752a038 to your computer and use it in GitHub Desktop.
Save limdauto/2d77f4052b3d3752a038 to your computer and use it in GitHub Desktop.
Lim's todojs build
'use strict';
var _ = require('lodash'),
browserify = require('browserify'),
compass = require('gulp-compass'),
concat = require('gulp-concat'),
conf = require('config'),
console = require('console-browserify'),
del = require('del'),
gulp = require('gulp'),
gutil = require('gulp-util'),
minifyCss = require('gulp-minify-css'),
seq = require('run-sequence'),
source = require('vinyl-source-stream'),
sprintf = require('sprintf'),
streamify = require('gulp-streamify'),
uglify = require('gulp-uglify');
// list of apps
var apps = ['todo-mithril-mocha'];
gulp.task('clean', function(cb) {
del([sprintf('%s/css/*.css', conf.DIST), sprintf('%s/js/*.js', conf.DIST)]);
});
gulp.task('deploy', ['build'], function() {
// nothing here yet
// @TODO: separate default task (dev) with deploy by uglify for deploy and add source map
});
gulp.task('default', ['build'] ,function() {
// nothing here yet, adding source map maybe?
});
gulp.task('build', function() {
seq('js', 'css');
});
gulp.task('test', ['js:test'], function() {});
/************************************
* JAVASCRIPT TASKS
************************************/
function parseModule(name, targetTask) {
return require(sprintf('%s/%s/%s', conf.NODE_ROOT, name, conf.TASK_CONF))[targetTask];
}
// build tasks
gulp.task('js', _.map(apps, function(app) { return sprintf('js:%s', app); }), function() {});
_.forEach(apps, function(app) {
gulp.task(sprintf('js:%s', app), parseModule(app, 'build'));
});
// test tasks
gulp.task('js:test', _.map(apps, function(app) { return sprintf('js:%s:test', app); }), function() {});
_.forEach(apps, function(app) {
gulp.task(sprintf('js:%s:test', app), parseModule(app, 'test'));
});
/************************************
* CSS TASKS
************************************/
gulp.task('css', ['css:lib', 'css:compass'], function() {
return gulp.src([
sprintf('css/%s', conf.LIB_CSS),
sprintf('css/%s', conf.MAIN_CSS)
])
.pipe(concat(conf.MAIN_CSS))
.pipe(minifyCss())
.pipe(gulp.dest(sprintf("%s/css", conf.DIST)));
});
gulp.task('css:lib', function() {
return gulp.src([
sprintf('%s/normalize.css/normalize.css', conf.BOWER)
])
.pipe(concat(conf.LIB_CSS))
.pipe(gulp.dest('css'));
});
gulp.task('css:compass', function () {
return gulp.src(conf.SASS)
.pipe(compass({
css: 'css/',
sass: 'css/sass/'
}))
.pipe(concat(conf.MAIN_CSS))
.pipe(gulp.dest('css'));
});
@limdauto
Copy link
Author

config.js will look like this

module.exports = {
    DIST : './dist',
    BOWER : './bower_components',
    SASS : './css/sass/*.scss',
    NODE_ROOT : './node_modules',
    TASK_CONF : 'task.js',
    MAIN_CSS : 'main.css',
    LIB_CSS : 'lib.css'
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment