From 6aa93800ebbee5e8b30752f97449cd867893085f Mon Sep 17 00:00:00 2001 From: Darwin Boersma Date: Sat, 7 Dec 2024 15:13:34 -0700 Subject: [PATCH] Implement 'add' functionality for template Signed-off-by: Darwin Boersma --- templates/leptos-ssr/content/spin.toml | 8 ++++---- .../metadata/snippets/component.txt | 20 +++++++++++++++++++ .../leptos-ssr/metadata/spin-template.toml | 7 ++++++- 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 templates/leptos-ssr/metadata/snippets/component.txt diff --git a/templates/leptos-ssr/content/spin.toml b/templates/leptos-ssr/content/spin.toml index c9beaa2..84d483a 100644 --- a/templates/leptos-ssr/content/spin.toml +++ b/templates/leptos-ssr/content/spin.toml @@ -7,7 +7,7 @@ authors = ["{{authors}}"] description = "{{project-description}}" [[trigger.http]] -route = "/..." +route = "{{http-path}}..." component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] @@ -19,9 +19,9 @@ command = "cargo leptos build --release && LEPTOS_OUTPUT_NAME={{project-name | s watch = ["src/**/*.rs", "Cargo.toml"] [[trigger.http]] -route = "/pkg/..." -component = "pkg" +route = "{{http-path}}pkg/..." +component = "{{project-name | kebab_case}}-pkg" -[component.pkg] +[component.{{project-name | kebab_case}}-pkg] source = { url = "https://github.com/fermyon/spin-fileserver/releases/download/v0.1.0/spin_static_fs.wasm", digest = "sha256:96c76d9af86420b39eb6cd7be5550e3cb5d4cc4de572ce0fd1f6a29471536cb4" } files = [{ source = "target/site/pkg", destination = "/" }] diff --git a/templates/leptos-ssr/metadata/snippets/component.txt b/templates/leptos-ssr/metadata/snippets/component.txt new file mode 100644 index 0000000..d133d99 --- /dev/null +++ b/templates/leptos-ssr/metadata/snippets/component.txt @@ -0,0 +1,20 @@ +[[trigger.http]] +route = "{{http-path}}..." +component = "{{project-name | kebab_case}}" + +[component.{{project-name | kebab_case}}] +source = "{{output-path}}/target/wasm32-wasip1/release/{{project-name | snake_case}}.wasm" +allowed_outbound_hosts = [] +key_value_stores = ["default"] +[component.{{project-name | kebab_case}}.build] +command = "cargo leptos build --release && LEPTOS_OUTPUT_NAME={{project-name | snake_case}} cargo build --lib --target wasm32-wasip1 --release --no-default-features --features ssr" +workdir = "{{output-path}}" +watch = ["src/**/*.rs", "Cargo.toml"] + +[[trigger.http]] +route = "{{http-path}}pkg/..." +component = "{{project-name | kebab_case}}-pkg" + +[component.{{project-name | kebab_case}}-pkg] +source = { url = "https://github.com/fermyon/spin-fileserver/releases/download/v0.1.0/spin_static_fs.wasm", digest = "sha256:96c76d9af86420b39eb6cd7be5550e3cb5d4cc4de572ce0fd1f6a29471536cb4" } +files = [{ source = "{{output-path}}/target/site/pkg", destination = "/" }] diff --git a/templates/leptos-ssr/metadata/spin-template.toml b/templates/leptos-ssr/metadata/spin-template.toml index 811ad51..2ed4bf3 100644 --- a/templates/leptos-ssr/metadata/spin-template.toml +++ b/templates/leptos-ssr/metadata/spin-template.toml @@ -5,4 +5,9 @@ tags = ["http", "rust", "leptos"] [parameters] project-description = { type = "string", prompt = "Description", default = "" } -http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" } \ No newline at end of file +http-path = { type = "string", prompt = "HTTP path", default = "/", pattern = "^/\\S*$" } + +[add_component] +skip_files = ["spin.toml"] +[add_component.snippets] +component = "component.txt" \ No newline at end of file