Tidy up xtask
This commit is contained in:
parent
d194edc49f
commit
d3a333b873
4 changed files with 64 additions and 7 deletions
|
@ -6,7 +6,8 @@ publish = false
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = "4.0"
|
||||
anyhow = "1.0"
|
||||
clap = {version = "4.0", features = ["derive"]}
|
||||
theme = {path = "../theme"}
|
||||
serde_json.workspace = true
|
||||
schemars.workspace = true
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
use std::path::PathBuf;
|
||||
/// Common utilities for Zed developers.
|
||||
// For more information, see [matklad's repository README](https://github.com/matklad/cargo-xtask/)
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
#[command(propagate_version = true)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Commands,
|
||||
}
|
||||
|
||||
/// Command to run.
|
||||
#[derive(Subcommand)]
|
||||
pub enum Commands {
|
||||
/// Builds theme types for interop with Typescript.
|
||||
BuildThemeTypes {
|
||||
#[clap(short, long, default_value = "schemas")]
|
||||
out_dir: PathBuf,
|
||||
#[clap(short, long, default_value = "theme.json")]
|
||||
file_name: PathBuf,
|
||||
},
|
||||
}
|
|
@ -1,11 +1,29 @@
|
|||
mod cli;
|
||||
|
||||
use schemars::schema_for;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use schemars::schema_for;
|
||||
use theme::Theme;
|
||||
fn main() {
|
||||
|
||||
fn build_themes(mut out_dir: PathBuf, file_name: PathBuf) -> Result<()> {
|
||||
let theme = schema_for!(Theme);
|
||||
let output = serde_json::to_string_pretty(&theme).unwrap();
|
||||
std::fs::create_dir("schemas").ok();
|
||||
std::fs::write("schemas/theme.json", output).ok();
|
||||
let output = serde_json::to_string_pretty(&theme)?;
|
||||
|
||||
std::fs::create_dir(&out_dir)?;
|
||||
|
||||
let mut file_path = out_dir;
|
||||
out_dir.push(file_name);
|
||||
|
||||
std::fs::write(file_path, output)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = cli::Cli::parse();
|
||||
match args.command {
|
||||
cli::Commands::BuildThemeTypes { out_dir, file_name } => build_themes(out_dir, file_name),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue