From c127a179107d49ca7cc72d446ccf901854bb6d39 Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Thu, 25 Apr 2024 17:36:45 -0500 Subject: [PATCH] Add the `StyleType` enum --- README.md | 4 ++-- src/config.rs | 9 ++++++++- src/main.rs | 12 ++---------- src/state.rs | 8 ++++---- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 550d403..1b578d3 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ id = 583095803 - Generate a Typescript definition file. - `luau`: boolean (optional) - Use the `luau` file extension. -- `tarmac`: boolean (optional) - - Use tarmac-styled code generation. +- `style`: string (optional) + - The code-generation style to use. Defaults to `flat`. - `output_name`: string (optional) - The name for the generated files. Defaults to `assets`. - `existing`: map (optional) diff --git a/src/config.rs b/src/config.rs index d6edb2b..e8d8abd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,13 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; +#[derive(Debug, Deserialize, Serialize, PartialEq)] +#[serde(rename_all = "snake_case")] +pub enum StyleType { + Flat, + Nested, +} + #[derive(Debug, Deserialize, Serialize, PartialEq)] #[serde(rename_all = "snake_case")] pub enum CreatorType { @@ -29,7 +36,7 @@ pub struct Config { pub output_name: Option, pub typescript: Option, pub luau: Option, - pub tarmac: Option, + pub style: Option, pub existing: Option>, } diff --git a/src/main.rs b/src/main.rs index 0134f9f..b465775 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,11 +180,7 @@ async fn main() -> anyhow::Result<()> { })); let lua_filename = format!("{}.{}", state.output_name, state.lua_extension); - let lua_output = if state.tarmac { - tarmac::generate_lua - } else { - generate_lua - }(&state.new_lockfile, asset_dir_str); + let lua_output = generate_lua(&state.new_lockfile, asset_dir_str); write(Path::new(&state.write_dir).join(lua_filename), lua_output?) .await @@ -192,11 +188,7 @@ async fn main() -> anyhow::Result<()> { if state.typescript { let ts_filename = format!("{}.d.ts", state.output_name); - let ts_output = if state.tarmac { - tarmac::generate_ts - } else { - generate_ts - }( + let ts_output = generate_ts( &state.new_lockfile, asset_dir_str, state.output_name.as_str(), diff --git a/src/state.rs b/src/state.rs index 274d436..8ec97e0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,6 +1,6 @@ use crate::{ args::Args, - config::{Config, CreatorType, ExistingAsset}, + config::{Config, CreatorType, ExistingAsset, StyleType}, LockFile, }; use anyhow::Context; @@ -35,7 +35,7 @@ pub struct State { pub output_name: String, pub lua_extension: String, - pub tarmac: bool, + pub style: StyleType, pub font_db: Database, @@ -74,7 +74,7 @@ impl State { .to_string(); let typescript = config.typescript.unwrap_or(false); - let tarmac = config.tarmac.unwrap_or(false); + let style = config.style.unwrap_or(StyleType::Flat); let lua_extension = String::from(if config.luau.unwrap_or(false) { "luau" @@ -104,7 +104,7 @@ impl State { typescript, output_name, lua_extension, - tarmac, + style, font_db, existing_lockfile, new_lockfile,