-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: speed up logic in Travis CI build steps
- Loading branch information
1 parent
8f2c7b6
commit 4a25698
Showing
1 changed file
with
47 additions
and
32 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 |
---|---|---|
|
@@ -19,42 +19,60 @@ cache: | |
directories: | ||
- 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 }' \ | ||
| sed 's/^0*//' | ||
} | ||
# Configure npm | ||
- | | ||
# Skip updating shrinkwrap / lock | ||
npm config set shrinkwrap false | ||
# Setup Node.js version-specific dependencies | ||
- | | ||
# mocha for testing | ||
# - use 2.x for Node.js < 0.10 | ||
# - use 3.x for Node.js < 6 | ||
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then | ||
npm install --save-dev [email protected] | ||
elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then | ||
npm install --save-dev [email protected] | ||
# Configure eslint for linting | ||
if node_version_lt '6.0'; then npm_remove_module_re '^eslint(-|$)' | ||
fi | ||
- | | ||
# istanbul for coverage | ||
# - remove on Node.js < 0.10 | ||
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then | ||
npm rm --silent --save-dev istanbul | ||
# Configure istanbul for coverage | ||
if node_version_lt '0.10'; then npm_remove_module_re '^istanbul$' | ||
fi | ||
- | | ||
# supertest for http calls | ||
# - use 1.1.0 for Node.js < 0.10 | ||
# - use 2.0.0 for Node.js < 4 | ||
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then | ||
npm install --save-dev [email protected] | ||
elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then | ||
npm install --save-dev [email protected] | ||
# Configure mocha for testing | ||
if 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' | ||
fi | ||
- | | ||
# eslint for linting | ||
# - remove on Node.js < 6 | ||
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then | ||
node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ | ||
grep -E '^eslint(-|$)' | \ | ||
xargs npm rm --save-dev | ||
# Configure supertest for http calls | ||
if node_version_lt '0.10'; then npm_use_module 'supertest' '1.1.0' | ||
elif node_version_lt '4.0' ; then npm_use_module 'supertest' '2.0.0' | ||
fi | ||
# Update Node.js modules | ||
- | | ||
|
@@ -64,17 +82,14 @@ before_install: | |
npm rebuild | ||
fi | ||
script: | ||
# Run test script | ||
- | | ||
if npm -ps ls istanbul | grep -q istanbul; then | ||
npm run test-travis | ||
else | ||
npm test | ||
# Run test script, depending on istanbul install | ||
if npm_module_installed 'istanbul'; then npm run-script test-travis | ||
else npm test | ||
fi | ||
# Run linting | ||
- | | ||
if npm -ps ls eslint | grep -q eslint; then | ||
npm run lint | ||
# Run linting, if eslint exists | ||
if npm_module_installed 'eslint'; then npm run-script lint | ||
fi | ||
after_script: | ||
- | | ||
|