Skip to content

Commit 6f715e1

Browse files
committed
gnd: Fix mapping file path and kebab-case conversion in scaffold
- Add ./src/ prefix to mapping file path in generated manifest (I7) The manifest referenced ./simple-contract.ts but the file was created at ./src/simple-contract.ts - Replace buggy custom to_kebab_case with Inflector (A3) Custom implementation incorrectly converted ERC20 -> e-r-c20 Inflector correctly produces erc20 (keeps acronyms together)
1 parent 3fff250 commit 6f715e1

2 files changed

Lines changed: 9 additions & 16 deletions

File tree

gnd/src/scaffold/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::ScaffoldOptions;
66
pub fn generate_manifest(options: &ScaffoldOptions) -> String {
77
let contract_name = &options.contract_name;
88
let network = &options.network;
9-
let mapping_file = format!("./{}.ts", super::to_kebab_case(contract_name));
9+
let mapping_file = format!("./src/{}.ts", super::to_kebab_case(contract_name));
1010
let abi_file = format!("./abis/{}.json", contract_name);
1111

1212
let mut source = format!(

gnd/src/scaffold/mod.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::path::Path;
1616
use std::process::{Command, Stdio};
1717

1818
use anyhow::{anyhow, Context, Result};
19+
use inflector::Inflector;
1920
use serde_json::Value as JsonValue;
2021

2122
use crate::formatter::format_typescript;
@@ -230,19 +231,9 @@ generated/
230231
}
231232

232233
/// Convert a string to kebab-case.
233-
fn to_kebab_case(s: &str) -> String {
234-
let mut result = String::new();
235-
for (i, c) in s.chars().enumerate() {
236-
if c.is_uppercase() {
237-
if i > 0 {
238-
result.push('-');
239-
}
240-
result.push(c.to_lowercase().next().unwrap_or(c));
241-
} else {
242-
result.push(c);
243-
}
244-
}
245-
result
234+
/// Uses Inflector which correctly handles acronyms (ERC20 → erc20, not e-r-c20).
235+
pub(crate) fn to_kebab_case(s: &str) -> String {
236+
s.to_kebab_case()
246237
}
247238

248239
#[cfg(test)]
@@ -251,10 +242,12 @@ mod tests {
251242

252243
#[test]
253244
fn test_to_kebab_case() {
245+
// Inflector correctly handles acronyms - consecutive uppercase letters stay together
254246
assert_eq!(to_kebab_case("MyContract"), "my-contract");
255-
assert_eq!(to_kebab_case("ERC20"), "e-r-c20");
247+
assert_eq!(to_kebab_case("ERC20"), "erc20");
256248
assert_eq!(to_kebab_case("contract"), "contract");
257-
assert_eq!(to_kebab_case("ABCToken"), "a-b-c-token");
249+
assert_eq!(to_kebab_case("ABCToken"), "abc-token");
250+
assert_eq!(to_kebab_case("ERC20Token"), "erc20-token");
258251
}
259252

260253
#[test]

0 commit comments

Comments
 (0)