@@ -18,18 +18,68 @@ cache:
1818 directories :
1919 - node_modules
2020before_install :
21- # Skip updating shrinkwrap / lock
22- - " npm config set shrinkwrap false"
21+ - |
22+ # Setup utility functions
23+ function node_version_lt () {
24+ [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v "${1}")" ]]
25+ }
26+ function npm_module_installed () {
27+ npm -lsp ls | grep -Fq "$(pwd)/node_modules/${1}:${1}@"
28+ }
29+ function npm_remove_module_re () {
30+ node -e '
31+ fs = require("fs");
32+ p = JSON.parse(fs.readFileSync("package.json", "utf8"));
33+ r = RegExp(process.argv[1]);
34+ for (k in p.devDependencies) {
35+ if (r.test(k)) delete p.devDependencies[k];
36+ }
37+ fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n");
38+ ' "$@"
39+ }
40+ function v () {
41+ tr '.' '\n' <<< "${1}" \
42+ | awk '{ printf "%03d", $0 }' \
43+ | sed 's/^0*//'
44+ }
45+ # Configure npm
46+ - |
47+ # Skip updating shrinkwrap / lock
48+ npm config set shrinkwrap false
2349 # Setup Node.js version-specific dependencies
24- - " test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
25- - " test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 6 || npm rm --save-dev $(grep -E '\" eslint\\ S*\" ' package.json | cut -d'\" ' -f2)"
50+ - |
51+ # Configure eslint for linting
52+ if node_version_lt '6.0'; then npm_remove_module_re '^eslint(-|$)'
53+ fi
54+ - |
55+ # Configure istanbul for coverage
56+ if node_version_lt '0.10'; then npm_remove_module_re '^istanbul$'
57+ fi
2658 # Update Node.js modules
27- - " test ! -d node_modules || npm prune"
28- - " test ! -d node_modules || npm rebuild"
59+ - |
60+ # Prune & rebuild node_modules
61+ if [[ -d node_modules ]]; then
62+ npm prune
63+ npm rebuild
64+ fi
65+ before_scrpt :
66+ - |
67+ # Contents of node_modules
68+ npm -s ls ||:
2969script :
30- # Run test script, depending on istanbul install
31- - " test ! -z $(npm -ps ls istanbul) || npm test"
32- - " test -z $(npm -ps ls istanbul) || npm run-script test-travis"
33- - " test -z $(npm -ps ls eslint ) || npm run-script lint"
70+ - |
71+ # Run test script, depending on istanbul install
72+ if npm_module_installed 'istanbul'; then npm run-script test-travis
73+ else npm test
74+ fi
75+ - |
76+ # Run linting, if eslint exists
77+ if npm_module_installed 'eslint'; then npm run-script lint
78+ fi
3479after_script :
35- - " test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
80+ - |
81+ # Upload coverage to coveralls if exists
82+ if [[ -e ./coverage/lcov.info ]]; then
83+ npm install --save-dev coveralls@2
84+ coveralls < ./coverage/lcov.info
85+ fi
0 commit comments