From 37aa03cb097246f78199f4dd0700e45d0d99d7b4 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Thu, 31 Dec 2020 15:26:21 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=90=20initial=20export=20script=20w/?= =?UTF-8?q?=20basics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exporter.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 exporter.js diff --git a/exporter.js b/exporter.js new file mode 100644 index 0000000..63e4bb4 --- /dev/null +++ b/exporter.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const packagecontents = JSON.parse(fs.readFileSync('./package.json')); +// +packagecontents.dependencies = Object.entries(packagecontents.dependencies); +packagecontents.devDependencies = Object.entries(packagecontents.devDependencies); +const all_dependencies = [].concat(packagecontents.dependencies, packagecontents.devDependencies); +let all = []; +(() => { + all_dependencies.forEach((p) => { + const packageinfo = JSON.parse(fs.readFileSync(`./node_modules/${p[0]}/package.json`, { encoding: 'utf-8' })); + let licensetext = ''; + if (fs.existsSync(`./node_modules/${p[0]}/LICENSE.md`)) { + licensetext = fs.readFileSync(`./node_modules/${p[0]}/LICENSE.md`, { encoding: 'utf-8' }); + } + if (fs.existsSync(`./node_modules/${p[0]}/LICENSE`)) { + licensetext = fs.readFileSync(`./node_modules/${p[0]}/LICENSE`, { encoding: 'utf-8' }); + } + if (fs.existsSync(`./node_modules/${p[0]}/LICENSE.txt`)) { + licensetext = fs.readFileSync(`./node_modules/${p[0]}/LICENSE.txt`, { encoding: 'utf-8' }); + } + const info = { + author: packageinfo.author, + repo: packageinfo.repository || packageinfo.repository.url, + description: packageinfo.description, + name: packageinfo.name, + license: packageinfo.license, + licensetext + }; + all.push(info); + }); + fs.writeFileSync('./licenses.json', JSON.stringify(all)); +})();