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.
|
2023-06-29 05:48:40 +00:00
|
|
|
function parse_accepted_toml(file: string): string[] {
|
2023-06-28 21:54:36 +00:00
|
|
|
const buffer = fs.readFileSync(file).toString()
|
2023-01-27 01:27:42 +00:00
|
|
|
|
2023-06-28 21:54:36 +00:00
|
|
|
const 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-29 05:48:40 +00:00
|
|
|
function check_licenses(themes: ThemeConfig[]) {
|
2023-06-07 15:10:16 +00:00
|
|
|
for (const theme of themes) {
|
2023-06-29 15:41:51 +00:00
|
|
|
if (!theme.license_file) {
|
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-29 05:48:40 +00:00
|
|
|
function generate_license_file(themes: ThemeConfig[]) {
|
|
|
|
check_licenses(themes)
|
2023-06-07 15:10:16 +00:00
|
|
|
for (const theme of themes) {
|
2023-06-29 15:41:51 +00:00
|
|
|
const license_text = fs.readFileSync(theme.license_file).toString()
|
2023-06-29 06:16:21 +00:00
|
|
|
write_license(theme.name, license_text, theme.license_url)
|
2023-02-25 16:46:33 +00:00
|
|
|
}
|
2023-01-27 01:27:42 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 05:48:40 +00:00
|
|
|
function write_license(
|
|
|
|
theme_name: string,
|
|
|
|
license_text: string,
|
|
|
|
license_url?: string
|
2023-05-30 16:12:31 +00:00
|
|
|
) {
|
2023-02-25 16:46:33 +00:00
|
|
|
process.stdout.write(
|
2023-06-29 05:48:40 +00:00
|
|
|
license_url
|
|
|
|
? `## [${theme_name}](${license_url})\n\n${license_text}\n********************************************************************************\n\n`
|
|
|
|
: `## ${theme_name}\n\n${license_text}\n********************************************************************************\n\n`
|
2023-02-25 16:46:33 +00:00
|
|
|
)
|
2023-01-27 01:27:42 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 05:48:40 +00:00
|
|
|
const accepted_licenses = parse_accepted_toml(ACCEPTED_LICENSES_FILE)
|
|
|
|
generate_license_file(themes)
|