Skip to content

Commit

Permalink
add lazypipes to consolidate some repetition on stream chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Oct 21, 2015
1 parent c6044e6 commit b844a79
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@
* limitations under the License.
*/

var gulp = require('gulp-help')(require('gulp'));
var autoprefixer = require('autoprefixer');
var babel = require('babelify');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var cssnano = require('cssnano');
var del = require('del');
var file = require('gulp-file');
var gulpWatch = require('gulp-watch');
var fs = require('fs-extra');
var sourcemaps = require('gulp-sourcemaps');
var gulp = require('gulp-help')(require('gulp'));
var gulpWatch = require('gulp-watch');
var lazypipe = require('lazypipe');
var postcss = require('postcss');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var util = require('gulp-util');
var watchify = require('watchify');
var wrap = require('gulp-wrap');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var babel = require('babelify');
var postcss = require('postcss');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
require('./build-system/tasks');

// NOTE: see https://github.com/ai/browserslist#queries for `browsers` list
Expand Down Expand Up @@ -393,16 +394,22 @@ function compileJs(srcDir, srcFilename, destDir, options) {

var wrapper = options.wrapper || '<%= contents %>';

var lazybuild = lazypipe()
.pipe(source, srcFilename)
.pipe(buffer)
.pipe(replace, /\$internalRuntimeVersion\$/g, internalRuntimeVersion)
.pipe(wrap, wrapper)
.pipe(sourcemaps.init.bind(sourcemaps), { loadMaps: true });

var lazywrite = lazypipe()
.pipe(sourcemaps.write.bind(sourcemaps), './')
.pipe(gulp.dest.bind(gulp), destDir);

function rebundle() {
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source(srcFilename))
.pipe(buffer())
.pipe(replace(/\$internalRuntimeVersion\$/g, internalRuntimeVersion))
.pipe(wrap(wrapper))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(destDir));
.pipe(lazybuild())
.pipe(lazywrite());
}

if (options.watch) {
Expand All @@ -416,17 +423,12 @@ function compileJs(srcDir, srcFilename, destDir, options) {
console.log('Minifying ' + srcFilename);
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source(srcFilename))
.pipe(buffer())
.pipe(replace(/\$internalRuntimeVersion\$/g, internalRuntimeVersion))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(wrap(wrapper))
.pipe(lazybuild())
.pipe(uglify({
preserveComments: 'some'
}))
.pipe(rename(options.minifiedName))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(destDir))
.pipe(lazywrite())
.on('end', function() {
fs.writeFileSync(destDir + '/version.txt', internalRuntimeVersion);
if (options.latestName) {
Expand Down

0 comments on commit b844a79

Please sign in to comment.