Last active
May 31, 2017 07:51
-
-
Save wildlyinaccurate/f81f9b43c6cd5bbc029ac409a0a4abb1 to your computer and use it in GitHub Desktop.
Check any Morph-powered page for duplicate styles.
This file contains hidden or 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
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