aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/dist.rs41
1 files changed, 29 insertions, 12 deletions
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs
index b5dc2354f..e3dddd9b1 100644
--- a/xtask/src/dist.rs
+++ b/xtask/src/dist.rs
@@ -23,27 +23,26 @@ fn dist_client(nightly: bool) -> Result<()> {
23 let _d = pushd("./editors/code"); 23 let _d = pushd("./editors/code");
24 24
25 let package_json_path = PathBuf::from("./package.json"); 25 let package_json_path = PathBuf::from("./package.json");
26 let original_package_json = fs2::read_to_string(&package_json_path)?; 26 let mut patch = Patch::new(package_json_path.clone())?;
27 let _restore =
28 Restore { path: package_json_path.clone(), contents: original_package_json.clone() };
29 27
30 let date = run!("date --utc +%Y%m%d")?; 28 let date = run!("date --utc +%Y%m%d")?;
31 let version_suffix = if nightly { "-nightly" } else { "" }; 29 let version_suffix = if nightly { "-nightly" } else { "" };
32 30
33 let mut package_json = original_package_json.replace( 31 patch.replace(
34 r#""version": "0.2.20200309-nightly""#, 32 r#""version": "0.2.20200309-nightly""#,
35 &format!(r#""version": "0.1.{}{}""#, date, version_suffix), 33 &format!(r#""version": "0.1.{}{}""#, date, version_suffix),
36 ); 34 );
37 35
38 if nightly { 36 if nightly {
39 package_json = package_json.replace( 37 patch.replace(
40 r#""displayName": "rust-analyzer""#, 38 r#""displayName": "rust-analyzer""#,
41 r#""displayName": "rust-analyzer nightly""#, 39 r#""displayName": "rust-analyzer (nightly)""#,
42 ); 40 );
43 } else {
44 package_json = package_json.replace(r#""enableProposedApi": true,"#, r#""#);
45 } 41 }
46 fs2::write(package_json_path, package_json)?; 42 if !nightly {
43 patch.replace(r#""enableProposedApi": true,"#, r#""#);
44 }
45 patch.commit()?;
47 46
48 run!("npm ci")?; 47 run!("npm ci")?;
49 run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?; 48 run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?;
@@ -80,13 +79,31 @@ fn dist_server() -> Result<()> {
80 Ok(()) 79 Ok(())
81} 80}
82 81
83struct Restore { 82struct Patch {
84 path: PathBuf, 83 path: PathBuf,
84 original_contents: String,
85 contents: String, 85 contents: String,
86} 86}
87 87
88impl Drop for Restore { 88impl Patch {
89 fn new(path: PathBuf) -> Result<Patch> {
90 let contents = fs2::read_to_string(&path)?;
91 Ok(Patch { path, original_contents: contents.clone(), contents })
92 }
93
94 fn replace(&mut self, from: &str, to: &str) -> &mut Patch {
95 assert!(self.contents.contains(from));
96 self.contents = self.contents.replace(from, to);
97 self
98 }
99
100 fn commit(&self) -> Result<()> {
101 fs2::write(&self.path, &self.contents)
102 }
103}
104
105impl Drop for Patch {
89 fn drop(&mut self) { 106 fn drop(&mut self) {
90 fs2::write(&self.path, &self.contents).unwrap(); 107 fs2::write(&self.path, &self.original_contents).unwrap();
91 } 108 }
92} 109}