From 514a10f302043e48459a79806775b6925dc9a7b5 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 23 Oct 2015 18:31:47 -0400 Subject: [PATCH] consolidating scripts --- .travis.yml | 6 +++--- make-prod-combined.sh | 25 ------------------------ make-tests.sh | 8 -------- package.json | 6 +++++- run-tests.sh | 21 -------------------- scripts/build-tests.sh | 12 ++++++++++++ scripts/build.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/run-tests.sh | 21 ++++++++++++++++++++ scripts/watch.sh | 30 ++++++++++++++++++++++++++++ watch-combined.js | 9 --------- watch-tests.sh | 8 -------- 11 files changed, 124 insertions(+), 75 deletions(-) delete mode 100755 make-prod-combined.sh delete mode 100755 make-tests.sh delete mode 100755 run-tests.sh create mode 100755 scripts/build-tests.sh create mode 100755 scripts/build.sh create mode 100755 scripts/run-tests.sh create mode 100644 scripts/watch.sh delete mode 100755 watch-combined.js delete mode 100755 watch-tests.sh diff --git a/.travis.yml b/.travis.yml index f318f37..a2ac109 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ node_js: sudo: false # Use container-based architecture script: > - ./make-prod-combined.sh && - ./make-tests.sh && - ./run-tests.sh && + npm run build && + npm run build-tests && + npm run test && curl -O https://raw.githubusercontent.com/danvk/travis-weigh-in/master/weigh_in.py && python weigh_in.py dist/dygraph-combined.js diff --git a/make-prod-combined.sh b/make-prod-combined.sh deleted file mode 100755 index 6e8f9aa..0000000 --- a/make-prod-combined.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -mkdir -p dist - -browserify \ - -v \ - -t babelify \ - -t [ envify --NODE_ENV production ] \ - --debug \ - --standalone Dygraph \ - src/dygraph.js \ - > dist/dygraph.js - -# Create dist/dygraph.js.map -cat dist/dygraph.js | exorcist --base . dist/dygraph.js.map > /dev/null - -# Create dist/dygraph.js.min{,.map} -uglifyjs --compress --mangle \ - --in-source-map dist/dygraph.js.map \ - --source-map-include-sources \ - --source-map dist/dygraph.min.js.map \ - -o dist/dygraph.min.js \ - dist/dygraph.js - -# Copy to the old location -cp dist/dygraph.min.js dist/dygraph-combined.js diff --git a/make-tests.sh b/make-tests.sh deleted file mode 100755 index 3242266..0000000 --- a/make-tests.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -browserify \ - -v \ - -t babelify \ - -t [ envify --NODE_ENV development ] \ - --debug \ - -o dist/tests.js \ - auto_tests/tests/*.js diff --git a/package.json b/package.json index 5ca91aa..b60a8fb 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "babel-core": "^5.8.25", "babelify": "^6.3.0", "browserify": "^11.2.0", + "browserify-header": "^0.9.2", "chai": "^3.3.0", "coveralls": "^2.11.2", "envify": "^3.4.0", @@ -47,7 +48,10 @@ "watchify": "^3.4.0" }, "scripts": { - "test": "make test", + "build": "./scripts/build.sh", + "watch": "./scripts/watch.sh", + "build-tests": "./scripts/build-tests.sh", + "test": "./scripts/run-tests.sh", "tests-ok": "./scripts/check-no-only.sh" }, "pre-commit": [ diff --git a/run-tests.sh b/run-tests.sh deleted file mode 100755 index 4b1c77f..0000000 --- a/run-tests.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# Starts the http-server and runs mocha-phantomjs-based tests -# Note that you must run `npm run build` or `npm run watch` before running this. -set -o errexit - -# Run http-server and save its PID -http-server -p 8081 > /dev/null & -SERVER_PID=$! -function finish() { - kill -TERM $SERVER_PID -} -trap finish EXIT - -# the following sleep step is not really necessary -# as http-server starts almost instantenously; -# but letting the server settle might help prevent -# possible racing conditions -sleep 1 - -# Start the tests -mocha-phantomjs http://localhost:8081/auto_tests/runner.html diff --git a/scripts/build-tests.sh b/scripts/build-tests.sh new file mode 100755 index 0000000..216296d --- /dev/null +++ b/scripts/build-tests.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Create dist/tests.js +# To run the tests, run `npm run test` +# To iterate on the tests, use `npm run watch` + +browserify \ + -v \ + -t babelify \ + -t [ envify --NODE_ENV development ] \ + --debug \ + -o dist/tests.js \ + auto_tests/tests/*.js diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..d9ea2e2 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# This generates: +# - dist/dygraph.js +# - dist/dygraph.js.map +# - dist/dygraph.min.js +# - dist/dygraph.min.js.map +set -o errexit + +mkdir -p dist + +# Create dist/dygraph.js +browserify \ + -v \ + -t babelify \ + -t [ envify --NODE_ENV development ] \ + --debug \ + --standalone Dygraph \ + src/dygraph.js \ + > dist/dygraph.tmp.js + +# Create dist/dygraph.js.map +cat dist/dygraph.tmp.js | exorcist --base . dist/dygraph.js.map > dist/dygraph.js + +# Create "production" bundle for minification +browserify \ + -v \ + -t babelify \ + -t [ envify --NODE_ENV production ] \ + --debug \ + --standalone Dygraph \ + src/dygraph.js \ + > dist/dygraph.tmp.js + +# Create dist/dygraph.tmp.js.map +cat dist/dygraph.tmp.js | exorcist --base . dist/dygraph.tmp.js.map > /dev/null + +# Create dist/dygraph.js.min{,.map} +uglifyjs --compress --mangle \ + --in-source-map dist/dygraph.tmp.js.map \ + --source-map-include-sources \ + --source-map dist/dygraph.min.js.map \ + -o dist/dygraph.min.js \ + dist/dygraph.tmp.js + +# Copy to the old location +cp dist/dygraph.min.js dist/dygraph-combined.js + +# Build GWT JAR +jar -cf dist/dygraph-gwt.jar -C gwt org + +# Remove temp files. +rm dist/dygraph.tmp.js +rm dist/dygraph.tmp.js.map diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100755 index 0000000..4b1c77f --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Starts the http-server and runs mocha-phantomjs-based tests +# Note that you must run `npm run build` or `npm run watch` before running this. +set -o errexit + +# Run http-server and save its PID +http-server -p 8081 > /dev/null & +SERVER_PID=$! +function finish() { + kill -TERM $SERVER_PID +} +trap finish EXIT + +# the following sleep step is not really necessary +# as http-server starts almost instantenously; +# but letting the server settle might help prevent +# possible racing conditions +sleep 1 + +# Start the tests +mocha-phantomjs http://localhost:8081/auto_tests/runner.html diff --git a/scripts/watch.sh b/scripts/watch.sh new file mode 100644 index 0000000..d13b88a --- /dev/null +++ b/scripts/watch.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Continually regenerate these two files: +# - dist/dygraph.js +# - dist/tests.js +# As source/test files change. + +# Clean background processes after quit +trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT + +mkdir -p dist # in case it doesn't exist; watchify needs it + +watchify \ + -v \ + -t babelify \ + -t [ envify --NODE_ENV development ] \ + --debug \ + --standalone Dygraph \ + -o dist/dygraph.js \ + src/dygraph.js & + +watchify \ + -v \ + -t babelify \ + -t [ envify --NODE_ENV development ] \ + --debug \ + -o dist/tests.js \ + auto_tests/tests/*.js & + +# Wait until background processes end +wait diff --git a/watch-combined.js b/watch-combined.js deleted file mode 100755 index 4ef91ce..0000000 --- a/watch-combined.js +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -watchify \ - -v \ - -t babelify \ - -t [ envify --NODE_ENV development ] \ - --debug \ - --standalone Dygraph \ - -o dist/dygraph.js \ - src/dygraph.js diff --git a/watch-tests.sh b/watch-tests.sh deleted file mode 100755 index 9b2b648..0000000 --- a/watch-tests.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -watchify \ - -v \ - -t babelify \ - -t [ envify --NODE_ENV development ] \ - --debug \ - -o dist/tests.js \ - auto_tests/tests/*.js -- 2.7.4