Created
December 4, 2021 16:02
-
-
Save liamegan/079e9326a9937778276abc2c30e28c3d to your computer and use it in GitHub Desktop.
A quick and dirty node shell script to get all of the production licenses from a package.
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
#!/usr/bin/env node | |
const { exec } = require("child_process") | |
async function run() { | |
let deps | |
exec("npm list --prod --depth=0 --json", (error, stdout, stderr) => { | |
if (error) { | |
console.log(`error: ${error.message}`) | |
return | |
} | |
if (stderr) { | |
console.log(`stderr: ${stderr}`) | |
return | |
} | |
deps = JSON.parse(stdout) | |
// console.log(deps) | |
let list = [] | |
for (let i in deps.dependencies) { | |
list.push(deps.dependencies[i].from) | |
} | |
exec( | |
`npx license-checker --packages "${list.join(";")}" --json`, | |
(error, stdout, stderr) => { | |
if (error) { | |
console.log(`error: ${error.message}`) | |
return | |
} | |
if (stderr) { | |
console.log(`stderr: ${stderr}`) | |
return | |
} | |
deps = JSON.parse(stdout) | |
console.log(deps) | |
} | |
) | |
}) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment