Skip to content

Instantly share code, notes, and snippets.

@leostaples
Created June 27, 2019 16:59
Show Gist options
  • Save leostaples/01622f7c77f9a73e2275e67583f2985f to your computer and use it in GitHub Desktop.
Save leostaples/01622f7c77f9a73e2275e67583f2985f to your computer and use it in GitHub Desktop.
Script to find recursively search lx-page dependencies to find which ones reference bbc-morph-grandstand
function parseDependencies(module) {
console.log("parseDependencies", module);
if (!parseDependencies.results) parseDependencies.results = [];
if (!parseDependencies.seenBefore) parseDependencies.seenBefore = {};
if (!(module in parseDependencies.seenBefore)) {
parseDependencies.seenBefore[module] = true;
var package_json = require('/Users/stapll/code/morph-modules/' + module + '/package.json');
var dependencies = package_json.dependencies;
if (dependencies.hasOwnProperty('bbc-morph-grandstand')) {
parseDependencies.results.push(module);
}
for (var module in dependencies) {
var regex = /^bbc-morph-(.*)/;
var found = module.match(regex);
if (found && found[1] !== 'grandstand') {
parseDependencies(found[1])
}
}
}
return parseDependencies.results;
}
var results = parseDependencies('lx-page');
console.log("Results: ", results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment