This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from Financial-Times/matth/remove-old-layout-…
…checks Replace next express layout checks with n-layout ones
- Loading branch information
Showing
3 changed files
with
19 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
||
}; |
This file was deleted.
Oops, something went wrong.