Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #33 from Financial-Times/verify-layouts
Browse files Browse the repository at this point in the history
added task to verify bower templates used in layouts exist
  • Loading branch information
wheresrhys committed Mar 27, 2015
2 parents a575f38 + 6a2dfdb commit 0fda8b8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bin/next-build-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var clean = require('../tasks/clean');
var configure = require('../tasks/configure');
var provision = require('../tasks/provision');
var verify = require('../tasks/verify');
var verifyLayoutDeps = require('../tasks/verify-layout-deps');
var destroy = require('../tasks/destroy');
var nightwatch = require('../tasks/nightwatch');
var downloadConfiguration = require('../tasks/download-configuration');
Expand Down Expand Up @@ -77,6 +78,13 @@ program
verify().catch(exit);
});

program
.command('verify-layout-deps')
.description('Verifies that the application has installed compatible versions of bower components which provide templates used by page layouts contained in ft-next-express')
.action(function() {
verifyLayoutDeps().catch(exit);
});

program
.command('nightwatch [test]')
.option('-c, --config <config>', 'The location of the nightwatch.json, defaults to Next Build Tools nightwatch.json')
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"glob": "^5.0.3",
"haikro": "^1.13.0",
"heroku-client": "^1.9.1",
"isomorphic-fetch": "^2.0.0"
"isomorphic-fetch": "^2.0.0",
"semver": "^4.3.1"
},
"devDependencies": {
"npm-prepublish": "^1.2.0",
Expand Down
32 changes: 32 additions & 0 deletions tasks/verify-layout-deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
var semver = require('semver');
var fs = require('fs');
var path = require('path');

module.exports = function() {
return new Promise(function (resolve, reject) {
var layoutBowerDeps;

try {
layoutBowerDeps = require(path.join(process.cwd(), 'node_modules/ft-next-express/bower.json')).dependencies;
} catch (e) {
console.log('No layout bower template dependencies found. Updating ft-next-express recommended');
resolve();
}

Object.keys(layoutBowerDeps).forEach(function (dep) {
if (!fs.exists(path.join(process.cwd(), 'bower_components', dep, '.bower.json'))) {
reject('This app needs to bower install ' + dep + '#' + layoutBowerDeps[dep] + ' in order to render layouts');
}
var appSemver = require(path.join(process.cwd(), 'bower_components', dep, '.bower.json')).version;

if (!semver.satisfies(appSemver, layoutBowerDeps[dep])) {
reject('This app needs to install a version of ' + dep + ' compatible with the semver ' + layoutBowerDeps[dep] + ' in order to render layouts');
}
});

console.log('Layout bower template dependencies OK');
resolve();
});

};

0 comments on commit 0fda8b8

Please sign in to comment.