Added custom input folder location as parameter
All checks were successful
continuous-integration/drone/push Build is passing

closes #1
This commit is contained in:
Nicolai Ort 2021-01-02 20:36:07 +01:00
parent 6de9475334
commit 6fbf02e0e4
2 changed files with 17 additions and 11 deletions

View File

@ -27,7 +27,13 @@ const args = yargs
}) })
.option('output', { .option('output', {
alias : 'o', alias : 'o',
describe: 'Output folder for the exports. (Default: Current folder)', describe: 'Output folder for the exports (Default: Current folder).',
type: 'string',
default: '.'
})
.option('input', {
alias : 'i',
describe: 'Path to the input folder containing your package.json and node_modules (Default: Current folder).',
type: 'string', type: 'string',
default: '.' default: '.'
}) })
@ -51,16 +57,16 @@ function getDependencyLicenseInfo(all_dependencies, recursive) {
let all = []; let all = [];
all_dependencies.forEach((p) => { all_dependencies.forEach((p) => {
const packageinfo = parsePackageInfo(`./node_modules/${p[0]}/package.json`); const packageinfo = parsePackageInfo(`${args.input}/node_modules/${p[0]}/package.json`);
let licensetext = ''; let licensetext = '';
if (fs.existsSync(`./node_modules/${p[0]}/LICENSE.md`)) { if (fs.existsSync(`${args.input}/node_modules/${p[0]}/LICENSE.md`)) {
licensetext = fs.readFileSync(`./node_modules/${p[0]}/LICENSE.md`, { encoding: 'utf-8' }); licensetext = fs.readFileSync(`${args.input}/node_modules/${p[0]}/LICENSE.md`, { encoding: 'utf-8' });
} }
if (fs.existsSync(`./node_modules/${p[0]}/LICENSE`)) { if (fs.existsSync(`${args.input}/node_modules/${p[0]}/LICENSE`)) {
licensetext = fs.readFileSync(`./node_modules/${p[0]}/LICENSE`, { encoding: 'utf-8' }); licensetext = fs.readFileSync(`${args.input}/node_modules/${p[0]}/LICENSE`, { encoding: 'utf-8' });
} }
if (fs.existsSync(`./node_modules/${p[0]}/LICENSE.txt`)) { if (fs.existsSync(`${args.input}/node_modules/${p[0]}/LICENSE.txt`)) {
licensetext = fs.readFileSync(`./node_modules/${p[0]}/LICENSE.txt`, { encoding: 'utf-8' }); licensetext = fs.readFileSync(`${args.input}/node_modules/${p[0]}/LICENSE.txt`, { encoding: 'utf-8' });
} }
const info = { const info = {
author: packageinfo.author, author: packageinfo.author,
@ -77,7 +83,7 @@ function getDependencyLicenseInfo(all_dependencies, recursive) {
}); });
return all; return all;
} }
const packageInfo = parsePackageInfo(`./package.json`); const packageInfo = parsePackageInfo(`${args.input}/package.json`);
const all = getDependencyLicenseInfo(mergeDependencies(packageInfo), args.recursive); const all = getDependencyLicenseInfo(mergeDependencies(packageInfo), args.recursive);
if (args.json) { if (args.json) {

View File

@ -1,7 +1,7 @@
{ {
"name": "@odit/license-exporter", "name": "@odit/license-exporter",
"version": "0.0.7", "version": "0.0.8",
"description": "A simple license crawler", "description": "A simple license crawler for crediting open source work",
"keywords": [ "keywords": [
"license", "license",
"ODIT.Services", "ODIT.Services",