Skip to content

Commit

Permalink
loco version support local and normal
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Nov 13, 2024
1 parent 171a64c commit 31b62a5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
3 changes: 1 addition & 2 deletions loco-new/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ fn main() -> Result<()> {
let executor =
executer::FileSystem::new(generator_tmp_folder.as_path(), to.as_path());

let mut settings = Settings::from_wizard(&app_name, &user_selection);
let settings = Settings::from_wizard(&app_name, &user_selection);

if let Ok(path) = env::var("LOCO_DEV_MODE_PATH") {
println!("⚠️ NOTICE: working in dev mode, pointing to local Loco on '{path}'");
settings.loco_version_text = format!(r#"version="*", path="{path}""#);
}

let res = match Generator::new(Arc::new(executor), settings).run() {
Expand Down
30 changes: 28 additions & 2 deletions loco-new/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Defines configurable application settings.

use std::env;

use heck::ToSnakeCase;
use rhai::{CustomType, TypeBuilder};
use serde::{Deserialize, Serialize};

use crate::{wizard, wizard_opts, LOCO_VERSION};

/// Represents general application settings.
#[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)]
#[derive(Serialize, Deserialize, Clone, Debug, CustomType)]
pub struct Settings {
pub package_name: String,
pub module_name: String,
Expand Down Expand Up @@ -79,11 +81,35 @@ impl Settings {
None
},
features,
loco_version_text: format!(r#"version = "{LOCO_VERSION}""#),
loco_version_text: get_loco_version_text(),
}
}
}
impl Default for Settings {
fn default() -> Self {
Self {
package_name: Default::default(),
module_name: Default::default(),
db: Default::default(),
background: Default::default(),
asset: Default::default(),
auth: Default::default(),
mailer: Default::default(),
initializers: Default::default(),
features: Default::default(),
loco_version_text: get_loco_version_text(),
}
}
}

fn get_loco_version_text() -> String {
if let Ok(path) = env::var("LOCO_DEV_MODE_PATH") {
format!(r#"version="*", path="{path}""#)
} else {
format!(r#"version = "{LOCO_VERSION}""#)
}
}

/// Database configuration settings.
#[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)]
pub struct Db {
Expand Down
13 changes: 9 additions & 4 deletions loco-new/tests/wizard/new.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use duct::cmd;
use rstest::rstest;
use std::{fs, path::PathBuf, sync::Arc};
use uuid::Uuid;

use duct::cmd;
use loco::{
generator::{executer::FileSystem, Generator},
settings, wizard,
wizard_opts::{AssetsOption, BackgroundOption, DBOption},
};
use rstest::rstest;
use uuid::Uuid;

struct TestDir {
pub path: PathBuf,
Expand Down Expand Up @@ -43,6 +43,8 @@ fn new_from_wizard(
#[values(AssetsOption::Serverside, AssetsOption::Clientside, AssetsOption::None)]
asset: AssetsOption,
) {
use std::collections::HashMap;

let test_dir = TestDir::new();

let executor = FileSystem::new(&PathBuf::from("base_template"), &test_dir.path);
Expand All @@ -57,8 +59,10 @@ fn new_from_wizard(
let res = Generator::new(Arc::new(executor), settings).run();
assert!(res.is_ok());

let mut env_map: HashMap<_, _> = std::env::vars().collect();
env_map.insert("RUSTFLAGS".into(), "-D warnings".into());
assert!(cmd!("cargo", "check")
.env("RUSTFLAGS", "-D warnings")
.full_env(&env_map)
// .stdout_null()
// .stderr_null()
.dir(test_dir.path.as_path())
Expand All @@ -68,6 +72,7 @@ fn new_from_wizard(
cmd!("cargo", "test")
// .stdout_null()
// .stderr_null()
.full_env(&env_map)
.dir(test_dir.path.as_path())
.run()
.expect("run test");
Expand Down

0 comments on commit 31b62a5

Please sign in to comment.