0.0.5 w/ cli fixes
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
b34105be8a
commit
923a496ee7
10
README.md
10
README.md
|
@ -13,13 +13,13 @@ yarn add @odit/license-exporter
|
||||||
npm i @odit/license-exporter
|
npm i @odit/license-exporter
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use
|
## CLI Usage
|
||||||
|
|
||||||
Export only your dependencies to json: `license-exporter --json`
|
Export only your dependencies to json: `licenseexporter --json`
|
||||||
Export all dependencies to json: `license-exporter --json --recursive`
|
Export all dependencies to json: `licenseexporter --json --recursive`
|
||||||
|
|
||||||
Export only your dependencies to markdown: `license-exporter --md`
|
Export only your dependencies to markdown: `licenseexporter --md`
|
||||||
Export all dependencies to markdown: `license-exporter --md --recursive`
|
Export all dependencies to markdown: `licenseexporter --md --recursive`
|
||||||
|
|
||||||
## Arguments
|
## Arguments
|
||||||
Arg | Description
|
Arg | Description
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
if (args.includes('--help')) {
|
||||||
|
console.log(`Arguments:
|
||||||
|
--help: View this help page
|
||||||
|
--recursive: Include all dependencies' subdependencies
|
||||||
|
--json: Exports the license information into ./licenses.json as json
|
||||||
|
--md: Exports the license information into ./licenses.md as markdown`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parsePackageInfo(path) {
|
||||||
|
const packagecontents = JSON.parse(fs.readFileSync(path, { encoding: 'utf-8' }));
|
||||||
|
packagecontents.dependencies = Object.entries(packagecontents.dependencies || {});
|
||||||
|
packagecontents.devDependencies = Object.entries(packagecontents.devDependencies || {});
|
||||||
|
return packagecontents;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeDependencies(packageInfo) {
|
||||||
|
return [].concat(packageInfo.dependencies, packageInfo.devDependencies);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDependencyLicenseInfo(all_dependencies, recursive) {
|
||||||
|
let all = [];
|
||||||
|
|
||||||
|
all_dependencies.forEach((p) => {
|
||||||
|
const packageinfo = parsePackageInfo(`./node_modules/${p[0]}/package.json`);
|
||||||
|
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);
|
||||||
|
if (recursive == true) {
|
||||||
|
all.push(...getDependencyLicenseInfo(packageinfo.dependencies, true));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
const packageInfo = parsePackageInfo(`./package.json`);
|
||||||
|
const all = getDependencyLicenseInfo(mergeDependencies(packageInfo), args.includes('--recursive'));
|
||||||
|
|
||||||
|
if (args.includes('--json')) {
|
||||||
|
if (args.includes('--pretty')) {
|
||||||
|
fs.writeFileSync('./licenses.json', JSON.stringify(all, null, 4));
|
||||||
|
} else {
|
||||||
|
fs.writeFileSync('./licenses.json', JSON.stringify(all));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (args.includes('--md')) {
|
||||||
|
fs.writeFileSync('./licenses.md', '');
|
||||||
|
all.forEach((p) => {
|
||||||
|
fs.appendFileSync(
|
||||||
|
'./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`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return all;
|
||||||
|
}
|
73
exporter.js
73
exporter.js
|
@ -1,72 +1 @@
|
||||||
const fs = require('fs');
|
console.log('API usage not implemented yet...');
|
||||||
|
|
||||||
const args = process.argv.slice(2);
|
|
||||||
if(args.includes("--help")){
|
|
||||||
console.log(`Arguments:
|
|
||||||
--help: View this help page
|
|
||||||
--recursive: Include all dependencies' subdependencies
|
|
||||||
--json: Exports the license information into ./licenses.json as json
|
|
||||||
--md: Exports the license information into ./licenses.md as markdown`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parsePackageInfo(path) {
|
|
||||||
const packagecontents = JSON.parse(fs.readFileSync(path, { encoding: 'utf-8' }));
|
|
||||||
packagecontents.dependencies = Object.entries(packagecontents.dependencies || {});
|
|
||||||
packagecontents.devDependencies = Object.entries(packagecontents.devDependencies || {});
|
|
||||||
return packagecontents;
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeDependencies(packageInfo) {
|
|
||||||
return [].concat(packageInfo.dependencies, packageInfo.devDependencies);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDependencyLicenseInfo(all_dependencies, recursive) {
|
|
||||||
let all = [];
|
|
||||||
|
|
||||||
all_dependencies.forEach((p) => {
|
|
||||||
const packageinfo = parsePackageInfo(`./node_modules/${p[0]}/package.json`);
|
|
||||||
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);
|
|
||||||
if (recursive == true) {
|
|
||||||
all.push(...getDependencyLicenseInfo(packageinfo.dependencies, true));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return all;
|
|
||||||
}
|
|
||||||
const packageInfo = parsePackageInfo(`./package.json`);
|
|
||||||
const all = getDependencyLicenseInfo(mergeDependencies(packageInfo), args.includes("--recursive"));
|
|
||||||
|
|
||||||
if (args.includes("--json")) {
|
|
||||||
if (args.includes("--pretty")) {
|
|
||||||
fs.writeFileSync('./licenses.json', JSON.stringify(all, null, 4));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fs.writeFileSync('./licenses.json', JSON.stringify(all));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (args.includes("--md")) {
|
|
||||||
fs.writeFileSync('./licenses.md', "");
|
|
||||||
all.forEach((p) => {
|
|
||||||
fs.appendFileSync("./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`)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return all;
|
|
||||||
}
|
|
||||||
|
|
56
package.json
56
package.json
|
@ -1,28 +1,32 @@
|
||||||
{
|
{
|
||||||
"name": "@odit/license-exporter",
|
"name": "@odit/license-exporter",
|
||||||
"version": "0.0.3",
|
"version": "0.0.5",
|
||||||
"description": "A simple license crawler",
|
"description": "A simple license crawler",
|
||||||
"main": "./export.js",
|
"keywords": [ "license", "ODIT.Services", "cli" ],
|
||||||
"bin": "./export.js",
|
"repository": {
|
||||||
"author": "ODIT.Services",
|
"type": "git",
|
||||||
"license": "MIT",
|
"url": "https://git.odit.services/odit/license-exporter"
|
||||||
"contributors": [
|
},
|
||||||
{
|
"author": "ODIT.Services",
|
||||||
"name": "Philipp Dormann",
|
"license": "MIT",
|
||||||
"email": "philipp@philippdormann.de",
|
"publishConfig": {
|
||||||
"url": "https://philippdormann.de"
|
"access": "public"
|
||||||
},
|
},
|
||||||
{
|
"contributors": [
|
||||||
"name": "Nicolai Ort",
|
{
|
||||||
"email": "info@nicolai-ort.com",
|
"name": "Philipp Dormann",
|
||||||
"url": "https://nicolai-ort.com"
|
"email": "philipp@philippdormann.de",
|
||||||
}
|
"url": "https://philippdormann.de"
|
||||||
],
|
},
|
||||||
"keywords": [
|
{
|
||||||
"license"
|
"name": "Nicolai Ort",
|
||||||
],
|
"email": "info@nicolai-ort.com",
|
||||||
"repository": {
|
"url": "https://nicolai-ort.com"
|
||||||
"type": "git",
|
}
|
||||||
"url": "https://git.odit.services/odit/license-exporter"
|
],
|
||||||
}
|
"main": "exporter.js",
|
||||||
|
"bin": {
|
||||||
|
"licenseexport": "./bin/exporter.js"
|
||||||
|
},
|
||||||
|
"files": [ "bin" ]
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue