-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: created version.rs & pg.rs
- Loading branch information
1 parent
45e0dda
commit a0214a3
Showing
4 changed files
with
67 additions
and
12 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
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,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 | ||
}; | ||
|
||
format!( | ||
"{}?u={}&utm_source={}&utm_medium={}", | ||
BASE_PLAYGROUND_URL, graphiql_url, utm_source, UTM_MEDIUM | ||
) | ||
} |
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,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 } | ||
} | ||
|
||
// 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()); | ||
// } | ||
// } |