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 #209 from Financial-Times/matth/remove-old-layout-…
Browse files Browse the repository at this point in the history
…checks

Replace next express layout checks with n-layout ones
  • Loading branch information
i-like-robots committed Sep 2, 2015
2 parents 9ac1072 + c03612c commit b17e5f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 114 deletions.
6 changes: 2 additions & 4 deletions bin/next-build-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@ program
.option('--skip-layout-checks', 'run verify checks when the application doesn\'t have customer facing html pages')
.option('--skip-npm-checks', 'skip npm dependency checks')
.option('--skip-dotenv-check', 'skip checking `.gitignore` has `.env` in it')
.option('-l, --layout [type]', 'Only check dependencies whose templates are needed in this layout')
.description('internally calls origami-build-tools verify with some Next specific configuration (use only for APPLICATIONS. Front End components should continue to use origami-build-tools verify)')
.description('internally calls origami-build-tools verify with some Next specific configuration (use only for APPLICATIONS. Front End components should continue to use origami-build-tools verify)')
.action(function(opts) {
verify({
skipLayoutChecks: opts.skipLayoutChecks,
skipNpmChecks: opts.skipNpmChecks,
skipDotenvCheck: opts.skipDotenvCheck,
layout: opts.layout
skipDotenvCheck: opts.skipDotenvCheck
}).catch(exit);
});

Expand Down
62 changes: 17 additions & 45 deletions lib/verify-layout-deps.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,37 @@
'use strict';
var semver = require('semver');

var fs = require('fs');
var path = require('path');

module.exports = function(opts) {
opts = opts || {};

module.exports = function() {
return new Promise(function(resolve, reject) {
var layoutBowerDeps;
var layout = opts.layout || 'wrapper';
var nLayoutPath = path.join(process.cwd(), 'bower_components/n-layout');
var templatePath = path.join(nLayoutPath, 'templates/wrapper.html');

console.log('Checking bower dependencies for layout ' + layout);
console.log('Checking Bower dependencies for n-layout');
console.log('If this app doesn\'t render any templates call nbt verify with --skip-layout-checks');

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.warn('No layout bower template dependencies found. Updating ft-next-express recommended');
resolve();
if (!fs.existsSync(templatePath)) {
reject('n-layout could not be found');
return;
}

Object.keys(layoutBowerDeps).forEach(function(dep) {

// 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;
}
var appBowerDeps = require(path.join(process.cwd(), 'bower.json')).dependencies;
var nLayoutBowerDeps = require(path.join(nLayoutPath, 'bower.json')).dependencies;

// test to see if the component is a compatible version
var bowerJson = require(path.join(process.cwd(), 'bower_components', dep, '.bower.json'));
var appSemver = bowerJson.version;
if (!appSemver) {
if (bowerJson._resolution.type === 'branch') {
console.warn('This app is using a non-versioned release of ' + dep);
console.warn('It\'s ok to do so while experimenting, but longer term try to revert to using a semvered version');
} else {
reject('Unknown bower resolution for ' + dep + '. Use a branch or semver');
}
} else {
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');
}
}
Object.keys(nLayoutBowerDeps).forEach(function(dep) {
if (appBowerDeps.hasOwnProperty(dep)) {
reject('n-layout handles ' + dep + ' now so your app doesn\'t have to. Remove ' + dep + ' from your Bower manifest');
}
});

if (appBowerDeps.hasOwnProperty('next-express')) {
reject('do not try to install next-express as Bower dependency');
}

resolve();
}).then(function() {
console.log('Layout bower template dependencies OK');
console.log('n-layout bower dependencies OK');
});

};
65 changes: 0 additions & 65 deletions lib/verify-npm-bower-parity.js

This file was deleted.

0 comments on commit b17e5f3

Please sign in to comment.