Skip to content

Commit

Permalink
[tasks/lib/notice] join all notices with the same separator
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed May 23, 2017
1 parent e5a4839 commit 60bf904
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
1 change: 0 additions & 1 deletion tasks/lib/notice/base_notice.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ THE SOFTWARE.
---
This product bundles geohash.js which is available under a
"MIT" license. For details, see src/ui/public/utils/decode_geo_hash.js.
---
13 changes: 9 additions & 4 deletions tasks/lib/notice/notice.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path';
import { readFileSync } from 'fs';

import { generatePackagesNoticeText } from './packages_notice';
import { generatePackageNoticeText } from './package_notice';
import { generateNodeNoticeText } from './node_notice';

const BASE_NOTICE = resolve(__dirname, './base_notice.txt');
Expand All @@ -20,9 +20,14 @@ const BASE_NOTICE = resolve(__dirname, './base_notice.txt');
*/
export async function generateNoticeText(options = {}) {
const { packages, nodeDir } = options;

const packageNotices = await Promise.all(
packages.map(generatePackageNoticeText)
);

return [
readFileSync(BASE_NOTICE, 'utf8'),
await generatePackagesNoticeText(packages),
generateNodeNoticeText(nodeDir)
].join('');
...packageNotices,
generateNodeNoticeText(nodeDir),
].join('\n---\n');
}
22 changes: 22 additions & 0 deletions tasks/lib/notice/package_notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getBundledNotices } from './bundled_notices';

const concatNotices = notices => (
notices.map(notice => notice.text).join('\n')
);

export async function generatePackageNoticeText(pkg) {
const bundledNotices = concatNotices(await getBundledNotices(pkg.directory));

const intro = `This product bundles ${pkg.name}@${pkg.version}`;
const license = ` which is available under ${
pkg.licenses.length > 1
? `the\n"${pkg.licenses.join('", ')} licenses.`
: `a\n"${pkg.licenses[0]}" license.`
}`;

const moreInfo = bundledNotices
? `\n${bundledNotices}\n`
: ` For details, see ${pkg.relative}/.`;

return `${intro}${license}${moreInfo}`;
}
28 changes: 0 additions & 28 deletions tasks/lib/notice/packages_notice.js

This file was deleted.

0 comments on commit 60bf904

Please sign in to comment.