From 28e41032e967b77dd8b5ea115602caa01fac5c35 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 30 Aug 2016 16:16:36 -0400 Subject: [PATCH] Unify, improve development environment --- Makefile | 2 +- development_server.js | 49 +++++++++++++++++++++++++++++++++++++++++++ package.json | 12 +++++------ rollup.config.js | 11 ---------- 4 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 development_server.js delete mode 100644 rollup.config.js diff --git a/Makefile b/Makefile index 7f4d9efb8..91f1fdf81 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ $(BUILDJS_TARGETS): $(BUILDJS_SOURCES) build.js node build.js dist/iD.js: $(BUILDJS_TARGETS) - ./node_modules/.bin/rollup --config=./rollup.config.js --input ./modules/id.js --output dist/iD.js + npm run build dist/iD.min.js: dist/iD.js Makefile @rm -f $@ diff --git a/development_server.js b/development_server.js new file mode 100644 index 000000000..8ee31c862 --- /dev/null +++ b/development_server.js @@ -0,0 +1,49 @@ +var rollup = require( 'rollup' ); +var nodeResolve = require('rollup-plugin-node-resolve'); +var commonjs = require('rollup-plugin-commonjs'); +var json = require('rollup-plugin-json'); +var http = require('http'); +var gaze = require('gaze'); +var ecstatic = require('ecstatic'); + +var cache; +var building = false; + +function build() { + if (building) return; + building = true; + console.log('Rebuilding'); + console.time('Rebuilt'); + rollup.rollup({ + entry: './modules/id.js', + cache: cache, + plugins: [ + nodeResolve({ jsnext: true, main: true, browser: false }), + commonjs(), + json() + ] + }).then(function (bundle) { + console.timeEnd('Rebuilt'); + cache = bundle; + bundle.write({ + format: 'iife', + dest: 'dist/iD.js' + }); + building = false; + }); +} + +if (process.argv[2] === 'develop') { + build(); + gaze('modules/**.js', function(err, watcher) { + watcher.on('all', function() { + build(); + }); + }); + http.createServer( + ecstatic({ root: __dirname }) + ).listen(8080); + console.log('Listening on :8080'); +} else { + build(); +} diff --git a/package.json b/package.json index 05b1829c0..82049d5a2 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,9 @@ }, "scripts": { "test": "npm run lint && make && phantomjs node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html spec", - "start": "rollup --config=./rollup.config.js -f iife --input ./modules/id.js --output dist/iD.js -w", - "web": "http-server", + "start": "node development_server.js develop", "build-min": "npm run build && uglifyjs dist/iD.js -c -m -o dist/iD.min.js", - "build": "rollup --config=./rollup.config.js -f iife --input ./modules/id.js --output dist/iD.js", + "build": "node development_server.js", "lint": "eslint js/id test/spec modules" }, "repository": { @@ -36,14 +35,15 @@ "wmf-sitematrix": "0.1.2" }, "devDependencies": { - "chai": "~3.5.0", "brfs": "1.4.3", + "chai": "~3.5.0", "d3": "4.2.1", + "ecstatic": "2.1.0", "editor-layer-index": "git://github.com/osmlab/editor-layer-index.git#gh-pages", "eslint": "~3.3.1", + "gaze": "1.1.1", "glob": "~7.0.5", "happen": "~0.3.1", - "http-server": "0.9.0", "js-yaml": "~3.6.1", "jsonschema": "~1.1.0", "maki": "0.5.0", @@ -55,10 +55,10 @@ "request": "~2.73.0", "rollup": "0.34.10", "rollup-plugin-commonjs": "3.3.1", + "rollup-plugin-json": "2.0.1", "rollup-plugin-node-resolve": "2.0.0", "sinon": "~1.17.5", "sinon-chai": "~2.8.0", - "rollup-plugin-json": "2.0.1", "smash": "0.0", "svg-sprite": "1.3.3", "uglify-js": "~2.7.0", diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index 322fcc37a..000000000 --- a/rollup.config.js +++ /dev/null @@ -1,11 +0,0 @@ -import nodeResolve from 'rollup-plugin-node-resolve'; -import commonjs from 'rollup-plugin-commonjs'; -import json from 'rollup-plugin-json'; - -export default { - plugins: [ - nodeResolve({ jsnext: true, main: true, browser: false }), - commonjs(), - json() - ] -};