-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use super::{AnalyzeResult, App}; | ||
use crate::config::{AppName, Version}; | ||
use crate::hosting::github_releases; | ||
use crate::install::{self, Method}; | ||
use crate::platform::{Cpu, Os, Platform}; | ||
use crate::prelude::*; | ||
use crate::subshell::Executable; | ||
use crate::Log; | ||
use const_format::formatcp; | ||
|
||
pub struct NodePrune {} | ||
|
||
const ORG: &str = "tj"; | ||
const REPO: &str = "node-prune"; | ||
|
||
impl App for NodePrune { | ||
fn name(&self) -> AppName { | ||
AppName::from("node-prune") | ||
} | ||
|
||
fn homepage(&self) -> &'static str { | ||
formatcp!("https://github.com/{ORG}/{REPO}") | ||
} | ||
|
||
fn latest_installable_version(&self, log: Log) -> Result<Version> { | ||
github_releases::latest(ORG, REPO, log) | ||
} | ||
|
||
fn install_methods(&self) -> Vec<install::Method> { | ||
vec![Method::DownloadExecutable(self), Method::CompileGoSource(self)] | ||
} | ||
|
||
fn installable_versions(&self, amount: usize, log: Log) -> Result<Vec<Version>> { | ||
github_releases::versions(ORG, REPO, amount, log) | ||
} | ||
|
||
fn analyze_executable(&self, executable: &Executable, log: Log) -> Result<AnalyzeResult> { | ||
let output = executable.run_output("-h", log)?; | ||
if !identify(&output) { | ||
return Ok(AnalyzeResult::NotIdentified { output }); | ||
} | ||
Ok(AnalyzeResult::IdentifiedButUnknownVersion) | ||
} | ||
} | ||
|
||
impl install::DownloadExecutable for NodePrune { | ||
fn download_url(&self, version: &Version, platform: Platform) -> String { | ||
let os = match platform.os { | ||
Os::Linux => "linux", | ||
Os::MacOS => "darwin", | ||
Os::Windows => "windows", | ||
}; | ||
let cpu = match platform.cpu { | ||
Cpu::Arm64 => "arm64", | ||
Cpu::Intel64 => "amd64", | ||
}; | ||
format!("https://github.com/{ORG}/{REPO}/releases/download/v{version}/node-prune_{version}_{os}_{cpu}.tar.gz") | ||
} | ||
} | ||
|
||
impl install::CompileGoSource for NodePrune { | ||
fn import_path(&self, version: &Version) -> String { | ||
format!("github.com/tj/node-prune@{version}") | ||
} | ||
} | ||
|
||
fn identify(output: &str) -> bool { | ||
output.contains("Glob of files that should not be pruned") | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
mod artifact_url { | ||
use crate::config::Version; | ||
use crate::install::DownloadExecutable; | ||
use crate::platform::{Cpu, Os, Platform}; | ||
|
||
#[test] | ||
fn windows_intel64() { | ||
let node_prune = super::super::NodePrune {}; | ||
let platform = Platform { | ||
os: Os::Linux, | ||
cpu: Cpu::Intel64, | ||
}; | ||
let have = node_prune.download_url(&Version::from("1.0.1"), platform); | ||
let want = "https://github.com/tj/node-prune/releases/download/v1.0.1/node-prune_1.0.1_linux_amd64.tar.gz"; | ||
assert_eq!(have, want); | ||
} | ||
} | ||
} |