Skip to content

Commit

Permalink
node-v10.2.1 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
saedwards committed Jun 6, 2018
1 parent 786a779 commit 76111a0
Show file tree
Hide file tree
Showing 7 changed files with 1,739 additions and 756 deletions.
112 changes: 64 additions & 48 deletions gulp/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,79 @@ const watchify = require('watchify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gutil = require('gulp-util');
const vinyl = require('vinyl');
const through2 = require('through2');

const rollupBabel = require('rollup-plugin-babel');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');

function bundleScripts (watch, opts) {
opts = opts || {};
function bundleScripts(watch, opts = {}) {

const bundler = browserify({
entries: [opts.path],
debug: true,
plugin: [watch ? watchify : null]
})
.on('update', () => bundle())
.on('log', gutil.log)
.on('error', gutil.log)
.transform('rollupify', {
config: {
cache: false,
entry: opts.path,
plugins: [
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/events/events.js': Object.keys(require('events'))
}
}),
nodeResolve({
jsnext: true,
main: true,
preferBuiltins: false
}),
rollupBabel({
plugins: ['lodash'],
presets: ['es2015-rollup', 'stage-2'],
babelrc: false,
exclude: 'node_modules/**'
})
]
}
});
const bundler = function() {
const b = browserify({
entries: opts.path,
debug: true,
plugin: [watch ? watchify : null]
})
.on('log', gutil.log)
.on('error', gutil.log)
.transform('rollupify', {
config: {
onwarn: function(message) {
if (message.code === 'THIS_IS_UNDEFINED') {
return;
}
console.error(message);
},
plugins: [
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/events/events.js': Object.keys(require('events'))
}
}),
nodeResolve({
jsnext: true,
main: true,
preferBuiltins: false
}),
rollupBabel({
plugins: ['lodash'],
presets: ['es2015-rollup', 'stage-2'],
babelrc: false,
exclude: 'node_modules/!**'
})
]
}
}),
stream = through2.obj(function(file, enc, next) {
// add each file to the bundle
b.add(file.path);
next();
}, function(next) {
b.bundle(function(err, src) {
if (err) {
throw err;
}

const bundle = () => {
return bundler
.bundle()
.on('error', function(err) {
gutil.log(err.message);
this.emit('end');
})
.pipe(source(opts.filename || 'bundle.js'))
.pipe(buffer())
.pipe(gulp.dest(opts.dest));
};
// create a new vinyl file with bundle contents
// and push it to the stream
stream.push(new vinyl({
path: opts.filename || 'bundle.js', // this path is relative to dest path
contents: src
}));
next();
});
});
return stream;
};

return bundle();
return gulp.src(opts.path)
.pipe(bundler())
.pipe(gulp.dest(opts.dest));
}

module.exports = {
bundleScripts: bundleScripts
bundleScripts: bundleScripts
};
28 changes: 19 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const reporter = require('postcss-reporter');
const inlineblock = require('postcss-inline-block');
const sourcemaps = require('gulp-sourcemaps');
const svgSprite = require('gulp-svg-sprite');
const path = require('path');

const babel = require('gulp-babel');

Expand Down Expand Up @@ -145,37 +146,46 @@ gulp.task('scripts:bundle:build', () =>
bundleScripts(false, scriptsBundleDefaultOpts)
);

gulp.task('scripts:bundle:watch', () =>
bundleScripts(true, scriptsBundleDefaultOpts)
gulp.task('scripts:bundle:watch', ['scripts:bundle:build'], () =>
gulp.watch('./_js/**/*.js', ['scripts:bundle:build'])
);

/**
* Javascript custom code built with pattern library modules.
*/
function scriptsBundles(opts, done) {
opts = opts || {};

function scriptsBundles(opts = {}, done) {
let root = './_prototypes';

glob(root + '/**/bundle.js', function(err, files) {
if (err) {
done(err);
}

let tasks = files.map(function(entry) {
files.map(function(entry) {
return bundleScripts(!!opts.watch, {
path: entry,
dest: entry.replace(root, './js/compiled').replace('bundle.js', '')
});
});

es.merge(tasks).on('end', done);
});
}

gulp.task('scripts:bundles:build', scriptsBundles.bind(null, { watch: false }));

gulp.task('scripts:bundles:watch', scriptsBundles.bind(null, { watch: true }));
gulp.task('scripts:bundles:watch', ['scripts:bundles:build'], () => {
return gulp.watch(
'./_prototypes/**/bundle.js', function(e) {
const dest = e.path
.replace(path.join(__dirname, '_prototypes'), './js/compiled')
.replace('bundle.js', '');

bundleScripts(false, {
path: e.path,
dest: dest
});
}
);
});

/**
* Jekyll configuration
Expand Down
Loading

0 comments on commit 76111a0

Please sign in to comment.