Created
December 22, 2022 11:39
-
-
Save lukepearson/9632c0d8f0ef6076de5ec949b08209d3 to your computer and use it in GitHub Desktop.
Generate a csv containing a list of all of the licences used in nodejs projects in a subdirectories
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
const { execSync } = require('child_process'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const startingDir = __dirname | |
const walkSync = (dir) => { | |
fs.readdirSync(dir).forEach(file => { | |
if (fs.statSync(path.join(dir, file)).isDirectory()) { | |
if (file === 'node_modules') return | |
walkSync(path.join(dir, file)) | |
} | |
if (file === 'package.json') { | |
console.log(`checking packages in ${dir}`) | |
const outFile = `${startingDir}/licenses/${dir.replace(/\//g, '-')}.csv` | |
const cmd = `cd ${__dirname}/${dir} && npx license-checker --summary --csv --out ${outFile}` | |
// Run license-checker | |
execSync(cmd) | |
// Remove header row | |
execSync(`sed -i '' '1d' ${outFile}`) | |
// Add newline to end of file | |
execSync(`echo '' >> ${outFile}`) | |
} | |
}); | |
}; | |
// Recursively walk through all directories | |
walkSync('.') | |
// Concat all the csv files into one | |
execSync(`cat ${startingDir}/licenses/*.csv > ${startingDir}/licenses.csv`) | |
execSync('open licenses.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment