Skip to content

Instantly share code, notes, and snippets.

@wildlyinaccurate
Last active May 31, 2017 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wildlyinaccurate/f81f9b43c6cd5bbc029ac409a0a4abb1 to your computer and use it in GitHub Desktop.
Save wildlyinaccurate/f81f9b43c6cd5bbc029ac409a0a4abb1 to your computer and use it in GitHub Desktop.
Check any Morph-powered page for duplicate styles.
var page = require('webpage').create()
var system = require('system')
if (system.args.length === 1) {
console.log('Usage: morph-style-checker.js <URL>')
phantom.exit(1)
}
var url = system.args[1]
page.open(url, function (status) {
if (status !== 'success') {
console.log('Page load failed.')
phantom.exit(1)
}
var styles = page.evaluate(function () {
return Object.keys(Morph.styles)
})
var versions = {}
styles.forEach(function (style) {
var parts = style.split('/')
var version = parts.splice(1, 1)
var module = parts.join('/')
if (!versions[module]) versions[module] = []
versions[module].push(version)
})
var exitCode = 0
Object.keys(versions).forEach(function (module) {
if (versions[module].length > 1) {
console.log(module, 'has multiple versions:', versions[module].sort().join(', '))
exitCode = 1
}
})
phantom.exit(exitCode)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment