Added support for custom output folders
continuous-integration/drone/push Build is passing Details

closes #3
This commit is contained in:
Nicolai Ort 2021-01-02 20:29:05 +01:00
parent 4b89d6419d
commit 6de9475334
3 changed files with 58 additions and 21 deletions

2
.gitignore vendored
View File

@ -126,4 +126,4 @@ dist
.yarn/build-state.yml .yarn/build-state.yml
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
*lock*

View File

@ -2,15 +2,39 @@
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('fs');
const yargs = require('yargs');
const args = process.argv.slice(2); const args = yargs
if (args.includes('--help')) { .option('json', {
console.log(`Arguments: alias: 'j',
--help: View this help page description: 'Exports the license information into ./licenses.json as json.',
--recursive: Include all dependencies' subdependencies type: 'boolean',
--json: Exports the license information into ./licenses.json as json })
--md: Exports the license information into ./licenses.md as markdown`); .option('pretty', {
} alias: 'p',
description: 'Prettify the json output.',
type: 'boolean',
})
.option('markdown', {
alias: 'm',
description: 'Exports the license information into ./licenses.md as markdown.',
type: 'boolean',
})
.option('recursive', {
alias: 'r',
description: 'Include all of the dependencies\' subdependencies.',
type: 'boolean',
})
.option('output', {
alias : 'o',
describe: 'Output folder for the exports. (Default: Current folder)',
type: 'string',
default: '.'
})
.help()
.alias('help', 'h')
.alias('v', 'version')
.argv;
function parsePackageInfo(path) { function parsePackageInfo(path) {
const packagecontents = JSON.parse(fs.readFileSync(path, { encoding: 'utf-8' })); const packagecontents = JSON.parse(fs.readFileSync(path, { encoding: 'utf-8' }));
@ -54,20 +78,20 @@ function getDependencyLicenseInfo(all_dependencies, recursive) {
return all; return all;
} }
const packageInfo = parsePackageInfo(`./package.json`); const packageInfo = parsePackageInfo(`./package.json`);
const all = getDependencyLicenseInfo(mergeDependencies(packageInfo), args.includes('--recursive')); const all = getDependencyLicenseInfo(mergeDependencies(packageInfo), args.recursive);
if (args.includes('--json')) { if (args.json) {
if (args.includes('--pretty')) { if (args.pretty) {
fs.writeFileSync('./licenses.json', JSON.stringify(all, null, 4)); fs.writeFileSync((args.output+'/licenses.json'), JSON.stringify(all, null, 4));
} else { } else {
fs.writeFileSync('./licenses.json', JSON.stringify(all)); fs.writeFileSync((args.output+'/licenses.json'), JSON.stringify(all));
} }
} }
if (args.includes('--md')) { if (args.markdown) {
fs.writeFileSync('./licenses.md', ''); fs.writeFileSync((args.output+'/licenses.md'), '');
all.forEach((p) => { all.forEach((p) => {
fs.appendFileSync( fs.appendFileSync(
'./licenses.md', (args.output+'/licenses.md'),
`# ${p.name}\n**Author**: ${p.author}\n**Repo**: ${p.repo}\n**License**: ${p.license}\n**Description**: ${p.description}\n## License Text\n${p.licensetext} \n\n` `# ${p.name}\n**Author**: ${p.author}\n**Repo**: ${p.repo}\n**License**: ${p.license}\n**Description**: ${p.description}\n## License Text\n${p.licensetext} \n\n`
); );
}); });

View File

@ -1,8 +1,12 @@
{ {
"name": "@odit/license-exporter", "name": "@odit/license-exporter",
"version": "0.0.6", "version": "0.0.7",
"description": "A simple license crawler", "description": "A simple license crawler",
"keywords": [ "license", "ODIT.Services", "cli" ], "keywords": [
"license",
"ODIT.Services",
"cli"
],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://git.odit.services/odit/license-exporter" "url": "https://git.odit.services/odit/license-exporter"
@ -26,7 +30,16 @@
], ],
"main": "exporter.js", "main": "exporter.js",
"bin": { "bin": {
"license-exporter": "./bin/exporter.js" "license-exporter": "bin/exporter.js"
}, },
"files": [ "bin", "exporter.js", "README.md", "package.json", "LICENSE" ] "files": [
"bin",
"exporter.js",
"README.md",
"package.json",
"LICENSE"
],
"dependencies": {
"yargs": "^16.2.0"
}
} }