Skip to content

Commit

Permalink
output_dir arg in package xtask + delete vsix after install xtask
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Jan 27, 2024
1 parent 3d1275b commit 39c378b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 3 additions & 1 deletion xtask/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub enum Commands {
/// Copy release build of the LSP server to the VSCode client
CopyLspRelease,
/// Build and package VSCode extension into a .vsix file
Package,
Package {
output_dir: Option<String>
},
/// Build, package and install the VSCode extension
Install
}
4 changes: 4 additions & 0 deletions xtask/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ pub fn install() -> anyhow::Result<()> {
if !installed_extensions.contains("witcherscript-ide") {
bail!("Could not install the Visual Studio Code extension.");
}

// Remove the vsix file
// If you want to keep it use xtask package instead
sh.remove_path(VSIX_NAME)?;

Ok(())
}
21 changes: 19 additions & 2 deletions xtask/src/commands/package.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::PathBuf;
use anyhow::Context;
use xshell::{Shell, cmd};

Expand All @@ -7,9 +8,16 @@ const LSP_DST: &str = "./editors/vscode/server/bin";
const EXT_DIR: &str = "./editors/vscode";
const VSIX_NAME: &str = "witcherscript-ide.vsix";

pub fn package() -> anyhow::Result<()> {
pub fn package(output_dir: Option<String>) -> anyhow::Result<()> {
let sh = Shell::new()?;

// normalize the output path so it stays valid when we change cwd
let output_dir = if let Some(output_dir) = output_dir {
Some(PathBuf::from(&output_dir).canonicalize()?)
} else {
None
};

println!("Building LSP release...");
cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?;

Expand Down Expand Up @@ -38,8 +46,17 @@ pub fn package() -> anyhow::Result<()> {
}

let version = env!("CARGO_PKG_VERSION");
sh.copy_file(VSIX_NAME, format!("witcherscript-ide-{version}.vsix"))?;
let vsix_file = format!("witcherscript-ide-{version}.vsix");
let vsix_dst = if let Some(output_dir) = output_dir {
output_dir.join(vsix_file)
} else {
PathBuf::from(&vsix_file).canonicalize()?
};

sh.copy_file(VSIX_NAME, vsix_dst.as_os_str())?;
println!("Copied vsix package into {}", vsix_dst.display());

// remove the original vsix file
sh.remove_path(VSIX_NAME)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() -> anyhow::Result<()> {
match cli.command {
cli::Commands::CopyLsp => commands::copy_lsp(),
cli::Commands::CopyLspRelease => commands::copy_lsp_release(),
cli::Commands::Package => commands::package(),
cli::Commands::Package { output_dir } => commands::package(output_dir),
cli::Commands::Install => commands::install()
}
}

0 comments on commit 39c378b

Please sign in to comment.