-
-
Save icetee/0cf64b4ba53ce52e1a6bd11cce021cb2 to your computer and use it in GitHub Desktop.
This script displays dependency relations between packages required by a Meteor project
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
"use strict"; | |
const execSync = require('child_process').execSync; | |
const fs = require('fs'); | |
function run(command) { | |
return execSync(command).toString().trim(); | |
} | |
console.log("Reading 'versions' file..."); | |
let versions = fs.readFileSync(".meteor/versions").toString().split("\n").filter(x => x != ""); | |
let packages = versions.map(version => { | |
let s = version.split("@"); | |
return { | |
name: s[0], | |
version: s[1], | |
deps: [], | |
depBy: [], | |
}; | |
}); | |
console.log("Querying Meteor packages..."); | |
packages.forEach(pack => { | |
console.log(pack.name); | |
try { | |
let description = run(`meteor show --ejson ${pack.name}@${pack.version}`); | |
let parsed = JSON.parse(description); | |
parsed["dependencies"].forEach(dep => { | |
let depPack = packages.find(x => x.name == dep.name); | |
if (!!depPack) { | |
if (dep.weak) { | |
depPack.depBy.push(pack.name + " (weak)"); | |
pack.deps.push(depPack.name + " (weak)"); | |
} else { | |
depPack.depBy.push(pack.name); | |
pack.deps.push(depPack.name); | |
} | |
} | |
}); | |
} catch (er) {} | |
}); | |
let output = ''; | |
output += "Package dependencies\n"; | |
output += "====================\n\n"; | |
packages.forEach(pack => { | |
output += `${pack.name}@${pack.version}`; | |
output += " depends on:\n"; | |
pack.deps.forEach(x => { | |
output += ` -${x}\n`; | |
}); | |
output += " depended by:"; | |
pack.depBy.forEach(x => { | |
output += ` -${x}\n`; | |
}); | |
}); | |
fs.writeFile('./meteordeps.txt', output, (err) => { | |
if (err) throw err; | |
console.log('Packages save in the file.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment