Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.task/
/test_app/target/
.zig-cache/
/assets/target/
26 changes: 26 additions & 0 deletions assets/main.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
///|
using @firefly {type Point, type Size, type Style}

///|
fn main {

}

///|
pub fn boot() -> Unit {
// ...
}

///|
pub fn update() -> Unit {
// ...
}

///|
pub fn render() -> Unit {
@firefly.draw_rect(
Point::new(10, 10),
Size::new(40, 15),
Style::new_solid(LightGray),
)
}
4 changes: 4 additions & 0 deletions assets/moon.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "app",
"preferred-target": "wasm"
}
9 changes: 9 additions & 0 deletions assets/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"is-main": true,
"import": ["applejag/firefly"],
"link": {
"wasm": {
"exports": ["boot", "update", "render"]
}
}
}
14 changes: 13 additions & 1 deletion src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn cmd_new(args: &NewArgs) -> Result<()> {
Lang::C => new_c(&args.name).context("new C project")?,
Lang::Cpp => new_cpp(&args.name).context("new C++ project")?,
Lang::Python => bail!("Python is not supported yet"),
Lang::Moon => bail!("Moon starter project is not supported yet"),
Lang::Moon => new_moon(&args.name).context("new Moon project")?,
}
write_config(&args.name)?;
init_git(&args.name)?;
Expand Down Expand Up @@ -77,6 +77,7 @@ fn parse_lang(lang: &str) -> Result<Lang> {
"ts" | "typescript" | "js" | "javascript" => Lang::TS,
"cpp" | "c++" => Lang::Cpp,
"python" | "py" => Lang::Python,
"moon" | "moonbit" => Lang::Moon,
_ => bail!("unsupported language: {lang}"),
};
Ok(result)
Expand Down Expand Up @@ -145,6 +146,17 @@ fn new_c_or_cpp(name: &str, main: &str) -> Result<()> {
Ok(())
}

fn new_moon(name: &str) -> Result<()> {
check_installed("Moon", "moon", "version")?;
let mut c = Commander::default();
c.cd(name)?;
c.copy_asset(&["main.mbt"], "main.mbt")?;
c.copy_asset(&["moon.mod.json"], "moon.mod.json")?;
c.copy_asset(&["moon.pkg.json"], "moon.pkg.json")?;
c.run(&["moon", "add", "applejag/firefly"])?;
Ok(())
}

#[derive(Default)]
struct Commander<'a> {
root: Option<&'a Path>,
Expand Down