Skip to content

Commit

Permalink
Add the StyleType enum
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Apr 25, 2024
1 parent 749f97a commit c127a17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ExistingAsset> (optional)
Expand Down
9 changes: 8 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -29,7 +36,7 @@ pub struct Config {
pub output_name: Option<String>,
pub typescript: Option<bool>,
pub luau: Option<bool>,
pub tarmac: Option<bool>,
pub style: Option<StyleType>,

pub existing: Option<HashMap<String, ExistingAsset>>,
}
12 changes: 2 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,15 @@ 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
.context("Failed to write output Lua file")?;

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(),
Expand Down
8 changes: 4 additions & 4 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
args::Args,
config::{Config, CreatorType, ExistingAsset},
config::{Config, CreatorType, ExistingAsset, StyleType},
LockFile,
};
use anyhow::Context;
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -104,7 +104,7 @@ impl State {
typescript,
output_name,
lua_extension,
tarmac,
style,
font_db,
existing_lockfile,
new_lockfile,
Expand Down

0 comments on commit c127a17

Please sign in to comment.