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 #36 from Financial-Times/verify-vanilla-layout
Browse files Browse the repository at this point in the history
possible to pick a layout to verify bower deps against
  • Loading branch information
wheresrhys committed Mar 27, 2015
2 parents c46d5f2 + 2fade06 commit dfbfd0e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
7 changes: 5 additions & 2 deletions bin/next-build-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ program

program
.command('verify-layout-deps')
.option('-l, --layout [type]', 'Only check dependencies whose templates are needed in this layout')
.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);
.action(function(options) {
verifyLayoutDeps({
layout: options.layout || 'wrapper'
}).catch(exit);
});

program
Expand Down
36 changes: 28 additions & 8 deletions tasks/verify-layout-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,45 @@ var semver = require('semver');
var fs = require('fs');
var path = require('path');

module.exports = function() {
module.exports = function (opts) {

return new Promise(function (resolve, reject) {
var layoutBowerDeps;
var layout = opts.layout || 'wrapper';

console.log('Checking bower dependencies for layout ' + layout);

if (!fs.existsSync(path.join(process.cwd(), 'node_modules/ft-next-express/layouts/', layout + '.html'))) {
reject('Please specify a valid layout to check template dependencies for');
return;
}

var tpl = fs.readFileSync(path.join(process.cwd(), 'node_modules/ft-next-express/layouts/', layout + '.html'), 'utf8');

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');
console.warn('No layout bower template dependencies found. Updating ft-next-express recommended');
resolve();
return;
}

Object.keys(layoutBowerDeps).forEach(function (dep) {
if (!fs.existsSync(path.join(process.cwd(), 'bower_components', dep, '.bower.json'))) {
reject('This app needs to bower install ' + dep + (layoutBowerDeps[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');
// test to see if the layout we're using actually references the given bower component
if (new RegExp('\{\{>\s*' + dep).test(tpl)) {

// test to see if the bower component is installed
if (!fs.existsSync(path.join(process.cwd(), 'bower_components', dep, '.bower.json'))) {
reject('This app needs to bower install ' + dep + (layoutBowerDeps[dep] !== '*' ? ('#' + layoutBowerDeps[dep]) : '') + ' in order to render layouts');
return;
}

// test to see if the component is a compatible version
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');
}
}
});

Expand Down

0 comments on commit dfbfd0e

Please sign in to comment.