Skip to content

Commit

Permalink
refactor: created version.rs & pg.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur16 committed May 21, 2024
1 parent 45e0dda commit a0214a3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod metrics;
pub mod server;
mod tc;
pub mod telemetry;
mod version;

pub mod runtime;
pub(crate) mod update_checker;
Expand Down
17 changes: 5 additions & 12 deletions src/cli/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
pub mod http_1;
pub mod http_2;
pub mod http_server;
pub mod playground;
pub mod server_config;

pub use http_server::Server;

use self::server_config::ServerConfig;
use crate::cli::command::VERSION;

const GRAPHQL_SLUG: &str = "/graphql";

fn log_launch(sc: &ServerConfig) {
let addr = sc.addr().to_string();
Expand All @@ -16,16 +18,7 @@ fn log_launch(sc: &ServerConfig) {
sc.http_version()
);

let url = sc.graphiql_url();
let utm_source = if VERSION.eq("0.1.0-dev") {
"tailcall-debug"
} else {
"tailcall-release"
};
let utm_medium = "server";
let url = format!(
"https://tailcall.run/playground/?u={}/graphql&utm_source={}&utm_medium={}",
url, utm_source, utm_medium
);
let graphiql_url = sc.graphiql_url() + GRAPHQL_SLUG;
let url = playground::build_url(&graphiql_url);
tracing::info!("🌍 Playground: {}", url);
}
19 changes: 19 additions & 0 deletions src/cli/server/playground.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::cli::version::VERSION;

const UTM_MEDIUM: &str = "server";
const DEBUG_UTM_SOURCE: &str = "tailcall-debug";
const RELEASE_UTM_SOURCE: &str = "tailcall-release";
const BASE_PLAYGROUND_URL: &str = "https://tailcall.run/playground/";

pub fn build_url(graphiql_url: &str) -> String {
let utm_source = if VERSION.is_dev() {
DEBUG_UTM_SOURCE
} else {
RELEASE_UTM_SOURCE

Check warning on line 12 in src/cli/server/playground.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/playground.rs#L12

Added line #L12 was not covered by tests
};

format!(
"{}?u={}&utm_source={}&utm_medium={}",
BASE_PLAYGROUND_URL, graphiql_url, utm_source, UTM_MEDIUM
)
}
42 changes: 42 additions & 0 deletions src/cli/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const DEFAULT_VERSION: &str = "0.1.0-dev";

pub struct Version {
version: &'static str,
}

impl Version {
pub const fn new(version: &'static str) -> Self {
Version { version }
}

Check warning on line 10 in src/cli/version.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/version.rs#L8-L10

Added lines #L8 - L10 were not covered by tests

// pub const fn as_str(&self) -> &'static str {
// self.version
// }

pub fn is_dev(&self) -> bool {
self.version == DEFAULT_VERSION
}
}

pub const VERSION: Version = match option_env!("APP_VERSION") {
Some(version) => Version::new(version),
None => Version::new(DEFAULT_VERSION),
};

// #[cfg(test)]
// mod tests {
// use super::*;

// #[test]
// fn test_default_version() {
// assert_eq!(VERSION.as_str(), DEFAULT_VERSION);
// assert!(VERSION.is_dev());
// }

// #[test]
// fn test_custom_version() {
// const CUSTOM_VERSION: Version = Version::new("1.0.0-release");
// assert_eq!(CUSTOM_VERSION.as_str(), "1.0.0-release");
// assert!(!CUSTOM_VERSION.is_dev());
// }
// }

0 comments on commit a0214a3

Please sign in to comment.