Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate markdown file from package-lock.json
// Run: node packageLock2Markdown.js "C:\..PATH..\package-lock.json" > out.md
const fs = require('fs');
const args = process.argv.slice(2);
let markdownOutput = '';
const contents = JSON.parse(fs.readFileSync(args[0], 'utf8'));
markdownOutput += `# Package: ${contents.name}`;
Object.keys(contents.dependencies).map(subPackageName => {
const content = contents.dependencies[subPackageName];
const requires = content.requires;
const dependencies = content.dependencies;
markdownOutput += `
## ${subPackageName}
**Version:** [${content.version}](${content.resolved})
**Requires (${Object.keys(requires || {}).length} pks):** ${Object.keys(requires || {}).map(r => `_${r} (${requires[r]})_`).join(', ')}
**Dependencies (${Object.keys(dependencies || {}).length} pks):** ${Object.keys(dependencies || {}).map(r => `_${r} (${dependencies[r]})_`).join(', ')}
`;
})
console.log(markdownOutput)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment