Skip to content

Commit 0356d72

Browse files
committed
chore(travis,grunt): extract the npm install and cache busting logic into install-dependencies.sh
So now we are DRY. Added extra error checking and improved the grunt file init setup so that stdio is visible in console. Closes angular#11110
1 parent a773f89 commit 0356d72

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

.travis.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ install:
4646
# Log HTTP requests
4747
- npm config set loglevel http
4848
- npm install -g npm@2.5
49-
# Instal npm dependcies and ensure that npm cache is not stale (these steps are replicated in lib/grunt/utils.js)
50-
- diff -q npm-shrinkwrap.json node_modules/npm-shrinkwrap.cached.json; if [[ $? -ne 0 ]]; then echo 'Shrinkwrap changed! Blowing away node_modules.'; rm -rf node_modules; fi
51-
- time npm install
52-
- cp npm-shrinkwrap.json node_modules/npm-shrinkwrap.cached.json
49+
# Instal npm dependecies and ensure that npm cache is not stale
50+
- scripts/npm/install-dependencies.sh
5351

5452
before_script:
5553
- mkdir -p $LOGS_DIR

Gruntfile.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ module.exports = function(grunt) {
1717
NG_VERSION.cdn = versionInfo.cdnVersion;
1818
var dist = 'angular-'+ NG_VERSION.full;
1919

20-
//global beforeEach
21-
util.init();
22-
23-
2420
//config
2521
grunt.initConfig({
2622
NG_VERSION: NG_VERSION,
@@ -285,6 +281,10 @@ module.exports = function(grunt) {
285281
},
286282

287283
shell: {
284+
"npm-install": {
285+
command: 'scripts/npm/install-dependencies.sh'
286+
},
287+
288288
"promises-aplus-tests": {
289289
options: {
290290
stdout: false,
@@ -311,6 +311,10 @@ module.exports = function(grunt) {
311311
}
312312
});
313313

314+
// global beforeEach task
315+
if (!process.env.TRAVIS) {
316+
grunt.task.run('shell:npm-install');
317+
}
314318

315319
//alias tasks
316320
grunt.registerTask('test', 'Run unit, docs and e2e tests with Karma', ['jshint', 'jscs', 'package','test:unit','test:promises-aplus', 'tests:docs', 'test:protractor']);

lib/grunt/utils.js

-10
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP
1414

1515
module.exports = {
1616

17-
init: function() {
18-
if (!process.env.TRAVIS) {
19-
// replicated from .travis.yaml
20-
shell.exec("diff -q npm-shrinkwrap.json node_modules/npm-shrinkwrap.cached.json; if [[ $? -ne 0 ]]; then echo 'Shrinkwrap changed! Blowing away node_modules.'; rm -rf node_modules; fi");
21-
shell.exec('npm install');
22-
shell.exec('cp npm-shrinkwrap.json node_modules/npm-shrinkwrap.cached.json');
23-
}
24-
},
25-
26-
2717
startKarma: function(config, singleRun, done){
2818
var browsers = grunt.option('browsers');
2919
var reporters = grunt.option('reporters');

scripts/clean-shrinkwrap.js scripts/npm/clean-shrinkwrap.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
var _ = require('lodash');
1111
var sorted = require('sorted-object');
1212
var fs = require('fs');
13+
var path = require('path');
1314

1415

1516
function cleanModule(module, name) {
@@ -27,10 +28,11 @@ function cleanModule(module, name) {
2728

2829

2930
console.log('Reading npm-shrinkwrap.json');
30-
var shrinkwrap = require('./../npm-shrinkwrap.json');
31+
var shrinkwrap = require('../../npm-shrinkwrap.json');
3132

3233
console.log('Cleaning shrinkwrap object');
3334
cleanModule(shrinkwrap, shrinkwrap.name);
3435

35-
console.log('Writing cleaned npm-shrinkwrap.clean.json');
36-
fs.writeFileSync('./npm-shrinkwrap.clean.json', JSON.stringify(sorted(shrinkwrap), null, 2) + "\n");
36+
var cleanShrinkwrapPath = path.join(__dirname, '..', '..', 'npm-shrinkwrap.clean.json');
37+
console.log('Writing cleaned to', cleanShrinkwrapPath);
38+
fs.writeFileSync(cleanShrinkwrapPath, JSON.stringify(sorted(shrinkwrap), null, 2) + "\n");

scripts/npm/install-dependencies.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SHRINKWRAP_FILE=npm-shrinkwrap.json
6+
SHRINKWRAP_CACHED_FILE=node_modules/npm-shrinkwrap.cached.json
7+
8+
if diff -q $SHRINKWRAP_FILE $SHRINKWRAP_CACHED_FILE; then
9+
echo 'No shrinkwrap changes detected. npm install will be skipped...';
10+
else
11+
echo 'Blowing away node_modules and reinstalling npm dependencies...'
12+
rm -rf node_modules
13+
npm install
14+
cp $SHRINKWRAP_FILE $SHRINKWRAP_CACHED_FILE
15+
echo 'npm install successful!'
16+
fi

0 commit comments

Comments
 (0)