UNPKG

jig-framework

Version:

Start building JavaScript apps fast with Bootstrap, React, Mocha, Chai, and Gulp

101 lines (98 loc) 3.06 kB
// Dependencies // var autoprefixer = require('gulp-autoprefixer'); var del = require('del'); var gulp = require('gulp'); var babel = require('gulp-babel'); var browserify = require('gulp-browserify'); var concat = require('gulp-concat'); var jshint = require('gulp-jshint'); // From: https://github.com/johnpapa/gulp-patterns/blob/master/gulpfile.js var $ = require('gulp-load-plugins')({lazy: true}); var mocha = require('gulp-mocha'); var sass = require('gulp-sass'); var gutil = require('gulp-util'); // Task: styles gulp.task('styles', function() { return gulp.src('styles/*.scss') .pipe(sass({ 'sourcemap=none': true }) .on('error', gutil.log)) .pipe(concat('style.css')) // .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1')) .pipe(gulp.dest('./public/')); }); // Task: main (jsx) gulp.task('main.jsx', function() { return gulp.src('src/main.jsx') .pipe(babel()) .on('error', gutil.log) .pipe(browserify({ insertGlobals: true, transform: 'reactify', // The React documentation seems to say use "babelify". debug: !gulp.env.production }) .on('error', gutil.log)) .pipe(concat('application.js')) .pipe(gulp.dest('./public/')); }); // // Task: js // gulp.task('js', ['cjsx', 'jsx'], function() { // return gulp.src('src/*.js') // .pipe(gulp.dest('./public/')); // }); // Task: html gulp.task('html', function() { return gulp.src('src/*.html') .pipe(gulp.dest('./public/')); }); // // Task: jsx // gulp.task('jsx', function() { // return gulp.src('src/*.jsx') // .pipe(babel()) // .pipe(gulp.dest('./public/')); // }); // Task: watch gulp.task('watch', function() { // By doing "**", it also rebuilds application.js when you add or delete // a source file. gulp.watch(['src/**'], ['main.jsx']); gulp.watch('styles/*.scss', ['styles']); // gulp.watch('src/*.js', ['js']); // gulp.watch('src/*.jsx', ['jsx']); gulp.watch('src/*.html', ['html']); }); /*Only run jshint on source JavaScript. Browserify, for example, produces code that doesn't pass jshint. */ // Task: jshint gulp.task('jshint', function() { return gulp.src('src/*.js') .pipe(jshint()) .pipe(jshint.reporter('jshint-stylish')); }); // Task: test gulp.task('test', function() { return gulp.src(['test/*.js'], { read: false }) .pipe(mocha({ reporter: 'list' })) .on('error', gutil.log); }); gulp.task('watch-mocha', function() { gulp.watch(['src/**', 'test/**'], ['test']); }); // Default task gulp.task('default', ['main.jsx', 'styles', 'html', 'jshint', 'watch', 'watch-mocha']); // Task: clean // Remove all the generated files from public. // Assume all files are to be removed. gulp.task('clean', function(done) { // The double glob "**" matches the parent, too, which is problematic for clean // See: https://github.com/sindresorhus/del/issues/3 var delconfig = [].concat('public/*'); gutil.log('Cleaning: ' + $.util.colors.red(delconfig)); del(delconfig, done); });