diff --git a/loco-new/base_template/.github/workflows/ci.yaml.t b/loco-new/base_template/.github/workflows/ci.yaml.t index cd2cd9fe3..ec3b568f3 100644 --- a/loco-new/base_template/.github/workflows/ci.yaml.t +++ b/loco-new/base_template/.github/workflows/ci.yaml.t @@ -90,8 +90,8 @@ jobs: with: toolchain: ${% raw %}{{ env.RUST_TOOLCHAIN }}{% endraw %} - {%- if settings.asset %} - {%- if settings.asset.kind == "client" %} + {%- if settings.rendering_method %} + {%- if settings.rendering_method.kind == "client" %} - name: Setup node uses: actions/setup-node@v4 with: diff --git a/loco-new/base_template/Cargo.toml.t b/loco-new/base_template/Cargo.toml.t index 4c1044c9a..c872da29b 100644 --- a/loco-new/base_template/Cargo.toml.t +++ b/loco-new/base_template/Cargo.toml.t @@ -47,12 +47,14 @@ uuid = { version = "1.6.0", features = ["v4"] } include_dir = { version = "0.7" } {%- endif %} -{%- if settings.asset %} +{%- if settings.rendering_method.kind %} +{%- if settings.rendering_method.kind == "server" %} # view engine i18n fluent-templates = { version = "0.8.0", features = ["tera"] } unic-langid = { version = "0.9.4" } # /view engine {%- endif %} +{%- endif %} [[bin]] name = "{{settings.module_name}}-cli" diff --git a/loco-new/base_template/config/development.yaml.t b/loco-new/base_template/config/development.yaml.t index fbd215dea..31324c2fc 100644 --- a/loco-new/base_template/config/development.yaml.t +++ b/loco-new/base_template/config/development.yaml.t @@ -24,8 +24,8 @@ server: host: http://localhost # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block middlewares: - {%- if settings.asset %} - {%- if settings.asset.kind == "server" %} + {%- if settings.rendering_method %} + {%- if settings.rendering_method.kind == "server" %} static: enable: true must_exist: true @@ -34,7 +34,7 @@ server: uri: "/static" path: "assets/static" fallback: "assets/static/404.html" - {%- elif settings.asset.kind == "client" %} + {%- elif settings.rendering_method.kind == "client" %} fallback: enable: false static: diff --git a/loco-new/base_template/config/test.yaml.t b/loco-new/base_template/config/test.yaml.t index f9cbb7a9d..4cded5c8a 100644 --- a/loco-new/base_template/config/test.yaml.t +++ b/loco-new/base_template/config/test.yaml.t @@ -22,8 +22,8 @@ server: host: http://localhost # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block middlewares: - {%- if settings.asset %} - {%- if settings.asset.kind == "server" %} + {%- if settings.rendering_method %} + {%- if settings.rendering_method.kind == "server" %} static: enable: true must_exist: true @@ -32,7 +32,7 @@ server: uri: "/static" path: "assets/static" fallback: "assets/static/404.html" - {%- elif settings.asset.kind == "client" %} + {%- elif settings.rendering_method.kind == "client" %} fallback: enable: false static: diff --git a/loco-new/setup.rhai b/loco-new/setup.rhai index 7622b222d..e5831ad51 100644 --- a/loco-new/setup.rhai +++ b/loco-new/setup.rhai @@ -84,7 +84,7 @@ if db { // ===================== // Initializers Support // ===================== -if initializers { +if settings.initializers.view_engine { gen.copy_file("src/initializers/view_engine.rs"); // Template for view engine initializer } @@ -125,7 +125,7 @@ if background { // ===================== // Adds asset directory if assets are configured in the app. -if asset { +if settings.assets { gen.copy_dir("assets"); // Static assets directory } @@ -134,7 +134,7 @@ if asset { // Client side // ===================== -if settings.clientside { +if settings.rendering_method.client_side { gen.copy_dir("frontend"); gen.create_file("frontend/dist/index.html", "this is a placeholder. please run your frontend build (npm build)"); } diff --git a/loco-new/src/bin/main.rs b/loco-new/src/bin/main.rs index c9329ac65..cb9afa3cc 100644 --- a/loco-new/src/bin/main.rs +++ b/loco-new/src/bin/main.rs @@ -47,9 +47,9 @@ enum Commands { #[arg(long)] bg: Option, - /// Assets serving configuration + /// Frontend rendering method configuration #[arg(long)] - assets: Option, + rendering_method: Option, /// Create the starter in target git repository #[arg(short, long)] @@ -82,12 +82,12 @@ fn main() -> Result<()> { path, db, bg, - assets, + rendering_method, name, allow_in_git_repo, os, } => { - tracing::debug!(path = ?path, db = ?db, bg=?bg, assets=?assets,name=?name, allow_in_git_repo=allow_in_git_repo, os=?os, "CLI options"); + tracing::debug!(path = ?path, db = ?db, bg=?bg, rendering_method=?rendering_method,name=?name, allow_in_git_repo=allow_in_git_repo, os=?os, "CLI options"); if !allow_in_git_repo && is_a_git_repo(path.as_path()).unwrap_or(false) { tracing::debug!("the target directory is a Git repository"); wizard::warn_if_in_git_repo()?; @@ -106,7 +106,11 @@ fn main() -> Result<()> { tracing::debug!(dir = %to.display(), "creating application directory"); std::fs::create_dir_all(&to)?; - let args = wizard::ArgsPlaceholder { db, bg, assets }; + let args = wizard::ArgsPlaceholder { + db, + bg, + rendering_method, + }; let user_selection = wizard::start(&args)?; let generator_tmp_folder = extract_default_template()?; diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index a477ab1b6..805475dfb 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -1,15 +1,23 @@ //! This module defines the `Generator` struct, which is responsible for //! executing scripted commands -use std::path::{Path, PathBuf}; pub mod executer; pub mod template; -use std::sync::Arc; + +use std::{ + path::{Path, PathBuf}, + sync::Arc, +}; use include_dir::{include_dir, Dir}; -use rhai::{Engine, Scope}; +use rhai::{export_module, exported_module, plugin::*, Dynamic, Engine, Scope}; -use crate::{settings, OS}; +use crate::{ + settings, + settings::{Initializers, RenderingMethod}, + wizard::RenderingMethodOption, + OS, +}; static APP_TEMPLATE: Dir<'_> = include_dir!("base_template"); @@ -68,7 +76,12 @@ impl Generator { ); engine .build_type::() - .build_type::() + .register_type_with_name::>("Option") + .register_type_with_name::>("Option") + .register_static_module( + "rhai_settings_extensions", + exported_module!(rhai_settings_extensions).into(), + ) .register_fn("copy_file", Self::copy_file) .register_fn("create_file", Self::create_file) .register_fn("copy_files", Self::copy_files) @@ -85,8 +98,6 @@ impl Generator { // TODO:: move it as part of the settings? scope.push("db", self.settings.db.is_some()); scope.push("background", self.settings.background.is_some()); - scope.push("initializers", self.settings.initializers.is_some()); - scope.push("asset", self.settings.asset.is_some()); scope.push("windows", self.settings.os == OS::Windows); engine.run_with_scope(&mut scope, script)?; @@ -232,6 +243,34 @@ impl Generator { } } +/// This module provides extensions to the Rhai scripting language to access +/// the inner fields of the [Settings] struct in a more ergonomic way. +#[export_module] +mod rhai_settings_extensions { + + /// Gives the script access to `settings.initializers.view_engine`. + #[rhai_fn(global, get = "view_engine", pure)] + pub fn view_engine(initializers: &mut Option) -> bool { + initializers.as_ref().map_or(false, |i| i.view_engine) + } + + /// Gives the script access to `settings.rendering_method.client_side`. + #[rhai_fn(global, get = "client_side", pure)] + pub fn client_side(rendering_method: &mut Option) -> bool { + rendering_method.as_ref().map_or(false, |r| { + matches!(r.kind, RenderingMethodOption::Clientside) + }) + } + + /// Gives the script access to `settings.rendering_method.server_side`. + #[rhai_fn(global, get = "server_side", pure)] + pub fn server_side(rendering_method: &mut Option) -> bool { + rendering_method.as_ref().map_or(false, |r| { + matches!(r.kind, RenderingMethodOption::Serverside) + }) + } +} + #[cfg(test)] mod tests { use executer::MockExecuter; diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index b142b09be..aff16f149 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -7,7 +7,7 @@ use rhai::{CustomType, TypeBuilder}; use serde::{Deserialize, Serialize}; use crate::{ - wizard::{self, AssetsOption, BackgroundOption, DBOption}, + wizard::{self, BackgroundOption, DBOption, RenderingMethodOption}, LOCO_VERSION, OS, }; @@ -18,10 +18,12 @@ pub struct Settings { pub module_name: String, pub db: Option, pub background: Option, - pub asset: Option, + /// Frontend rendering method configuration + pub rendering_method: Option, + /// Copy the asset folder to the new project + pub assets: bool, pub auth: bool, pub mailer: bool, - pub clientside: bool, pub initializers: Option, pub features: Features, pub loco_version_text: String, @@ -49,11 +51,13 @@ impl From for Option { } } -impl From for Option { - fn from(asset: AssetsOption) -> Self { - match asset { - AssetsOption::None => None, - _ => Some(Asset { kind: asset }), +impl From for Option { + fn from(rendering_method: RenderingMethodOption) -> Self { + match rendering_method { + RenderingMethodOption::None => None, + _ => Some(RenderingMethod { + kind: rendering_method, + }), } } } @@ -72,20 +76,32 @@ impl Settings { features }; + // we only need the view engine initializer for serverside rendering + let initializers = if matches!( + prompt_selection.rendering_method, + RenderingMethodOption::Serverside + ) { + Some(Initializers { view_engine: true }) + } else { + None + }; + + // we only need to copy the asset folder for serverside rendering + let assets = matches!( + prompt_selection.rendering_method, + RenderingMethodOption::Serverside + ); + Self { package_name: package_name.to_string(), module_name: package_name.to_snake_case(), + assets, auth: prompt_selection.db.enable() && prompt_selection.background.enable(), mailer: prompt_selection.db.enable() && prompt_selection.background.enable(), db: prompt_selection.db.clone().into(), background: prompt_selection.background.clone().into(), - asset: prompt_selection.asset.clone().into(), - clientside: prompt_selection.asset.enable(), - initializers: if prompt_selection.asset.enable() { - Some(Initializers { view_engine: true }) - } else { - None - }, + rendering_method: prompt_selection.rendering_method.clone().into(), + initializers, features, loco_version_text: get_loco_version_text(), os, @@ -100,10 +116,10 @@ impl Default for Settings { module_name: Default::default(), db: Default::default(), background: Default::default(), - asset: Default::default(), + rendering_method: Default::default(), + assets: Default::default(), auth: Default::default(), mailer: Default::default(), - clientside: Default::default(), initializers: Default::default(), features: Default::default(), loco_version_text: get_loco_version_text(), @@ -135,10 +151,10 @@ pub struct Background { pub kind: BackgroundOption, } -/// Asset configuration settings. +/// Rendering method configuration. #[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)] -pub struct Asset { - pub kind: AssetsOption, +pub struct RenderingMethod { + pub kind: RenderingMethodOption, } #[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)] diff --git a/loco-new/src/wizard.rs b/loco-new/src/wizard.rs index 16ba8c699..7142337ac 100644 --- a/loco-new/src/wizard.rs +++ b/loco-new/src/wizard.rs @@ -14,9 +14,9 @@ use crate::Error; )] pub enum Template { #[default] - #[strum(to_string = "Saas App with server side rendering")] + #[strum(to_string = "Saas App with server-side rendering")] SaasServerSideRendering, - #[strum(to_string = "Saas App with client side rendering")] + #[strum(to_string = "Saas App with client-side rendering")] SaasClientSideRendering, #[strum(to_string = "Rest API (with DB and user auth)")] RestApi, @@ -32,8 +32,8 @@ pub enum OptionsList { DB, #[serde(rename = "bg")] Background, - #[serde(rename = "assets")] - Assets, + #[serde(rename = "rendering_method")] + RenderingMethod, } #[derive( @@ -136,12 +136,12 @@ impl BackgroundOption { #[derive( Debug, Clone, Deserialize, Serialize, EnumIter, Display, Default, PartialEq, Eq, ValueEnum, )] -pub enum AssetsOption { +pub enum RenderingMethodOption { #[default] - #[strum(to_string = "Server (configures server-rendered views)")] + #[strum(to_string = "Server (configures server-side rendering)")] #[serde(rename = "server")] Serverside, - #[strum(to_string = "Client (configures assets for frontend serving)")] + #[strum(to_string = "Client (configures client-side rendering)")] #[serde(rename = "client")] Clientside, #[strum(to_string = "None")] @@ -149,20 +149,16 @@ pub enum AssetsOption { None, } -impl AssetsOption { - #[must_use] - pub const fn enable(&self) -> bool { - !matches!(self, Self::None) - } - +impl RenderingMethodOption { #[must_use] pub fn user_message(&self) -> Option { match self { Self::Clientside => Some(format!( - "{}: You've selected `{}` for your asset serving configuration.\n\nNext step, \ - build your frontend:\n $ cd {}\n $ npm install && npm run build\n", - "assets".underline(), - "clientside".yellow(), + "{}: You've selected `{}` as your frontend rendering method.\n\nTo build your \ + frontend, please run the following commands:\n$ cd {}\n$ npm install && npm run \ + build\n", + "Rendering method".underline(), + "client-side rendering".yellow(), "frontend/".yellow() )), Self::Serverside | Self::None => None, @@ -175,14 +171,14 @@ impl AssetsOption { pub struct ArgsPlaceholder { pub db: Option, pub bg: Option, - pub assets: Option, + pub rendering_method: Option, } /// Holds the user's configuration selections. pub struct Selections { pub db: DBOption, pub background: BackgroundOption, - pub asset: AssetsOption, + pub rendering_method: RenderingMethodOption, } impl Selections { @@ -195,7 +191,7 @@ impl Selections { if let Some(m) = self.background.user_message() { res.push(m); } - if let Some(m) = self.asset.user_message() { + if let Some(m) = self.rendering_method.user_message() { res.push(m); } res @@ -295,13 +291,15 @@ where /// when could not show user selection or user chose not continue pub fn start(args: &ArgsPlaceholder) -> crate::Result { // user provided everything via flags so no need to prompt, just return - if let (Some(db), Some(bg), Some(assets)) = - (args.db.clone(), args.bg.clone(), args.assets.clone()) - { + if let (Some(db), Some(bg), Some(rendering_method)) = ( + args.db.clone(), + args.bg.clone(), + args.rendering_method.clone(), + ) { return Ok(Selections { db, background: bg, - asset: assets, + rendering_method, }); } @@ -314,22 +312,22 @@ pub fn start(args: &ArgsPlaceholder) -> crate::Result { Template::Lightweight => Ok(Selections { db: DBOption::None, background: BackgroundOption::None, - asset: AssetsOption::None, + rendering_method: RenderingMethodOption::None, }), Template::RestApi => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: AssetsOption::None, + rendering_method: RenderingMethodOption::None, }), Template::SaasServerSideRendering => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: AssetsOption::Serverside, + rendering_method: RenderingMethodOption::Serverside, }), Template::SaasClientSideRendering => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: AssetsOption::Clientside, + rendering_method: RenderingMethodOption::Clientside, }), Template::Advanced => { let db = select_db(args)?; @@ -340,7 +338,7 @@ pub fn start(args: &ArgsPlaceholder) -> crate::Result { Ok(Selections { db, background: select_background(args, background_options.as_ref())?, - asset: select_asset(args)?, + rendering_method: select_rendering_method(args)?, }) } } @@ -378,16 +376,16 @@ fn select_background( Ok(bgopt) } -/// Prompts the user to select an asset configuration if none is provided in the -/// arguments. -fn select_asset(args: &ArgsPlaceholder) -> crate::Result { - let assetopt = if let Some(assetopt) = args.assets.clone() { - assetopt +/// Prompts the user to select frontend rendering method if none is provided in +/// the arguments. +fn select_rendering_method(args: &ArgsPlaceholder) -> crate::Result { + let rendering_method_opt = if let Some(rendering_method_opt) = args.rendering_method.clone() { + rendering_method_opt } else { select_option( - "❯ Select an asset serving configuration", - &AssetsOption::iter().collect::>(), + "❯ Select a frontend rendering method", + &RenderingMethodOption::iter().collect::>(), )? }; - Ok(assetopt) + Ok(rendering_method_opt) } diff --git a/loco-new/tests/assertion/string.rs b/loco-new/tests/assertion/string.rs index 8f33a9de4..581792b6c 100644 --- a/loco-new/tests/assertion/string.rs +++ b/loco-new/tests/assertion/string.rs @@ -35,8 +35,8 @@ pub fn assert_contains(content: &str, expected: &str) { assert!( content_sanitized.contains(&expected_sanitized), - "Assertion failed: The content did not contain the expected string. \ - Expected: '{expected_sanitized}', content:\n{content_sanitized}" + "Assertion failed: The content did not contain the expected string. Expected: \ + '{expected_sanitized}', content:\n{content_sanitized}" ); } @@ -46,7 +46,7 @@ pub fn assert_not_contains(content: &str, unexpected: &str) { assert!( !content_sanitized.contains(&unexpected_sanitized), - "Assertion failed: The content unexpectedly contained the string. \ - Unexpected: '{unexpected_sanitized}', content:\n{content_sanitized}" + "Assertion failed: The content unexpectedly contained the string. Unexpected: \ + '{unexpected_sanitized}', content:\n{content_sanitized}" ); } diff --git a/loco-new/tests/templates/mod.rs b/loco-new/tests/templates/mod.rs index d2c6f9af6..9ac4722e3 100644 --- a/loco-new/tests/templates/mod.rs +++ b/loco-new/tests/templates/mod.rs @@ -9,7 +9,6 @@ use loco::{ }; use rand::{rngs::StdRng, SeedableRng}; -mod asset; mod auth; mod background; mod db; @@ -17,6 +16,7 @@ mod features; mod initializers; mod mailer; mod module_name; +mod rendering_method; pub struct TestGenerator { tree: tree_fs::Tree, diff --git a/loco-new/tests/templates/asset.rs b/loco-new/tests/templates/rendering_method.rs similarity index 65% rename from loco-new/tests/templates/asset.rs rename to loco-new/tests/templates/rendering_method.rs index 2c248fa4d..378f1b51b 100644 --- a/loco-new/tests/templates/asset.rs +++ b/loco-new/tests/templates/rendering_method.rs @@ -1,12 +1,12 @@ -use loco::{settings, wizard::AssetsOption}; +use loco::{settings, wizard::RenderingMethodOption}; use rstest::rstest; use super::*; use crate::assertion; -pub fn run_generator(asset: AssetsOption) -> TestGenerator { +pub fn run_generator(rendering_method: RenderingMethodOption) -> TestGenerator { let settings = settings::Settings { - asset: asset.into(), + rendering_method: rendering_method.into(), ..Default::default() }; @@ -14,20 +14,20 @@ pub fn run_generator(asset: AssetsOption) -> TestGenerator { } #[rstest] -fn test_config_file_middleware_when_asset_empty( +fn test_config_file_middleware_when_rendering_method_empty( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { - let generator: TestGenerator = run_generator(AssetsOption::None); + let generator: TestGenerator = run_generator(RenderingMethodOption::None); let content = assertion::yaml::load(generator.path(config_file)); assertion::yaml::assert_path_is_empty(&content, &["server", "middlewares"]); } #[rstest] -fn test_config_file_middleware_asset_server( +fn test_config_file_middleware_when_rendering_method_server_side( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { - let generator: TestGenerator = run_generator(AssetsOption::Serverside); + let generator: TestGenerator = run_generator(RenderingMethodOption::Serverside); let content = assertion::yaml::load(generator.path(config_file)); assertion::yaml::assert_path_is_object(&content, &["server", "middlewares", "static"]); @@ -52,10 +52,10 @@ fallback: assets/static/404.html } #[rstest] -fn test_config_file_middleware_asset_client( +fn test_config_file_middleware_when_rendering_method_client_side( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { - let generator: TestGenerator = run_generator(AssetsOption::Clientside); + let generator: TestGenerator = run_generator(RenderingMethodOption::Clientside); let content = assertion::yaml::load(generator.path(config_file)); assertion::yaml::assert_path_is_object(&content, &["server", "middlewares"]); @@ -80,24 +80,32 @@ static: #[rstest] fn test_cargo_toml( - #[values(AssetsOption::None, AssetsOption::Serverside, AssetsOption::Clientside)] - asset: AssetsOption, + #[values( + RenderingMethodOption::None, + RenderingMethodOption::Serverside, + RenderingMethodOption::Clientside + )] + rendering_method: RenderingMethodOption, ) { - let generator = run_generator(asset.clone()); + let generator = run_generator(rendering_method.clone()); let content = assertion::toml::load(generator.path("Cargo.toml")); insta::assert_snapshot!( - format!("cargo_dependencies_{:?}", asset), + format!("cargo_dependencies_{:?}", rendering_method), content.get("dependencies").unwrap() ); } #[rstest] fn test_github_ci_yaml( - #[values(AssetsOption::None, AssetsOption::Serverside, AssetsOption::Clientside)] - asset: AssetsOption, + #[values( + RenderingMethodOption::None, + RenderingMethodOption::Serverside, + RenderingMethodOption::Clientside + )] + rendering_method: RenderingMethodOption, ) { - let generator: TestGenerator = run_generator(asset.clone()); + let generator: TestGenerator = run_generator(rendering_method.clone()); let content = assertion::string::load(generator.path(".github").join("workflows").join("ci.yaml")); @@ -111,11 +119,11 @@ fn test_github_ci_yaml( - name: Setup Rust cache uses: Swatinem/rust-cache@v2"; - match asset { - AssetsOption::Serverside | AssetsOption::None => { + match rendering_method { + RenderingMethodOption::Serverside | RenderingMethodOption::None => { assertion::string::assert_not_contains(&content, frontend_section); } - AssetsOption::Clientside => { + RenderingMethodOption::Clientside => { assertion::string::assert_contains(&content, frontend_section); } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Serverside.snap b/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Serverside.snap deleted file mode 100644 index 0b77f22a9..000000000 --- a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Serverside.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: tests/templates/asset.rs -expression: "content.get(\"dependencies\").unwrap()" ---- -{ async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, fluent-templates = { features = ["tera"], version = "0.8.0" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" }, unic-langid = { version = "0.9.4" } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap new file mode 100644 index 000000000..9ed659322 --- /dev/null +++ b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap @@ -0,0 +1,6 @@ +--- +source: tests/templates/rendering_method.rs +expression: "content.get(\"dependencies\").unwrap()" +snapshot_kind: text +--- +{ async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_None.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap similarity index 91% rename from loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_None.snap rename to loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap index 2bc81b44c..4a7518008 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_None.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap @@ -1,5 +1,5 @@ --- -source: tests/templates/asset.rs +source: tests/templates/rendering_method.rs expression: "content.get(\"dependencies\").unwrap()" --- { async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Clientside.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap similarity index 92% rename from loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Clientside.snap rename to loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap index 0b77f22a9..8f046d841 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Clientside.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap @@ -1,5 +1,5 @@ --- -source: tests/templates/asset.rs +source: tests/templates/rendering_method.rs expression: "content.get(\"dependencies\").unwrap()" --- { async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, fluent-templates = { features = ["tera"], version = "0.8.0" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" }, unic-langid = { version = "0.9.4" } } diff --git a/loco-new/tests/wizard/new.rs b/loco-new/tests/wizard/new.rs index c0f5dda23..ce05c08bf 100644 --- a/loco-new/tests/wizard/new.rs +++ b/loco-new/tests/wizard/new.rs @@ -1,11 +1,12 @@ +use std::{collections::HashMap, path::PathBuf, process::Output, sync::Arc}; + use duct::cmd; use loco::{ generator::{executer::FileSystem, Generator}, settings, - wizard::{self, AssetsOption, BackgroundOption, DBOption}, + wizard::{self, BackgroundOption, DBOption, RenderingMethodOption}, OS, }; -use std::{collections::HashMap, path::PathBuf, process::Output, sync::Arc}; #[cfg(feature = "test-wizard")] #[rstest::rstest] @@ -18,10 +19,14 @@ fn test_all_combinations( BackgroundOption::None )] background: BackgroundOption, - #[values(AssetsOption::Serverside, AssetsOption::Clientside, AssetsOption::None)] - asset: AssetsOption, + #[values( + RenderingMethodOption::Serverside, + RenderingMethodOption::Clientside, + RenderingMethodOption::None + )] + rendering_method: RenderingMethodOption, ) { - test_combination(db, background, asset, false); + test_combination(db, background, rendering_method, false); } // when running locally set LOCO_DEV_MODE_PATH= @@ -31,35 +36,35 @@ fn test_starter_combinations() { test_combination( DBOption::None, BackgroundOption::None, - AssetsOption::None, + RenderingMethodOption::None, true, ); // REST API test_combination( DBOption::Sqlite, BackgroundOption::Async, - AssetsOption::None, + RenderingMethodOption::None, true, ); // SaaS, serverside test_combination( DBOption::Sqlite, BackgroundOption::Async, - AssetsOption::Serverside, + RenderingMethodOption::Serverside, true, ); // SaaS, clientside test_combination( DBOption::Sqlite, BackgroundOption::Async, - AssetsOption::Clientside, + RenderingMethodOption::Clientside, true, ); // test only DB test_combination( DBOption::Sqlite, BackgroundOption::None, - AssetsOption::None, + RenderingMethodOption::None, true, ); } @@ -67,7 +72,7 @@ fn test_starter_combinations() { fn test_combination( db: DBOption, background: BackgroundOption, - asset: AssetsOption, + rendering_method: RenderingMethodOption, test_generator: bool, ) { let test_dir = tree_fs::TreeBuilder::default().drop(true); @@ -77,7 +82,7 @@ fn test_combination( let wizard_selection = wizard::Selections { db: db.clone(), background: background.clone(), - asset, + rendering_method, }; let settings = settings::Settings::from_wizard("test-loco-template", &wizard_selection, OS::default());