feat: embed official starter template with token substitution

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-11 12:49:53 -05:00
1 parent 6ad481eb82
commit 456fa10664
7 files changed
+106

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
mod cli; mod cli;
mod runtime; mod runtime;
mod template;
use clap::Parser; use clap::Parser;
use cli::{Cli, Command}; use cli::{Cli, Command};
+49
View File
@@ -0,0 +1,49 @@
use include_dir::{include_dir, Dir};
use std::path::Path;
pub static STARTER: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/starter");
#[allow(dead_code)]
pub fn write_starter(dest: &Path, project_name: &str) -> std::io::Result<()> {
write_dir(&STARTER, dest, project_name)
}
fn write_dir(dir: &Dir, dest: &Path, name: &str) -> std::io::Result<()> {
for entry in dir.entries() {
match entry {
include_dir::DirEntry::Dir(d) => {
let sub = dest.join(d.path().file_name().unwrap());
std::fs::create_dir_all(&sub)?;
write_dir(d, &sub, name)?;
}
include_dir::DirEntry::File(f) => {
let out = dest.join(f.path().file_name().unwrap());
if let Some(parent) = out.parent() {
std::fs::create_dir_all(parent)?;
}
let contents = std::str::from_utf8(f.contents())
.map(|s| s.replace("{{project_name}}", name).into_bytes())
.unwrap_or_else(|_| f.contents().to_vec());
std::fs::write(out, contents)?;
}
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
#[test]
fn writes_starter_and_substitutes_name() {
let d = tempdir().unwrap();
write_starter(d.path(), "my-api").unwrap();
let html = std::fs::read_to_string(d.path().join("public/index.html")).unwrap();
assert!(html.contains("<title>my-api</title>"));
assert!(!html.contains("{{project_name}}"));
assert!(d.path().join("src/controllers/home.controller.ts").exists());
assert!(d.path().join("matcha.toml").exists());
}
}
+1
View File
@@ -0,0 +1 @@
{ "tasks": { "dev": "deno run --watch --allow-net --allow-read src/main.ts" } }
+1
View File
@@ -0,0 +1 @@
runtime = "deno"
+23
View File
@@ -0,0 +1,23 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{{project_name}}</title>
<style>
body { font-family: system-ui; display: grid; place-items: center;
min-height: 100vh; margin: 0; background: #0f1f13; color: #d7f5df; }
.logo { font-size: 4rem; }
.zen { margin-top: 1rem; opacity: .85; font-style: italic; }
</style>
</head>
<body>
<div>
<div class="logo">🍵 green-tea</div>
<div class="zen" id="zen">connecting…</div>
</div>
<script>
const es = new EventSource('/zen');
es.onmessage = (e) => { document.getElementById('zen').textContent = JSON.parse(e.data).zen; };
</script>
</body>
</html>
+5
View File
@@ -0,0 +1,5 @@
import { Module } from '@green-tea/core';
import { HomeController } from './controllers/home.controller';
@Module({ controllers: [HomeController] })
export class AppModule {}
@@ -0,0 +1,26 @@
import { Route, Get, Html, Sse } from '@green-tea/core';
const ZEN = [
'Simplicity is the ultimate sophistication.',
'The obstacle is the path.',
'When you let go, you have two hands to work.',
'Make it work, make it right, make it fast.',
'Less, but better.',
];
@Route('/')
export class HomeController {
@Get('/')
@Html('public/index.html')
home() {}
@Sse('/zen')
zen() {
return (async function* () {
for (let i = 0; ; i++) {
yield { zen: ZEN[i % ZEN.length] };
await new Promise((r) => setTimeout(r, 30_000));
}
})();
}
}