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 toml from "toml"
import { schemeMeta } from "./colorSchemes"
import { MetaAndLicense } from "./themes/common/colorScheme"
import { themes } from "./themes"
import { ThemeConfig } from "./common"
const ACCEPTED_LICENSES_FILE = `${__dirname}/../../script/licenses/zed-licenses.toml`
@ -18,37 +18,31 @@ function parseAcceptedToml(file: string): string[] {
return obj.accepted
}
function checkLicenses(
schemeMetaWithLicense: MetaAndLicense[],
licenses: string[]
) {
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 checkLicenses(themes: ThemeConfig[]) {
for (const theme of themes) {
if (!theme.licenseFile) {
throw Error(`Theme ${theme.name} should have a LICENSE files`)
}
}
}
function generateLicenseFile(schemeMetaWithLicense: MetaAndLicense[]) {
for (const { meta, licenseFile } of schemeMetaWithLicense) {
const licenseText = fs.readFileSync(licenseFile).toString()
writeLicense(meta.name, meta.url, licenseText)
function generateLicenseFile(themes: ThemeConfig[]) {
checkLicenses(themes)
for (const theme of themes) {
const licenseText = fs.readFileSync(theme.licenseFile).toString()
writeLicense(theme.name, theme.licenseUrl, licenseText)
}
}
function writeLicense(
themeName: string,
themeUrl: string,
licenseUrl: string,
licenseText: String
) {
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)
checkLicenses(schemeMeta, acceptedLicenses)
generateLicenseFile(schemeMeta)
generateLicenseFile(themes)