diff --git a/tasks/lib/notice/base_notice.txt b/tasks/lib/notice/base_notice.txt index 19f505cdfe61bff..13cb1a0121529b9 100644 --- a/tasks/lib/notice/base_notice.txt +++ b/tasks/lib/notice/base_notice.txt @@ -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. ---- diff --git a/tasks/lib/notice/notice.js b/tasks/lib/notice/notice.js index 31047ec89d67136..f57129d6bbdcf5a 100644 --- a/tasks/lib/notice/notice.js +++ b/tasks/lib/notice/notice.js @@ -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'); @@ -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'); } diff --git a/tasks/lib/notice/package_notice.js b/tasks/lib/notice/package_notice.js new file mode 100644 index 000000000000000..3071da151819a37 --- /dev/null +++ b/tasks/lib/notice/package_notice.js @@ -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}`; +} diff --git a/tasks/lib/notice/packages_notice.js b/tasks/lib/notice/packages_notice.js deleted file mode 100644 index 47af7739cb61107..000000000000000 --- a/tasks/lib/notice/packages_notice.js +++ /dev/null @@ -1,28 +0,0 @@ -import { map as asyncMap } from 'bluebird'; - -import { getBundledNotices } from './bundled_notices'; - -const concatNotices = notices => ( - notices.map(notice => notice.text).join('\n') -); - -export async function generatePackagesNoticeText(packages) { - const noticeChunks = await asyncMap(packages, async 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}`; - }); - - return noticeChunks.join('\n---\n'); -}