Skip to content

Instantly share code, notes, and snippets.

@jxm262
Created March 5, 2015 17:15
Show Gist options
  • Save jxm262/a9a154449628f235373a to your computer and use it in GitHub Desktop.
Save jxm262/a9a154449628f235373a to your computer and use it in GitHub Desktop.
(function () {
//Used for jsx to js transformations during mocha tests
require('./test/configs/jsxcompiler.js');
var gulp = require('gulp');
var gutil = require('gulp-util');
var nodemon = require('gulp-nodemon');
var less = require('gulp-less');
var rimraf = require('rimraf');
var gulp = require('gulp');
var exit = require('gulp-exit');
var watchify = require('watchify');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var react = require('gulp-react');
var tap = require('gulp-tap');
//paths
var src_site_root = "site";
var src_site_js = src_site_root + "/js";
var components_path = "bower_components";
var modules_path = "node_modules";
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var app = "" + "api/server.js";
var paths = {
css: './site/css',
jsx: './site/js',
jsx_entry: './site/js/app.jsx',
html: './site/*.html',
dist: './dist',
buildfile: 'app.js'
};
var err = function () {
var x;
x = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
gutil.log.apply(gutil, x);
return gutil.beep.apply(gutil, x);
};
gulp.task('run', function () {
return nodemon({
script: app,
watch: [app],
env: {
PORT: process.env.PORT || 3000
}
});
});
gulp.task('test-api', function (cb) {
gulp.src(['api/**/*.js'])
.pipe(istanbul()) // Covering files
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function () {
gulp.src(['test/api/*.js'])
.pipe(mocha())
.pipe(istanbul.writeReports(
{
dir: './coverage',
reporters: [ 'html', 'lcov', 'json', 'text', 'text-summary' ]
})) // Creating the reports after tests runned
.on('end', cb);
});
});
gulp.task('test-site', function () {
gulp.src(["test/site/js/*.js"], {
read: false
})
.pipe(mocha({
reporter: 'spec'
}))
.pipe(exit());
});
gulp.task('watch', function() {
gulp.watch(paths.html, ['copy']);
var watcher = watchify(browserify({
entries: [paths.jsx_entry],
transform: ['reactify'],
extensions: ['.jsx'],
debug: true,
cache: {}, packageCache: {}, fullPaths: true
}));
return watcher.on('update', function () {
watcher.bundle()
.pipe(source(paths.buildfile))
.pipe(gulp.dest(paths.dist))
console.log('Updated');
})
.bundle()
.pipe(source(paths.buildfile))
.pipe(gulp.dest(paths.dist));
});
gulp.task('jsx', function() {
browserify({
insertGlobals : true,
entries: [paths.jsx_entry],
transform: ['reactify'],
extensions: ['.jsx'],
debug :false
})
.bundle()
.pipe(source(paths.buildfile))
//.pipe(streamify(uglify(paths.buildfile))) // minify/uglify
.pipe(gulp.dest(paths.dist));
});
gulp.task('css', function () {
return gulp.src("" + src_site_root + "/styles/*.less")
.pipe(less({
paths: [components_path, modules_path]
}))
.on('error', err)
.pipe(gulp.dest(paths.dist));
});
gulp.task('clean', function () {
return rimraf.sync(paths.dist);
});
gulp.task('copy', function(){
gulp.src(paths.html)
.pipe(gulp.dest(paths.dist));
});
gulp.task('test', ['test-site', 'test-api']);
gulp.task('ci_build', ['build', 'test-site'])
gulp.task('build', ['clean', 'copy', 'css', 'jsx']);
gulp.task('dev', ['clean', 'copy', 'css', 'run', 'watch']);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment