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 dada9fa commit d42e9c0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/loco-cli-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ on:
branches:
- master
paths:
- 'loco-new/**'
- "loco-new/**"
pull_request:
paths:
- 'loco-new/**'

- "loco-new/**"

env:
RUST_TOOLCHAIN: stable
Expand Down Expand Up @@ -61,4 +60,5 @@ jobs:
- name: Run cargo test
run: cargo test --all-features
working-directory: ./loco-new

env:
LOCO_DEV_MODE_PATH: ${{ github.workspace }}
2 changes: 1 addition & 1 deletion loco-new/base_template/Cargo.toml.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default-run = "{{settings.module_name}}-cli"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace.dependencies]
loco-rs = { version = "0.12.0" {%- if not settings.features.default_features %}, default-features = false {%- endif %} }
loco-rs = { {{settings.loco_version_text}} {%- if not settings.features.default_features %}, default-features = false {%- endif %} }

[dependencies]
loco-rs = { workspace = true {% if feature_list | length > 0 %}, features = {{feature_list}}{% endif %} }
Expand Down
3 changes: 2 additions & 1 deletion loco-new/base_template/migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ path = "src/lib.rs"

[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }
loco-rs = { version = "0.12.0" }
loco-rs = { workspace = true }


[dependencies.sea-orm-migration]
version = "1.1.0"
Expand Down
13 changes: 9 additions & 4 deletions loco-new/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use duct::cmd;
use std::process::exit;
use std::{
env,
path::{Path, PathBuf},
process::Command,
process::{exit, Command},
sync::Arc,
};

use clap::{Parser, Subcommand};
use duct::cmd;
use loco::{
generator::{executer, extract_default_template, Generator},
settings::Settings,
Expand Down Expand Up @@ -107,7 +107,12 @@ fn main() -> Result<()> {
let executor =
executer::FileSystem::new(generator_tmp_folder.as_path(), to.as_path());

let settings = Settings::from_wizard(&app_name, &user_selection);
let mut 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() {
Ok(()) => {
Expand Down
3 changes: 3 additions & 0 deletions loco-new/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pub mod wizard_opts;

pub type Result<T> = std::result::Result<T, Error>;

/// Matching minimal Loco version
pub const LOCO_VERSION: &str = "0.13";

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("{0}")]
Expand Down
5 changes: 4 additions & 1 deletion loco-new/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Defines configurable application settings.

use crate::{wizard, wizard_opts};
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)]
pub struct Settings {
Expand All @@ -17,6 +18,7 @@ pub struct Settings {
pub mailer: bool,
pub initializers: Option<Initializers>,
pub features: Features,
pub loco_version_text: String,
}

impl From<wizard_opts::DBOption> for Option<Db> {
Expand Down Expand Up @@ -77,6 +79,7 @@ impl Settings {
None
},
features,
loco_version_text: format!(r#"version = "{LOCO_VERSION}""#),
}
}
}
Expand Down

0 comments on commit d42e9c0

Please sign in to comment.