From 0b36b50d901fe1b56036d7744004cd7d31c45200 Mon Sep 17 00:00:00 2001 From: Denis Bardadym Date: Sun, 29 May 2016 20:31:47 +0300 Subject: [PATCH] Use rollup for build --- .gitignore | 2 ++ as-function.js | 2 +- browser-entry.js | 13 +++++++- gulpfile.js | 78 ------------------------------------------------ index.js | 2 +- package.json | 27 ++++++++--------- rollup.config.js | 44 +++++++++++++++++++++++++++ 7 files changed, 72 insertions(+), 96 deletions(-) delete mode 100644 gulpfile.js create mode 100644 rollup.config.js diff --git a/.gitignore b/.gitignore index a68eaaf..35e9633 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ desktop.ini should.js.for-tests *.swp npm-debug.log +cjs/ +es6/ diff --git a/as-function.js b/as-function.js index c3f0d0a..729dfdc 100644 --- a/as-function.js +++ b/as-function.js @@ -1 +1 @@ -module.exports = require('./lib/should'); +module.exports = require('./cjs/should'); diff --git a/browser-entry.js b/browser-entry.js index 0ea1e08..51694a6 100644 --- a/browser-entry.js +++ b/browser-entry.js @@ -1 +1,12 @@ -should = require('./index'); +import should from './es6/should'; + +var defaultProto = Object.prototype; +var defaultProperty = 'should'; + +//Expose api via `Object#should`. +try { + var prevShould = should.extend(defaultProperty, defaultProto); + should._prevShould = prevShould; +} catch (e) { + //ignore errors +} diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 159d571..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict'; - -const gulp = require('gulp'); - -const derequire = require('gulp-derequire'); -const wrapper = require('gulp-wrapper'); -const uglify = require('gulp-uglify'); -const rename = require('gulp-rename'); - -const source = require('vinyl-source-stream'); -const buffer = require('vinyl-buffer'); - -const browserify = require('browserify'); -const collapse = require('bundle-collapser'); - -const pkg = require('./package.json'); - -const template = require('lodash.template') - -const header = template(` -/*! - * <%= pkg.name %> - <%= pkg.description %> - * @version v<%= pkg.version %> - * @author <%= pkg.author %> - * @link <%= pkg.homepage %> - * @license <%= pkg.license %> - */ - -;(function (root, factory) { - if (typeof define === 'function' && define.amd) { - define([], factory); - } else if (typeof module === 'object' && module.exports) { - module.exports = factory(); - } else { - root.Should = factory(); - - Object.defineProperty(root, 'should', { - enumerable: false, - configurable: true, - value: root.Should - }); - } -}(this, function () { - var should, require = null; -`, { variable: 'pkg' })(pkg); - -var footer = ` - return should; -})); -`; - -gulp.task('script', () => { - var bundleStream = browserify({ - entries: './browser-entry', - builtins: null, - insertGlobals: false, - detectGlobals: false, - fullPaths: false, - hasExports: false - }) - .plugin('bundle-collapser/plugin') - .bundle(); - - return bundleStream - .pipe(source('should.js')) - .pipe(buffer()) - .pipe(derequire()) - .pipe(wrapper({ - header, - footer - })) - .pipe(gulp.dest('./')) - .pipe(uglify({ preserveComments: 'some' })) - .pipe(rename('should.min.js')) - .pipe(gulp.dest('./')); -}); - -gulp.task('default', ['script']); diff --git a/index.js b/index.js index 9aa4ffc..4aa415f 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -var should = require('./lib/should'); +var should = require('./cjs/should'); var defaultProto = Object.prototype; var defaultProperty = 'should'; diff --git a/package.json b/package.json index 1177afc..5a95848 100644 --- a/package.json +++ b/package.json @@ -9,25 +9,22 @@ }, "homepage": "https://github.com/shouldjs/should.js", "scripts": { + "cjs": "rollup --format=cjs --output=cjs/should.js lib/should.js", + "es6": "rollup --format=es6 --output=es6/should.js lib/should.js", + "build": "npm run cjs && npm run es6", + "prepublish": "npm run build && npm run browser", + "pretest": "npm run build", "test": "mocha -R mocha-better-spec-reporter --check-leaks ./test/*.test.js ./test/**/*.test.js", "zuul": "zuul -- ./test/**/*.test.js ./test/*.test.js", - "browser": "gulp script" + "browser": "rollup -c rollup.config.js --output ./should.js" }, "devDependencies": { "bluebird": "^3.0.6", - "browserify": "latest", - "bundle-collapser": "^1.2.1", "eslint": "^2.4.0", - "gulp": "^3.8.10", - "gulp-derequire": "^2.1.0", - "gulp-rename": "^1.2.0", - "gulp-uglify": "^1.0.1", - "gulp-wrapper": "^1.0.0", - "lodash.template": "^4.2.4", "mocha": "latest", "mocha-better-spec-reporter": "latest", - "vinyl-buffer": "^1.0.0", - "vinyl-source-stream": "^1.1.0", + "rollup": "^0.26.3", + "rollup-plugin-node-resolve": "^1.5.0", "zuul": "latest" }, "keywords": [ @@ -39,10 +36,10 @@ "main": "./index.js", "license": "MIT", "dependencies": { - "should-equal": "0.8.0", - "should-format": "0.3.2", - "should-type": "0.2.0" - } + "should-equal": "^1.0.0", + "should-format": "^1.0.0", + "should-type": "^1.0.0" + }, "files": [ "cjs/*", "es6/*", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..d0e849d --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,44 @@ +/*eslint-env node */ +'use strict'; + +const nodeResolve = require('rollup-plugin-node-resolve'); + +const pkg = require('./package.json'); + +const banner = `/*! + * ${pkg.name} - ${pkg.description} + * @version v${pkg.version} + * @author ${pkg.author} + * @link ${pkg.homepage} + * @license ${pkg.license} + */ +`; + +const outro = ` +if (typeof define === 'function' && define.amd) { + define([], function() { return should }); +} else if (typeof module === 'object' && module.exports) { + module.exports = should; +} else { + this.Should = should; + + Object.defineProperty(this, 'should', { + enumerable: false, + configurable: true, + value: should + }); +}`; + +module.exports = { + entry: 'browser-entry.js', + banner, + outro, + format: 'iife', + plugins: [ + nodeResolve({ + jsnext: true, + main: true, + preferBuiltins: false + }) + ] +};