diff --git a/gulpfile.js b/gulpfile.js index 09d02ab..1dc41af 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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]+)?/ }); @@ -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'); @@ -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 @@ -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')) @@ -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')) @@ -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); @@ -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()) @@ -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')); \ No newline at end of file diff --git a/package.json b/package.json index c8e1195..7add2ec 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/setup/setup.js b/test/setup/setup.js index f2a70a0..3aa32e9 100644 --- a/test/setup/setup.js +++ b/test/setup/setup.js @@ -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); });