Skip to content

Commit

Permalink
feat(cli): include notice with license when generating disclaimer (#5072
Browse files Browse the repository at this point in the history
) (#5111)
  • Loading branch information
iansu authored and arcanis committed Jan 15, 2018
1 parent b2ce74e commit 05b4e01
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/cli/commands/licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,23 @@ export const {run, examples} = buildSubCommands('licenses', {
// the same license text are grouped together.
const manifestsByLicense: Map<string, Map<string, Manifest>> = new Map();
for (const manifest of manifests) {
const {licenseText} = manifest;
const {licenseText, noticeText} = manifest;
let licenseKey;
if (!licenseText) {
continue;
}

if (!manifestsByLicense.has(licenseText)) {
manifestsByLicense.set(licenseText, new Map());
if (!noticeText) {
licenseKey = licenseText;
} else {
licenseKey = `${licenseText}\n\nNOTICE\n\n${noticeText}`;
}

if (!manifestsByLicense.has(licenseKey)) {
manifestsByLicense.set(licenseKey, new Map());
}

const byLicense = manifestsByLicense.get(licenseText);
const byLicense = manifestsByLicense.get(licenseKey);
invariant(byLicense, 'expected value');
byLicense.set(manifest.name, manifest);
}
Expand All @@ -168,7 +175,7 @@ export const {run, examples} = buildSubCommands('licenses', {
);
console.log();

for (const [licenseText, manifests] of manifestsByLicense) {
for (const [licenseKey, manifests] of manifestsByLicense) {
console.log('-----');
console.log();

Expand All @@ -191,8 +198,8 @@ export const {run, examples} = buildSubCommands('licenses', {
console.log(heading.join(' '));
console.log();

if (licenseText) {
console.log(licenseText.trim());
if (licenseKey) {
console.log(licenseKey.trim());
} else {
// what do we do here? base it on `license`?
}
Expand Down
1 change: 1 addition & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export type Manifest = {
flat?: boolean,
license?: string,
licenseText?: string,
noticeText?: string,

readme?: string,
readmeFilename?: string,
Expand Down
13 changes: 13 additions & 0 deletions src/util/normalize-manifest/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ export default (async function(
}
}

// get notice file
const noticeFile = files.find((filename): boolean => {
const lower = filename.toLowerCase();
return lower === 'notice' || lower.startsWith('notice.');
});
if (noticeFile) {
const noticeFilepath = path.join(moduleLoc, noticeFile);
const noticeFileStats = await fs.stat(noticeFilepath);
if (noticeFileStats.isFile()) {
info.noticeText = await fs.readFile(noticeFilepath);
}
}

for (const dependencyType of MANIFEST_FIELDS) {
const dependencyList = info[dependencyType];
if (dependencyList && typeof dependencyList === 'object') {
Expand Down

0 comments on commit 05b4e01

Please sign in to comment.