-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Rework
moon init
command. (#1204)
* Minor polish. * Update init/node. * Update ts/rust. * Added bun. * Update changelog. * Update error. * Final pass. * Fix tests. * Polish rust.
- Loading branch information
Showing
42 changed files
with
760 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use super::prompts::prompt_version; | ||
use super::InitOptions; | ||
use dialoguer::theme::ColorfulTheme; | ||
use dialoguer::Confirm; | ||
use miette::IntoDiagnostic; | ||
use moon_bun_lang::BUNPM; | ||
use moon_config::load_toolchain_bun_config_template; | ||
use moon_terminal::label_header; | ||
use starbase::AppResult; | ||
use starbase_styles::color; | ||
use std::path::Path; | ||
use tera::{Context, Tera}; | ||
|
||
pub fn render_template(context: Context) -> AppResult<String> { | ||
Tera::one_off(load_toolchain_bun_config_template(), &context, false).into_diagnostic() | ||
} | ||
|
||
pub async fn init_bun( | ||
_dest_dir: &Path, | ||
options: &InitOptions, | ||
theme: &ColorfulTheme, | ||
) -> AppResult<String> { | ||
if !options.yes { | ||
println!("\n{}\n", label_header("Bun")); | ||
|
||
println!( | ||
"Toolchain: {}", | ||
color::url("https://moonrepo.dev/docs/concepts/toolchain") | ||
); | ||
println!( | ||
"Handbook: {}", | ||
color::url("https://moonrepo.dev/docs/guides/javascript/bun-handbook") | ||
); | ||
println!( | ||
"Config: {}\n", | ||
color::url("https://moonrepo.dev/docs/config/toolchain#bun") | ||
); | ||
} | ||
|
||
let bun_version = prompt_version("Bun", options, theme, || Ok(String::new()))?; | ||
|
||
let sync_dependencies = options.yes | ||
|| options.minimal | ||
|| Confirm::with_theme(theme) | ||
.with_prompt(format!( | ||
"Sync project relationships as {} {}?", | ||
color::file(BUNPM.manifest), | ||
color::property("dependencies") | ||
)) | ||
.interact() | ||
.into_diagnostic()?; | ||
|
||
let mut context = Context::new(); | ||
context.insert("bun_version", &bun_version); | ||
context.insert("sync_dependencies", &sync_dependencies); | ||
context.insert("minimal", &options.minimal); | ||
|
||
render_template(context) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use moon_test_utils::assert_snapshot; | ||
|
||
#[test] | ||
fn renders_default() { | ||
let mut context = Context::new(); | ||
context.insert("bun_version", &"1.0.0"); | ||
context.insert("infer_tasks", &false); | ||
context.insert("sync_dependencies", &true); | ||
|
||
assert_snapshot!(render_template(context).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn renders_minimal() { | ||
let mut context = Context::new(); | ||
context.insert("bun_version", &"1.0.0"); | ||
context.insert("sync_dependencies", &true); | ||
context.insert("minimal", &true); | ||
|
||
assert_snapshot!(render_template(context).unwrap()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.