Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust license file path #30

Merged
merged 4 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ You could see something like this:
└─ licenses: MIT*
```

## Changes

### Version 3.0.0

From now on, when you give the `--files` option, this tool outputs the path to the _copied_ license files rather than to
the originals. When the `relativeLicensePath` option is given, this path will either be relative to the working
directory or - if also the `out` option is given - relative to the `out` path.

When using the `--out` option, you will not see output in the console, as the output goes into the file specified by
`--out`. When using the `--files` option without `--out` option, you will now get console output, which was not the case
before.

## All options in alphabetical order:

- `--angularCli` is just a synonym for `--plainVertical`
Expand Down
57 changes: 45 additions & 12 deletions bin/license-checker-rseidelsohn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const mkdirp = require('mkdirp');
const path = require('path');
const chalk = require('chalk');
const fs = require('fs');
const cloneDeep = require('lodash.clonedeep');
const hasFailingArg = parsedArgs.failOn || parsedArgs.onlyAllow;

const usageMessage = [
Expand Down Expand Up @@ -47,15 +48,19 @@ const usageMessage = [
'',
' --version The current version',
' --help The text you are reading right now :)',
''
'',
].join('\n');

const kownOptions = Object.keys(args.knownOpts);
const unknownArgs = Object.keys(parsedArgs).filter((arg) => !kownOptions.includes(arg));

if (unknownArgs.length) {
console.error(`license-checker-rseidelsohn@${require('../package.json').version}`, '\n');
console.error(`Error: Unknown option${unknownArgs.length > 1 ? 's' : ''}: ${unknownArgs.map((unknownArg) => `'${unknownArg}'`).join(', ')}`);
console.error(
`Error: Unknown option${unknownArgs.length > 1 ? 's' : ''}: ${unknownArgs
.map((unknownArg) => `'${unknownArg}'`)
.join(', ')}`,
);
console.error(` Possibly a typo? Currently known options are:`);
console.error(usageMessage, '\n');
process.exit(1);
Expand All @@ -79,7 +84,9 @@ if (parsedArgs.failOn && parsedArgs.onlyAllow) {

if (hasFailingArg && hasFailingArg.indexOf(',') >= 0) {
const argName = parsedArgs.failOn ? 'failOn' : 'onlyAllow';
console.warn(`Warning: As of v17 the --${argName} argument takes semicolons as delimeters instead of commas (some license names can contain commas)`);
console.warn(
`Warning: As of v17 the --${argName} argument takes semicolons as delimeters instead of commas (some license names can contain commas)`,
);
}

licenseChecker.init(parsedArgs, function (err, json) {
Expand All @@ -105,7 +112,9 @@ licenseChecker.init(parsedArgs, function (err, json) {
mkdirp.sync(dir);
fs.writeFileSync(parsedArgs.out, formattedOutput, 'utf8');
}
} else {
}

if (!parsedArgs.out) {
console.log(formattedOutput);
}
});
Expand All @@ -117,33 +126,57 @@ function shouldColorizeOutput(args) {
function colorizeOutput(json) {
Object.keys(json).forEach((key) => {
const index = key.lastIndexOf('@');
const colorizedKey = chalk.white.bgKeyword('darkslategrey')(key.substr(0, index)) + chalk.dim('@') + chalk.white.bgKeyword('green')(key.substr(index + 1));
const colorizedKey =
chalk.white.bgKeyword('darkslategrey')(key.substr(0, index)) +
chalk.dim('@') +
chalk.white.bgKeyword('green')(key.substr(index + 1));
json[colorizedKey] = json[key];

delete json[key];
});
}

function getFormattedOutput(json, args) {
const jsonCopy = cloneDeep(json);

if (args.files) {
Object.keys(jsonCopy).forEach((moduleName) => {
const outPath = path.join(args.files, `${moduleName}-LICENSE.txt`);
const originalLicenseFile = jsonCopy[moduleName].licenseFile;

if (originalLicenseFile && fs.existsSync(originalLicenseFile)) {
if (args.relativeLicensePath) {
if (args.out) {
jsonCopy[moduleName].licenseFile = path.relative(args.out, outPath);
} else {
jsonCopy[moduleName].licenseFile = path.relative(process.cwd(), outPath);
}
} else {
jsonCopy[moduleName].licenseFile = outPath;
}
}
});
}

if (args.json) {
return JSON.stringify(json, null, 4) + '\n';
return JSON.stringify(jsonCopy, null, 4) + '\n';
}

if (args.csv) {
return licenseChecker.asCSV(json, args.customFormat, args.csvComponentPrefix);
return licenseChecker.asCSV(jsonCopy, args.customFormat, args.csvComponentPrefix);
}

if (args.markdown){
return licenseChecker.asMarkDown(json, args.customFormat) + "\n";
if (args.markdown) {
return licenseChecker.asMarkDown(jsonCopy, args.customFormat) + '\n';
}

if (args.summary) {
return licenseChecker.asSummary(json);
return licenseChecker.asSummary(jsonCopy);
}

if (args.plainVertical || args.angluarCli) {
return licenseChecker.asPlainVertical(json);
return licenseChecker.asPlainVertical(jsonCopy);
}

return licenseChecker.asTree(json);
return licenseChecker.asTree(jsonCopy);
}
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "license-checker-rseidelsohn",
"description": "Feature enhanced version of the original license-checker v25.0.1",
"author": "Roman Seidelsohn <rseidelsohn@gmail.com>",
"version": "2.4.8",
"version": "3.0.0",
"license": "BSD-3-Clause",
"contributors": [
"Adam Weber <adamweber01@gmail.com>",
Expand Down Expand Up @@ -67,6 +67,7 @@
"dependencies": {
"chalk": "^4.1.2",
"debug": "^4.3.2",
"lodash.clonedeep": "^4.5.0",
"mkdirp": "^1.0.4",
"nopt": "^5.0.0",
"read-installed-packages": "^1.0.0",
Expand Down