Skip to content

Commit

Permalink
Go back to using declaration file. Fix indentation to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackTabsCode committed Nov 19, 2024
1 parent aad7e71 commit 09568e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/commands/sync/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::BTreeMap;
use std::path::Path;

pub struct GeneratorOptions {
pub output_name: String,
pub style: CodegenStyle,
pub strip_extension: bool,
}
Expand Down Expand Up @@ -35,9 +36,9 @@ impl Generator {
let data_value = self.build_data_value();
let mut output = String::new();

output.push_str("export = ");
output.push_str(&format!("declare const {}: ", self.options.output_name));
self.serialize_value_typescript(&data_value, &mut output, 0);
output.push(';');
output.push_str(";\nexport = assets;\n");

output
}
Expand Down Expand Up @@ -109,7 +110,7 @@ impl Generator {
DataValue::Node(map) => {
output.push_str("{\n");

let indent_str = " ".repeat(indent + 1);
let indent_str = "\t".repeat(indent + 1);

for (i, (key, val)) in map.iter().enumerate() {
output.push_str(&indent_str);
Expand All @@ -129,7 +130,7 @@ impl Generator {
output.push('\n');
}

output.push_str(&" ".repeat(indent));
output.push_str(&"\t".repeat(indent));
output.push('}');
}
}
Expand All @@ -144,7 +145,7 @@ impl Generator {
DataValue::Node(map) => {
output.push_str("{\n");

let indent_str = " ".repeat(indent + 1);
let indent_str = "\t".repeat(indent + 1);

for (i, (key, val)) in map.iter().enumerate() {
output.push_str(&indent_str);
Expand All @@ -165,7 +166,7 @@ impl Generator {
output.push('\n');
}

output.push_str(&" ".repeat(indent));
output.push_str(&"\t".repeat(indent));
output.push('}');
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub async fn sync(args: SyncArgs, existing_lockfile: LockFile) -> anyhow::Result
GeneratorOptions {
style: state.style,
strip_extension: state.strip_extension,
output_name: state.output_name.clone(),
},
);

Expand All @@ -204,7 +205,7 @@ pub async fn sync(args: SyncArgs, existing_lockfile: LockFile) -> anyhow::Result
.context("Failed to write output Luau file")?;

if state.typescript {
let ts_filename = format!("{}.ts", state.output_name);
let ts_filename = format!("{}.d.ts", state.output_name);
let ts_output = generator.generate_typescript();

write(Path::new(&state.write_dir).join(ts_filename), ts_output)
Expand Down

0 comments on commit 09568e5

Please sign in to comment.