Skip to content

Commit

Permalink
chore(travis,grunt): extract the npm install and cache busting logic …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
IgorMinar committed Feb 22, 2015
1 parent a773f89 commit 0356d72
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ install:
# Log HTTP requests
- npm config set loglevel http
- npm install -g [email protected]
# Instal npm dependcies and ensure that npm cache is not stale (these steps are replicated in lib/grunt/utils.js)
- 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
- time npm install
- cp npm-shrinkwrap.json node_modules/npm-shrinkwrap.cached.json
# Instal npm dependecies and ensure that npm cache is not stale
- scripts/npm/install-dependencies.sh

before_script:
- mkdir -p $LOGS_DIR
Expand Down
12 changes: 8 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ module.exports = function(grunt) {
NG_VERSION.cdn = versionInfo.cdnVersion;
var dist = 'angular-'+ NG_VERSION.full;

//global beforeEach
util.init();


//config
grunt.initConfig({
NG_VERSION: NG_VERSION,
Expand Down Expand Up @@ -285,6 +281,10 @@ module.exports = function(grunt) {
},

shell: {
"npm-install": {
command: 'scripts/npm/install-dependencies.sh'
},

"promises-aplus-tests": {
options: {
stdout: false,
Expand All @@ -311,6 +311,10 @@ module.exports = function(grunt) {
}
});

// global beforeEach task
if (!process.env.TRAVIS) {
grunt.task.run('shell:npm-install');
}

//alias tasks
grunt.registerTask('test', 'Run unit, docs and e2e tests with Karma', ['jshint', 'jscs', 'package','test:unit','test:promises-aplus', 'tests:docs', 'test:protractor']);
Expand Down
10 changes: 0 additions & 10 deletions lib/grunt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP

module.exports = {

init: function() {
if (!process.env.TRAVIS) {
// replicated from .travis.yaml
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");
shell.exec('npm install');
shell.exec('cp npm-shrinkwrap.json node_modules/npm-shrinkwrap.cached.json');
}
},


startKarma: function(config, singleRun, done){
var browsers = grunt.option('browsers');
var reporters = grunt.option('reporters');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
var _ = require('lodash');
var sorted = require('sorted-object');
var fs = require('fs');
var path = require('path');


function cleanModule(module, name) {
Expand All @@ -27,10 +28,11 @@ function cleanModule(module, name) {


console.log('Reading npm-shrinkwrap.json');
var shrinkwrap = require('./../npm-shrinkwrap.json');
var shrinkwrap = require('../../npm-shrinkwrap.json');

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

console.log('Writing cleaned npm-shrinkwrap.clean.json');
fs.writeFileSync('./npm-shrinkwrap.clean.json', JSON.stringify(sorted(shrinkwrap), null, 2) + "\n");
var cleanShrinkwrapPath = path.join(__dirname, '..', '..', 'npm-shrinkwrap.clean.json');
console.log('Writing cleaned to', cleanShrinkwrapPath);
fs.writeFileSync(cleanShrinkwrapPath, JSON.stringify(sorted(shrinkwrap), null, 2) + "\n");
16 changes: 16 additions & 0 deletions scripts/npm/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

SHRINKWRAP_FILE=npm-shrinkwrap.json
SHRINKWRAP_CACHED_FILE=node_modules/npm-shrinkwrap.cached.json

if diff -q $SHRINKWRAP_FILE $SHRINKWRAP_CACHED_FILE; then
echo 'No shrinkwrap changes detected. npm install will be skipped...';
else
echo 'Blowing away node_modules and reinstalling npm dependencies...'
rm -rf node_modules
npm install
cp $SHRINKWRAP_FILE $SHRINKWRAP_CACHED_FILE
echo 'npm install successful!'
fi

0 comments on commit 0356d72

Please sign in to comment.