Skip to content

Commit

Permalink
feat(next/dev): allow to display version (vercel#2793)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj authored Nov 22, 2022
1 parent b6a60a0 commit 079b83f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/next-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ nix = "0.25.0"

[build-dependencies]
turbo-tasks-build = { path = "../turbo-tasks-build" }
vergen = { version = "7.3.2", default-features = false, features = ["cargo","git"] }
5 changes: 5 additions & 0 deletions crates/next-dev/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use turbo_tasks_build::generate_register;
use vergen::{vergen, Config};

fn main() {
generate_register();

// Attempt to collect some build time env values but will skip if there are any
// errors.
let _ = vergen(Config::default());
}
5 changes: 5 additions & 0 deletions crates/next-dev/src/devserver_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ pub struct DevServerOptions {
#[cfg_attr(feature = "serializable", serde(default))]
pub eager_compile: bool,

/// Display version of the binary. Noop if used in library mode.
#[cfg_attr(feature = "cli", clap(long))]
#[cfg_attr(feature = "serializable", serde(default))]
pub display_version: bool,

/// Don't open the browser automatically when the dev server has started.
#[cfg_attr(feature = "cli", clap(long))]
#[cfg_attr(feature = "serializable", serde(default))]
Expand Down
37 changes: 37 additions & 0 deletions crates/next-dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,42 @@ fn main() -> Result<()> {
async fn main() -> Result<()> {
let options = next_dev::devserver_options::DevServerOptions::parse();

if options.display_version {
println!(
"Build Timestamp\t\t{:#?}",
option_env!("VERGEN_BUILD_TIMESTAMP").unwrap_or_else(|| "N/A")
);
println!(
"Build Version\t\t{:#?}",
option_env!("VERGEN_BUILD_SEMVER").unwrap_or_else(|| "N/A")
);
println!(
"Commit SHA\t\t{:#?}",
option_env!("VERGEN_GIT_SHA").unwrap_or_else(|| "N/A")
);
println!(
"Commit Date\t\t{:#?}",
option_env!("VERGEN_GIT_COMMIT_TIMESTAMP").unwrap_or_else(|| "N/A")
);
println!(
"Commit Branch\t\t{:#?}",
option_env!("VERGEN_GIT_BRANCH").unwrap_or_else(|| "N/A")
);
println!(
"Commit Message\t\t{:#?}",
option_env!("VERGEN_GIT_COMMIT_MESSAGE").unwrap_or_else(|| "N/A")
);
println!(
"Cargo Target Triple\t{:#?}",
option_env!("VERGEN_CARGO_TARGET_TRIPLE").unwrap_or_else(|| "N/A")
);
println!(
"Cargo Profile\t\t{:#?}",
option_env!("VERGEN_CARGO_PROFILE").unwrap_or_else(|| "N/A")
);

return Ok(());
}

next_dev::start_server(&options).await
}

0 comments on commit 079b83f

Please sign in to comment.