From 3d1cb5e20f7a05314f6fd4261076b0a85546cfe4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 19 Mar 2020 09:32:57 +0100 Subject: Simplify extension tag sniffing --- xtask/src/dist.rs | 23 ++++++++++------------- xtask/src/main.rs | 5 +++-- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index e3dddd9b1..3a14f8a63 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -7,31 +7,27 @@ use crate::{ project_root, }; -pub fn run_dist(nightly: bool) -> Result<()> { +pub fn run_dist(version: &str, release_tag: &str) -> Result<()> { let dist = project_root().join("dist"); rm_rf(&dist)?; fs2::create_dir_all(&dist)?; if cfg!(target_os = "linux") { - dist_client(nightly)?; + dist_client(version, release_tag)?; } dist_server()?; Ok(()) } -fn dist_client(nightly: bool) -> Result<()> { +fn dist_client(version: &str, release_tag: &str) -> Result<()> { let _d = pushd("./editors/code"); + let nightly = release_tag == "nightly"; - let package_json_path = PathBuf::from("./package.json"); - let mut patch = Patch::new(package_json_path.clone())?; + let mut patch = Patch::new("./package.json")?; - let date = run!("date --utc +%Y%m%d")?; - let version_suffix = if nightly { "-nightly" } else { "" }; - - patch.replace( - r#""version": "0.2.20200309-nightly""#, - &format!(r#""version": "0.1.{}{}""#, date, version_suffix), - ); + patch + .replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version)) + .replace(r#""releaseTag": "nightly""#, &format!(r#""releaseTag": "{}""#, release_tag)); if nightly { patch.replace( @@ -86,7 +82,8 @@ struct Patch { } impl Patch { - fn new(path: PathBuf) -> Result { + fn new(path: impl Into) -> Result { + let path = path.into(); let contents = fs2::read_to_string(&path)?; Ok(Patch { path, original_contents: contents.clone(), contents }) } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7c8ea9001..aafa73610 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -103,9 +103,10 @@ FLAGS: run_release(dry_run) } "dist" => { - let nightly = args.contains("--nightly"); + let version: String = args.value_from_str("--version")?; + let release_tag: String = args.value_from_str("--tag")?; args.finish()?; - run_dist(nightly) + run_dist(&version, &release_tag) } _ => { eprintln!( -- cgit v1.2.3