Skip to content

Commit

Permalink
Update gulp to v4
Browse files Browse the repository at this point in the history
  • Loading branch information
th0r committed Jan 30, 2018
1 parent 8bdc420 commit 3ff94db
Show file tree
Hide file tree
Showing 4 changed files with 560 additions and 554 deletions.
109 changes: 0 additions & 109 deletions gulpfile.babel.js

This file was deleted.

75 changes: 75 additions & 0 deletions gulpfile.js
@@ -0,0 +1,75 @@
'use strict';

const gulp = require('gulp');

const NODE_SRC = './src/**/*.js';
const NODE_DEST = './lib';

const cli = require('commander')
.usage('<task> [options]')
.option('-e, --env <environment>', 'Can be `prod` or `dev`. Default is `dev`', /^(dev|prod)$/, 'dev')
.option('-a, --analyze', 'Analyze client bundle. If set, `env` will be set to `prod`.')
.parse(process.argv);

let watching = false;
const task = cli.args[0] || 'watch';
if (task === 'build' || cli.analyze) {
cli.env = 'prod';
}

gulp.task('clean', gulp.parallel(cleanNodeScripts, cleanViewerScripts));
gulp.task('build', gulp.series('clean', compileNodeScripts, compileViewerScripts));
gulp.task('watch', gulp.series('build', watch));
gulp.task('default', gulp.task('watch'));

function watch() {
watching = true;
gulp.watch(NODE_SRC, gulp.series(cleanNodeScripts, compileNodeScripts));
}

function cleanViewerScripts() {
const del = require('del');
return del('public');
}

function cleanNodeScripts() {
const del = require('del');
return del(NODE_DEST);
}

function compileNodeScripts() {
const babel = require('gulp-babel');
const plumber = require('gulp-plumber');
const noop = require('gulp-noop');

return gulp
.src(NODE_SRC)
.pipe(watching ? plumber() : noop())
.pipe(babel())
.pipe(gulp.dest(NODE_DEST));
}

function compileViewerScripts() {
const webpack = require('webpack');
const config = require('./webpack.config')({
env: cli.env,
analyze: cli.analyze
});

return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (cli.env === 'dev') {
if (err) {
console.error(err);
} else {
console.log(stats.toString({ colors: true }));
}
resolve();
} else {
if (err) return reject(err);
console.log(stats.toString({ colors: true }));
resolve();
}
});
});
}
7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -62,11 +62,10 @@
"eslint": "3.19.0",
"eslint-plugin-react": "7.0.0",
"exports-loader": "0.6.4",
"gulp": "3.9.1",
"gulp-babel": "6.1.2",
"gulp": "4.0.0",
"gulp-babel": "7.0.1",
"gulp-noop": "1.0.0",
"gulp-plumber": "1.2.0",
"gulp-util": "3.0.8",
"gulp-watch": "5.0.0",
"mocha": "5.0.0",
"nightmare": "2.10.0",
"preact": "8.2.7",
Expand Down

0 comments on commit 3ff94db

Please sign in to comment.