From 0bc2e4b13e50e241f2ea83a8c787bc96201b9164 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 24 Jun 2014 22:58:40 -0700 Subject: [PATCH 1/4] Install karma-cli; add test 'watch' script --- Makefile | 2 +- karma.conf.js | 5 ++--- package.json | 5 ++++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 7da8925b..50259e24 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ clean: standalone: clean @ mkdir -p $(BUILD_DIR) - @ node tools/standalone/build.js + @ npm test test: standalone @ npm test diff --git a/karma.conf.js b/karma.conf.js index ac0abcde..ca3f3209 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -37,7 +37,7 @@ module.exports = function (config) { // use dots reporter, as travis terminal does not support escaping sequences // possible values: 'dots', 'progress' // CLI --reporters progress - reporters: ['dots'], + reporters: ['progress'], // enable / disable watching file and executing tests whenever any file changes // CLI --auto-watch --no-auto-watch @@ -53,8 +53,7 @@ module.exports = function (config) { // - IE (only Windows) // CLI --browsers Chrome, Firefox, Safari browsers: [ - 'Chrome', - 'Firefox' + 'Chrome' ], // If browser does not capture in given timeout [ms], kill it diff --git a/package.json b/package.json index 477feba4..a0b47252 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.2.0", "devDependencies": { "karma": "<=0.11.14", + "karma-cli": "0.0.4", "karma-jasmine": "~0.1.0", "karma-requirejs": "~0.1.0", "karma-chrome-launcher": "~0.1.0", @@ -14,6 +15,8 @@ "uglify-js": "~2.3.6" }, "scripts": { - "test": "./node_modules/karma/bin/karma start --browsers Firefox --single-run" + "build": "npm run webpack & npm run webpack-minified", + "test": "karma start --browsers Firefox --single-run", + "watch": "karma start" } } From ed8defc2ccbf5fbeaaf6a10d9485e0f1ad3baca1 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 24 Jun 2014 23:26:41 -0700 Subject: [PATCH 2/4] Use webpack to build exported library --- Makefile | 2 +- package.json | 7 +++++-- webpack.config.js | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 webpack.config.js diff --git a/Makefile b/Makefile index 50259e24..10b39fce 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ clean: standalone: clean @ mkdir -p $(BUILD_DIR) - @ npm test + @ npm run build test: standalone @ npm test diff --git a/package.json b/package.json index a0b47252..b1f15b05 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,14 @@ "karma-phantomjs-launcher": "~0.1.0", "karma-safari-launcher": "~0.1.1", "loadbuilder": ">=0.4.2", - "uglify-js": "~2.3.6" + "uglify-js": "~2.3.6", + "webpack": "~1.3.1-beta4" }, "scripts": { "build": "npm run webpack & npm run webpack-minified", "test": "karma start --browsers Firefox --single-run", - "watch": "karma start" + "watch": "karma start", + "webpack": "webpack --progress --colors", + "webpack-minified": "webpack --progress --colors --optimize-minimize --output-file flight.min.js" } } diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 00000000..94912e00 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,16 @@ +var BannerPlugin = require('webpack/lib/BannerPlugin'); +var version = require('./package.json').version; + +module.exports = { + entry: './lib/index', + output: { + path: __dirname + '/build', + filename: 'flight.js', + library: 'flight', + libraryTarget: 'umd', + sourcePrefix: '' + }, + plugins: [ + new BannerPlugin('Flight v' + version + ' | (c) Twitter, Inc. | MIT License') + ] +}; From 77d3734f43f8ad16c61fafef1bb71f00039f3471 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 24 Jun 2014 23:03:23 -0700 Subject: [PATCH 3/4] Remove previous build tools --- package.json | 2 -- tools/standalone/amd-shim.js | 63 ------------------------------------ tools/standalone/banner.txt | 1 - tools/standalone/build.js | 31 ------------------ 4 files changed, 97 deletions(-) delete mode 100644 tools/standalone/amd-shim.js delete mode 100644 tools/standalone/banner.txt delete mode 100644 tools/standalone/build.js diff --git a/package.json b/package.json index b1f15b05..6ac6764c 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,6 @@ "karma-firefox-launcher": "~0.1.0", "karma-phantomjs-launcher": "~0.1.0", "karma-safari-launcher": "~0.1.1", - "loadbuilder": ">=0.4.2", - "uglify-js": "~2.3.6", "webpack": "~1.3.1-beta4" }, "scripts": { diff --git a/tools/standalone/amd-shim.js b/tools/standalone/amd-shim.js deleted file mode 100644 index 5cbac773..00000000 --- a/tools/standalone/amd-shim.js +++ /dev/null @@ -1,63 +0,0 @@ -(function(context) { - var factories = {}, loaded = {}; - var isArray = Array.isArray || function(obj) { - return obj.constructor == Array; - }; - - var map = Array.map || function(arr, fn, scope) { - for (var i = 0, len = arr.length, result = []; i < len; i++) { - result.push(fn.call(scope, arr[i])); - } - return result; - }; - - function define() { - var args = Array.prototype.slice.call(arguments), dependencies = [], id, factory; - if (typeof args[0] == 'string') { - id = args.shift(); - } - if (isArray(args[0])) { - dependencies = args.shift(); - } - factory = args.shift(); - factories[id] = [dependencies, factory]; - } - - function require(id) { - function resolve(dep) { - var relativeParts = id.split('/'), depParts = dep.split('/'), relative = false; - relativeParts.pop(); - while (depParts[0] == '..' && relativeParts.length) { - relativeParts.pop(); - depParts.shift(); - relative = true; - } - if (depParts[0] == '.') { - depParts.shift(); - relative = true; - } - if (relative) { - depParts = relativeParts.concat(depParts); - } - return depParts.join('/'); - } - - var unresolved, factory, dependencies; - if (typeof loaded[id] == 'undefined') { - unresolved = factories[id]; - if (unresolved) { - dependencies = unresolved[0]; - factory = unresolved[1]; - loaded[id] = factory.apply(undefined, map(dependencies, function(id) { - return require(resolve(id)); - })); - } - } - - return loaded[id]; - } - -{{ module }} - - context.flight = require('lib/index'); -}(this)); diff --git a/tools/standalone/banner.txt b/tools/standalone/banner.txt deleted file mode 100644 index 50e9802f..00000000 --- a/tools/standalone/banner.txt +++ /dev/null @@ -1 +0,0 @@ -/*! Flight v{{ version }} | (c) Twitter, Inc. | MIT License */ diff --git a/tools/standalone/build.js b/tools/standalone/build.js deleted file mode 100644 index 396dfb61..00000000 --- a/tools/standalone/build.js +++ /dev/null @@ -1,31 +0,0 @@ -var builder = require('loadbuilder'), - uglify = require('uglify-js'), - version = require('../../package.json').version, - path = require('path'), - fs = require('fs'); - -var rootPath = path.join(__dirname, '..', '..'), - shimPath = path.join(__dirname, 'amd-shim.js'), - bannerPath = path.join(__dirname, 'banner.txt'), - buildDir = path.join(__dirname, '..', '..', 'build'), - flightPath = path.join(buildDir, 'flight.js'), - flightPathMin = path.join(buildDir, 'flight.min.js'), - modulePlaceholder = '{{ module }}', - versionPlaceholder = '{{ version }}'; - -var flightSource = builder({ - docRoot: rootPath, - path: '.' -}).include('lib/index').toSource(); - -var amdShim = fs.readFileSync(shimPath, 'utf8'); -var banner = fs.readFileSync(bannerPath, 'utf8').split(versionPlaceholder).join(version); -var bundle = amdShim.split(modulePlaceholder).join(flightSource); -var bundleMin = uglify.minify(bundle, {fromString: true}).code; - -// prepend the version / licence banner to the files -bundle = [banner, bundle].join(''); -bundleMin = [banner, bundleMin].join(''); - -fs.writeFileSync(flightPath, bundle, 'utf8'); -fs.writeFileSync(flightPathMin, bundleMin, 'utf8'); From 67b8c6d892ed594ff01c15f9a2086ee569e56e23 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 24 Jun 2014 23:05:41 -0700 Subject: [PATCH 4/4] Remove karma-phantomjs-launcher It's not used by this project and contributes to a slow first npm-install. --- karma.conf.js | 1 - package.json | 1 - 2 files changed, 2 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index ca3f3209..bf3008be 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -70,7 +70,6 @@ module.exports = function (config) { 'karma-chrome-launcher', 'karma-firefox-launcher', 'karma-ie-launcher', - 'karma-phantomjs-launcher', 'karma-safari-launcher' ] }); diff --git a/package.json b/package.json index 6ac6764c..86f90986 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "karma-chrome-launcher": "~0.1.0", "karma-ie-launcher": "~0.1.1", "karma-firefox-launcher": "~0.1.0", - "karma-phantomjs-launcher": "~0.1.0", "karma-safari-launcher": "~0.1.1", "webpack": "~1.3.1-beta4" },