2023-02-25 16:46:33 +00:00
|
|
|
import * as fs from "fs"
|
|
|
|
import toml from "toml"
|
2023-06-07 15:10:16 +00:00
|
|
|
import { themes } from "./themes"
|
|
|
|
import { ThemeConfig } from "./common"
|
2023-01-27 02:15:34 +00:00
|
|
|
|
2023-05-30 16:12:31 +00:00
|
|
|
const ACCEPTED_LICENSES_FILE = `${__dirname}/../../script/licenses/zed-licenses.toml`
|
2023-01-27 01:27:42 +00:00
|
|
|
|
|
|
|
// Use the cargo-about configuration file as the source of truth for supported licenses.
|
|
|
|
function parseAcceptedToml(file: string): string[] {
|
2023-02-25 16:46:33 +00:00
|
|
|
let buffer = fs.readFileSync(file).toString()
|
2023-01-27 01:27:42 +00:00
|
|
|
|
2023-02-25 16:46:33 +00:00
|
|
|
let obj = toml.parse(buffer)
|
2023-01-27 01:27:42 +00:00
|
|
|
|
2023-02-25 16:46:33 +00:00
|
|
|
if (!Array.isArray(obj.accepted)) {
|
|
|
|
throw Error("Accepted license source is malformed")
|
|
|
|
}
|
2023-01-27 01:27:42 +00:00
|
|
|
|
2023-02-25 16:46:33 +00:00
|
|
|
return obj.accepted
|
2023-01-27 01:27:42 +00:00
|
|
|
}
|
|
|
|
|
2023-06-07 15:10:16 +00:00
|
|
|
function checkLicenses(themes: ThemeConfig[]) {
|
|
|
|
for (const theme of themes) {
|
|
|
|
if (!theme.licenseFile) {
|
2023-06-07 16:40:49 +00:00
|
|
|
throw Error(`Theme ${theme.name} should have a LICENSE file`)
|
2023-02-25 16:46:33 +00:00
|
|
|
}
|
2023-01-27 01:27:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:10:16 +00:00
|
|
|
function generateLicenseFile(themes: ThemeConfig[]) {
|
|
|
|
checkLicenses(themes)
|
|
|
|
for (const theme of themes) {
|
|
|
|
const licenseText = fs.readFileSync(theme.licenseFile).toString()
|
2023-06-08 05:23:19 +00:00
|
|
|
writeLicense(theme.name, licenseText, theme.licenseUrl)
|
2023-02-25 16:46:33 +00:00
|
|
|
}
|
2023-01-27 01:27:42 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 16:12:31 +00:00
|
|
|
function writeLicense(
|
|
|
|
themeName: string,
|
2023-06-08 05:23:19 +00:00
|
|
|
licenseText: string,
|
|
|
|
licenseUrl?: string
|
2023-05-30 16:12:31 +00:00
|
|
|
) {
|
2023-02-25 16:46:33 +00:00
|
|
|
process.stdout.write(
|
2023-06-08 05:23:19 +00:00
|
|
|
licenseUrl
|
|
|
|
? `## [${themeName}](${licenseUrl})\n\n${licenseText}\n********************************************************************************\n\n`
|
|
|
|
: `## ${themeName}\n\n${licenseText}\n********************************************************************************\n\n`
|
2023-02-25 16:46:33 +00:00
|
|
|
)
|
2023-01-27 01:27:42 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 16:12:31 +00:00
|
|
|
const acceptedLicenses = parseAcceptedToml(ACCEPTED_LICENSES_FILE)
|
2023-06-07 15:10:16 +00:00
|
|
|
generateLicenseFile(themes)
|