Skip to content

Commit

Permalink
Updated versions of most of devDependencies. Removed run-sequence dep…
Browse files Browse the repository at this point in the history
…endency. Pending to upgrade istanbul to nyc and 6to5 to babel. Pending to review coverage. Updated sinon function in tests setup. jamesplease#59
  • Loading branch information
gndelia committed May 18, 2019
1 parent 72e7b49 commit 8f37ea2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 86 deletions.
111 changes: 51 additions & 60 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var gulp = require('gulp');
var { dest, task, series, src, parallel, watch } = require('gulp');
var $ = require('gulp-load-plugins')({
replaceString: /^gulp(-|\.)([0-9]+)?/
});
Expand All @@ -11,7 +11,6 @@ const to5ify = require('6to5ify');
const isparta = require('isparta');
const esperanto = require('esperanto');
const browserify = require('browserify');
const runSequence = require('run-sequence');
const source = require('vinyl-source-stream');

const manifest = require('./package.json');
Expand All @@ -21,14 +20,10 @@ const destinationFolder = path.dirname(mainFile);
const exportFileName = path.basename(mainFile, path.extname(mainFile));

// Remove the built files
gulp.task('clean', function(cb) {
del([destinationFolder], cb);
});
task('clean', cb => del([destinationFolder], cb));

// Remove our temporary files
gulp.task('clean-tmp', function(cb) {
del(['tmp'], cb);
});
task('clean-tmp', cb => del(['tmp'], cb));

// Send a notification when JSHint fails,
// so that you know your changes didn't build
Expand All @@ -43,8 +38,8 @@ function jscsNotify(file) {
}

// Lint our source code
gulp.task('lint-src', function() {
return gulp.src(['src/**/*.js'])
task('lint-src', () => {
return src(['src/**/*.js'])
.pipe($.plumber())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
Expand All @@ -55,8 +50,8 @@ gulp.task('lint-src', function() {
});

// Lint our test code
gulp.task('lint-test', function() {
return gulp.src(['test/**/*.js'])
task('lint-test', () => {
return src(['test/**/*.js'])
.pipe($.plumber())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
Expand All @@ -67,41 +62,41 @@ gulp.task('lint-test', function() {
});

// Build two versions of the library
gulp.task('build', ['lint-src', 'clean'], function(done) {
esperanto.bundle({
task('build', series('lint-src', 'clean', async (done) => {
let bundle = await esperanto.bundle({
base: 'src',
entry: config.entryFileName,
}).then(function(bundle) {
var res = bundle.toUmd({
sourceMap: true,
sourceMapSource: config.entryFileName + '.js',
sourceMapFile: exportFileName + '.js',
name: config.exportVarName
});
});

// Write the generated sourcemap
mkdirp.sync(destinationFolder);
fs.writeFileSync(path.join(destinationFolder, exportFileName + '.js'), res.map.toString());

$.file(exportFileName + '.js', res.code, { src: true })
.pipe($.plumber())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.to5({ blacklist: ['useStrict'] }))
.pipe($.sourcemaps.write('./', {addComment: false}))
.pipe(gulp.dest(destinationFolder))
.pipe($.filter(['*', '!**/*.js.map']))
.pipe($.rename(exportFileName + '.min.js'))
.pipe($.uglifyjs({
outSourceMap: true,
inSourceMap: destinationFolder + '/' + exportFileName + '.js.map',
}))
.pipe(gulp.dest(destinationFolder))
.on('end', done);
let res = bundle.toUmd({
sourceMap: true,
sourceMapSource: config.entryFileName + '.js',
sourceMapFile: exportFileName + '.js',
name: config.exportVarName
});
});

// Write the generated sourcemap
mkdirp.sync(destinationFolder);
fs.writeFileSync(path.join(destinationFolder, exportFileName + '.js'), res.map.toString());

$.file(exportFileName + '.js', res.code, { src: true })
.pipe($.plumber())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.to5({ blacklist: ['useStrict'] }))
.pipe($.sourcemaps.write('./', {addComment: false}))
.pipe(dest(destinationFolder))
.pipe($.filter(['*', '!**/*.js.map']))
.pipe($.rename(exportFileName + '.min.js'))
.pipe($.uglifyjs({
outSourceMap: true,
inSourceMap: destinationFolder + '/' + exportFileName + '.js.map',
}))
.pipe(dest(destinationFolder))
.on('end', done);
}));

// Bundle our app for our unit tests
gulp.task('browserify', function() {
task('browserify', () => {
var testFiles = glob.sync('./test/unit/**/*');
var allFiles = ['./test/setup/browserify.js'].concat(testFiles);
var bundler = browserify(allFiles);
Expand All @@ -111,24 +106,24 @@ gulp.task('browserify', function() {
}));
var bundleStream = bundler.bundle();
return bundleStream
.on('error', function(err){
.on('error', err => {
console.log(err.message);
this.emit('end');
})
.pipe($.plumber())
.pipe(source('./tmp/__spec-build.js'))
.pipe(gulp.dest(''))
.pipe(dest(destinationFolder))
.pipe($.livereload());
});

function test() {
return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
return src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
.pipe($.plumber())
.pipe($.mocha({reporter: 'dot', globals: config.mochaGlobals}));
}

gulp.task('coverage', function(done) {
gulp.src(['src/*.js'])
task('coverage', done => {
src(['src/*.js'])
.pipe($.plumber())
.pipe($.istanbul({ instrumenter: isparta.Instrumenter }))
.pipe($.istanbul.hookRequire())
Expand All @@ -140,30 +135,26 @@ gulp.task('coverage', function(done) {
});

// Lint and run our tests
gulp.task('test', ['lint-src', 'lint-test'], function() {
require('6to5/register')({modules: 'common'});
task('test', series(parallel('lint-src', 'lint-test'), () => {
// require('6to5/register')({modules: 'common'});
return test();
});
}));

// Ensure that linting occurs before browserify runs. This prevents
// the build from breaking due to poorly formatted code.
gulp.task('build-in-sequence', function(callback) {
runSequence(['lint-src', 'lint-test'], 'browserify', callback);
});
task('build-in-sequence', series('lint-src', 'lint-test', 'browserify'));

// Run the headless unit tests as you make changes.
gulp.task('watch', function() {
gulp.watch(['src/**/*', 'test/**/*', '.jshintrc', 'test/.jshintrc'], ['test']);
});
task('watch', () => watch(['src/**/*', 'test/**/*', '.jshintrc', 'test/.jshintrc'], 'test'));

// Set up a livereload environment for our spec runner
gulp.task('test-browser', ['build-in-sequence'], function() {
task('test-browser', series('build-in-sequence', () => {
$.livereload.listen({port: 35729, host: 'localhost', start: true});
return gulp.watch(
return watch(
['src/**/*.js', 'test/**/*', '.jshintrc', 'test/.jshintrc'],
['build-in-sequence']
'build-in-sequence'
);
});
}));

// An alias of test
gulp.task('default', ['test']);
task('default', series('test'));
51 changes: 26 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,40 @@
"devDependencies": {
"6to5": "^3.3.3",
"6to5ify": "^4.1.1",
"browserify": "^8.1.1",
"chai": "^1.10.0",
"del": "^1.1.1",
"browserify": "^16.2.3",
"chai": "^4.2.0",
"del": "^4.1.1",
"esperanto": "^0.6.7",
"glob": "^4.3.5",
"gulp": "^3.8.10",
"glob": "^7.1.4",
"gulp": "^4.0.2",
"gulp-6to5": "^3.0.0",
"gulp-file": "^0.2.0",
"gulp-filter": "^2.0.0",
"gulp-file": "^0.4.0",
"gulp-filter": "^5.0.0",
"gulp-istanbul": "^0.6.0",
"gulp-jscs": "^1.4.0",
"gulp-jshint": "^1.9.0",
"gulp-livereload": "^3.4.0",
"gulp-load-plugins": "^0.8.0",
"gulp-mocha": "^2.0.0",
"gulp-notify": "^2.1.0",
"gulp-plumber": "^0.6.6",
"gulp-rename": "^1.2.0",
"gulp-sourcemaps": "^1.3.0",
"gulp-uglifyjs": "^0.6.0",
"isparta": "^1.0.1",
"jshint-stylish": "^1.0.0",
"mkdirp": "^0.5.0",
"mocha": "^2.1.0",
"run-sequence": "^1.0.2",
"sinon": "^1.12.2",
"sinon-chai": "^2.6.0",
"underscore": "^1.7.0",
"vinyl-source-stream": "^1.0.0"
"gulp-livereload": "^4.0.1",
"gulp-load-plugins": "^1.5.0",
"gulp-mocha": "^4.0.0",
"gulp-notify": "^3.1.0",
"gulp-plumber": "^1.2.1",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.6.5",
"gulp-uglify": "^3.0.2",
"isparta": "^4.0.0",
"jshint-stylish": "^2.2.1",
"mkdirp": "^0.5.1",
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"sinon": "^7.3.2",
"sinon-chai": "^3.3.0",
"underscore": "^1.9.1",
"vinyl-source-stream": "^2.0.0"
},
"dependencies": {
"contained-periodic-values": "^1.0.0",
"skipped-periodic-values": "^1.0.0"
"moment": "^2.24.0",
"skipped-periodic-values": "^1.0.1"
},
"to5BoilerplateOptions": {
"entryFileName": "moment-business",
Expand Down
2 changes: 1 addition & 1 deletion test/setup/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function() {
global.expect = global.chai.expect;

beforeEach(function() {
this.sandbox = global.sinon.sandbox.create();
this.sandbox = global.sinon.createSandbox();
global.stub = this.sandbox.stub.bind(this.sandbox);
global.spy = this.sandbox.spy.bind(this.sandbox);
});
Expand Down

0 comments on commit 8f37ea2

Please sign in to comment.