Decouple theme license generation from TypeScript theme definitions (#3917)
This PR decouples the generation of licenses for the themes we ship from the TypeScript theme definitions. For now, we are embedding the license information for the themes in the `theme_importer`, and emit a combined `LICENSES` file in the `theme` crate whenever we import themes. This is also where we check that each theme has a valid license. We then use this `LICENSES` file when building up the global license file for Zed. This decoupling is one step towards us being able to delete the old Zed1 styles. Release Notes: - N/A
This commit is contained in:
parent
254a52d0a1
commit
c7c874a371
12 changed files with 10815 additions and 8565 deletions
|
@ -11,6 +11,7 @@ clap = { version = "4.4", features = ["derive"] }
|
|||
convert_case = "0.6.0"
|
||||
gpui = { path = "../gpui" }
|
||||
indexmap = { version = "1.6.2", features = ["serde"] }
|
||||
indoc.workspace = true
|
||||
json_comments = "0.2.2"
|
||||
log.workspace = true
|
||||
palette = { version = "0.7.3", default-features = false, features = ["std"] }
|
||||
|
|
|
@ -18,6 +18,7 @@ use clap::Parser;
|
|||
use convert_case::{Case, Casing};
|
||||
use gpui::serde_json;
|
||||
use indexmap::IndexMap;
|
||||
use indoc::formatdoc;
|
||||
use json_comments::StripComments;
|
||||
use log::LevelFilter;
|
||||
use serde::Deserialize;
|
||||
|
@ -28,7 +29,7 @@ use crate::theme_printer::UserThemeFamilyPrinter;
|
|||
use crate::vscode::VsCodeTheme;
|
||||
use crate::vscode::VsCodeThemeConverter;
|
||||
use crate::zed1::theme::Theme as Zed1Theme;
|
||||
use crate::zed1::Zed1ThemeConverter;
|
||||
use crate::zed1::{zed1_theme_licenses, Zed1ThemeConverter};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct FamilyMetadata {
|
||||
|
@ -200,7 +201,13 @@ fn main() -> Result<()> {
|
|||
"Summercamp",
|
||||
];
|
||||
|
||||
let mut zed1_themes_by_family: HashMap<String, Vec<UserTheme>> = HashMap::from_iter(
|
||||
let zed1_licenses_by_theme: HashMap<String, zed1::Zed1ThemeLicense> = HashMap::from_iter(
|
||||
zed1_theme_licenses()
|
||||
.into_iter()
|
||||
.map(|theme_license| (theme_license.theme.clone(), theme_license)),
|
||||
);
|
||||
|
||||
let mut zed1_themes_by_family: IndexMap<String, Vec<UserTheme>> = IndexMap::from_iter(
|
||||
zed1_theme_familes
|
||||
.into_iter()
|
||||
.map(|family| (family.to_string(), Vec::new())),
|
||||
|
@ -254,13 +261,44 @@ fn main() -> Result<()> {
|
|||
themes_for_family.push(theme);
|
||||
}
|
||||
|
||||
zed1_themes_by_family.sort_keys();
|
||||
|
||||
let mut licenses = Vec::new();
|
||||
|
||||
for (family, themes) in zed1_themes_by_family {
|
||||
let theme_family = UserThemeFamily {
|
||||
let mut theme_family = UserThemeFamily {
|
||||
name: family,
|
||||
author: "Zed Industries".to_string(),
|
||||
themes,
|
||||
};
|
||||
|
||||
theme_family
|
||||
.themes
|
||||
.sort_unstable_by_key(|theme| theme.name.clone());
|
||||
|
||||
for theme in &theme_family.themes {
|
||||
let license = zed1_licenses_by_theme
|
||||
.get(&theme.name)
|
||||
.ok_or_else(|| anyhow!("missing license for theme: '{}'", theme.name))?;
|
||||
|
||||
let license_header = match license.license_url.as_ref() {
|
||||
Some(license_url) => {
|
||||
format!("[{theme_name}]({license_url})", theme_name = theme.name)
|
||||
}
|
||||
None => theme.name.clone(),
|
||||
};
|
||||
|
||||
licenses.push(formatdoc!(
|
||||
"
|
||||
## {license_header}
|
||||
|
||||
{license_text}
|
||||
********************************************************************************
|
||||
",
|
||||
license_text = license.license_text
|
||||
));
|
||||
}
|
||||
|
||||
theme_families.push(theme_family);
|
||||
}
|
||||
|
||||
|
@ -357,6 +395,12 @@ fn main() -> Result<()> {
|
|||
|
||||
mod_rs_file.write_all(mod_rs_contents.as_bytes())?;
|
||||
|
||||
log::info!("Writing LICENSES file...");
|
||||
|
||||
let mut licenses_file = File::create(themes_output_path.join(format!("LICENSES")))?;
|
||||
|
||||
licenses_file.write_all(licenses.join("\n").as_bytes())?;
|
||||
|
||||
log::info!("Formatting themes...");
|
||||
|
||||
let format_result = format_themes_crate()
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
mod converter;
|
||||
mod licenses;
|
||||
pub mod theme;
|
||||
|
||||
pub use converter::*;
|
||||
pub use licenses::*;
|
||||
|
|
1192
crates/theme_importer/src/zed1/licenses.rs
Normal file
1192
crates/theme_importer/src/zed1/licenses.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue