-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: simplify & speed up logic in Travis CI build steps
- Loading branch information
1 parent
30516ba
commit 7328d0b
Showing
1 changed file
with
39 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,32 @@ cache: | |
- node_modules | ||
before_install: | ||
- | | ||
# Setup utility functions | ||
function node_version_lt () { | ||
[[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v "${1}")" ]] | ||
} | ||
function npm_module_installed () { | ||
npm -lsp ls | grep -Fq "$(pwd)/node_modules/${1}:${1}@" | ||
} | ||
function npm_remove_module_re () { | ||
node -e ' | ||
fs = require("fs"); | ||
p = JSON.parse(fs.readFileSync("package.json", "utf8")); | ||
r = RegExp(process.argv[1]); | ||
for (k in p.devDependencies) { | ||
if (r.test(k)) delete p.devDependencies[k]; | ||
} | ||
fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); | ||
' "$@" | ||
} | ||
function npm_use_module () { | ||
node -e ' | ||
fs = require("fs"); | ||
p = JSON.parse(fs.readFileSync("package.json", "utf8")); | ||
p.devDependencies[process.argv[1]] = process.argv[2]; | ||
fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); | ||
' "$@" | ||
} | ||
function v () { | ||
tr '.' '\n' <<< "${1}" \ | ||
| awk '{ printf "%03d", $0 }' \ | ||
|
@@ -33,33 +59,19 @@ before_install: | |
npm config set shrinkwrap false | ||
# Setup Node.js version-specific dependencies | ||
- | | ||
# eslint for linting | ||
if [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v '6.0')" ]]; then | ||
# - remove on Node.js < 6 | ||
node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ | ||
grep -E '^eslint(-|$)' | \ | ||
xargs npm rm --save-dev | ||
# Configure eslint for linting | ||
if node_version_lt '6.0'; then npm_remove_module_re '^eslint(-|$)' | ||
fi | ||
- | | ||
# istanbul for coverage | ||
if [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v '0.10')" ]]; then | ||
# - remove on Node.js < 0.10 | ||
npm rm --save-dev istanbul | ||
# Configure istanbul for coverage | ||
if node_version_lt '0.10'; then npm_remove_module_re '^istanbul$' | ||
fi | ||
- | | ||
# mocha for testing | ||
if [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v '0.8')" ]]; then | ||
# - use 1.x for Node.js < 0.8 | ||
npm install --save-dev [email protected] | ||
elif [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v '0.10')" ]]; then | ||
# - use 2.x for Node.js < 0.10 | ||
npm install --save-dev [email protected] | ||
elif [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v '4.0')" ]]; then | ||
# - use 3.x for Node.js < 4 | ||
npm install --save-dev [email protected] | ||
elif [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v '6.0')" ]]; then | ||
# - use 5.x for Node.js < 6 | ||
npm install --save-dev [email protected] | ||
# Configure mocha for testing | ||
if node_version_lt '0.8' ; then npm_use_module 'mocha' '1.21.5' | ||
elif node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3' | ||
elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3' | ||
elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0' | ||
fi | ||
# Update Node.js modules | ||
- | | ||
|
@@ -68,19 +80,15 @@ before_install: | |
npm prune | ||
npm rebuild | ||
fi | ||
script: | ||
- | | ||
# Run test script, depending on istanbul install | ||
if npm -ps ls istanbul | grep -q istanbul; then | ||
npm run-script test-travis | ||
else | ||
npm test | ||
if npm_module_installed 'istanbul'; then npm run-script test-travis | ||
else npm test | ||
fi | ||
- | | ||
# Run linting, depending on eslint install | ||
if npm -ps ls eslint | grep -q eslint; then | ||
npm run-script lint | ||
# Run linting, if eslint exists | ||
if npm_module_installed 'eslint'; then npm run-script lint | ||
fi | ||
after_script: | ||
- | | ||
|