feat: use theme index to build licenses

This commit is contained in:
Sergey Onufrienko 2023-06-07 16:10:16 +01:00
parent 0ad76ac92c
commit 4c405e65a3
No known key found for this signature in database
GPG key ID: 3299873ECFD30CA3

View file

@ -1,7 +1,7 @@
import * as fs from "fs" import * as fs from "fs"
import toml from "toml" import toml from "toml"
import { schemeMeta } from "./colorSchemes" import { themes } from "./themes"
import { MetaAndLicense } from "./themes/common/colorScheme" import { ThemeConfig } from "./common"
const ACCEPTED_LICENSES_FILE = `${__dirname}/../../script/licenses/zed-licenses.toml` const ACCEPTED_LICENSES_FILE = `${__dirname}/../../script/licenses/zed-licenses.toml`
@ -18,37 +18,31 @@ function parseAcceptedToml(file: string): string[] {
return obj.accepted return obj.accepted
} }
function checkLicenses( function checkLicenses(themes: ThemeConfig[]) {
schemeMetaWithLicense: MetaAndLicense[], for (const theme of themes) {
licenses: string[] if (!theme.licenseFile) {
) { throw Error(`Theme ${theme.name} should have a LICENSE files`)
for (const { meta } of schemeMetaWithLicense) {
// FIXME: Add support for conjuctions and conditions
if (licenses.indexOf(meta.license.SPDX) < 0) {
throw Error(
`License for theme ${meta.name} (${meta.license.SPDX}) is not supported`
)
} }
} }
} }
function generateLicenseFile(schemeMetaWithLicense: MetaAndLicense[]) { function generateLicenseFile(themes: ThemeConfig[]) {
for (const { meta, licenseFile } of schemeMetaWithLicense) { checkLicenses(themes)
const licenseText = fs.readFileSync(licenseFile).toString() for (const theme of themes) {
writeLicense(meta.name, meta.url, licenseText) const licenseText = fs.readFileSync(theme.licenseFile).toString()
writeLicense(theme.name, theme.licenseUrl, licenseText)
} }
} }
function writeLicense( function writeLicense(
themeName: string, themeName: string,
themeUrl: string, licenseUrl: string,
licenseText: String licenseText: String
) { ) {
process.stdout.write( process.stdout.write(
`## [${themeName}](${themeUrl})\n\n${licenseText}\n********************************************************************************\n\n` `## [${themeName}](${licenseUrl})\n\n${licenseText}\n********************************************************************************\n\n`
) )
} }
const acceptedLicenses = parseAcceptedToml(ACCEPTED_LICENSES_FILE) const acceptedLicenses = parseAcceptedToml(ACCEPTED_LICENSES_FILE)
checkLicenses(schemeMeta, acceptedLicenses) generateLicenseFile(themes)
generateLicenseFile(schemeMeta)