Skip to content

Commit

Permalink
Auto-generate NTP backgrounds LICENSE file (fixes #7460)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarier committed Feb 12, 2020
1 parent 12e2855 commit 5f450bc
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion lib/licensing.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,67 @@ const listSubComponents = (baseDir) => {
return subComponents
}

const listNtpBackgrounds = (metadataFile) => {
const metadata = fs.readFileSync(metadataFile).toString()
let images = []
// Hack to import this TypeScript file in Node:
eval(metadata.replace('export const images: NewTab.Image[]', 'images'))
return images
}

const generateNtpBackgroundsLicense = (preamble, components) => {
let componentNotices = ''

for (let component of components) {
if (componentNotices.length != 0) {
componentNotices += '\n'
}

const fileName = component['source']
if (!fileName) {
console.error('Missing source for background image ' + component['name'])
process.exit(1)
}
const authorName = component['author']
if (!authorName) {
console.error('Missing author for background image ' + component['name'])
process.exit(1)
}
const authorLink = component['link']
if (!authorLink) {
console.error('Missing link for background image ' + component['name'])
process.exit(1)
}
const originalUrl = component['originalUrl']
if (!originalUrl) {
console.error('Missing originalUrl for background image ' + component['name'])
process.exit(1)
}
const license = component['license']
if (!license) {
console.error('Missing license for background image ' + component['name'])
process.exit(1)
}
if ((license != 'used with permission') &&
(license.substr(0, 8) != 'https://') && (license.substr(0, 7) != 'http://')) {
console.error('Invalid license for background image ' + component['name'] + '. It needs to be a URL or the string "used with permission".')
process.exit(1)
}

componentNotices += 'File: ' + fileName + '\n' +
'Author: ' + authorName + ' (' + authorLink + ')\n' +
'URL: ' + originalUrl + '\n' +
'License: ' + license + '\n'
}

return preamble + '\n\n' + componentNotices
}

const licensing = {
updateLicenses: () => {
console.log('regenerating LICENSE files...')
const braveComponentsThirdPartyDir = path.join(config.projects['brave-core'].dir, 'components', 'third_party')
const braveComponentsDir = path.join(config.projects['brave-core'].dir, 'components')
const braveComponentsThirdPartyDir = path.join(braveComponentsDir, 'third_party')

// Brave Ad Block component
const braveAdBlockDir = path.join(braveComponentsThirdPartyDir, 'adblock')
Expand All @@ -154,6 +211,13 @@ const licensing = {
let localDataLicense = generateExternalComponentLicenseFile(localDataPreamble, localDataComponents)
fs.writeFileSync(path.join(braveComponentsThirdPartyDir, 'local_data', 'LICENSE'), localDataLicense)
console.log(' - ' + localDataComponents.length + ' sub-components added in local_data/LICENSE')

const braveNtpDataDir = path.join(braveComponentsDir, 'brave_new_tab_ui', 'data')
let ntpBackgroundsPreamble = 'These licenses do not apply to any of the code shipped with the Brave Browser and instead apply to background images used on the new tab page. The Brave Browser and such data files are separate and independent works.'
const ntpBackgrounds = listNtpBackgrounds(path.join(braveNtpDataDir, 'backgrounds.ts'))
let ntpBackgroundsLicense = generateNtpBackgroundsLicense(ntpBackgroundsPreamble, ntpBackgrounds)
fs.writeFileSync(path.join(braveNtpDataDir, 'LICENSE'), ntpBackgroundsLicense)
console.log(' - ' + ntpBackgrounds.length + ' sub-components added in brave_new_tab_ui/data/LICENSE')
}
}

Expand Down

0 comments on commit 5f450bc

Please sign in to comment.