-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ink0rr/dev
rgl v0.4.0
- Loading branch information
Showing
19 changed files
with
330 additions
and
209 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,14 @@ | ||
use super::{rimraf, Config}; | ||
use crate::info; | ||
use anyhow::{Context, Result}; | ||
|
||
pub fn clean() -> Result<()> { | ||
// Make sure it's a regolith project | ||
let _ = Config::load().context("Not a Regolith project")?; | ||
info!("Cleaning .regolith folder..."); | ||
rimraf(".regolith")?; | ||
info!("Cleaning build files..."); | ||
rimraf("build")?; | ||
info!("Completed!"); | ||
Ok(()) | ||
} |
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
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 |
---|---|---|
@@ -1,93 +1,89 @@ | ||
use super::{FilterDeno, FilterGo, FilterNode, FilterPython, FilterRemote}; | ||
use anyhow::{bail, Context, Result}; | ||
use super::{FilterDeno, FilterExe, FilterGo, FilterNode, FilterPython, RemoteFilter}; | ||
use anyhow::{anyhow, Result}; | ||
use dunce::canonicalize; | ||
use enum_dispatch::enum_dispatch; | ||
use serde::{Deserialize, Serialize}; | ||
use std::path::{Path, PathBuf}; | ||
|
||
pub trait Filter { | ||
fn run(&self, temp: &Path, run_args: &[String]) -> Result<()>; | ||
fn install_dependencies(&self) -> Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
use serde_json::Value; | ||
use std::{ | ||
env, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
#[enum_dispatch] | ||
pub enum FilterDefinition { | ||
Local(LocalFilterDefinition), | ||
Remote(RemoteFilterDefinition), | ||
Local(LocalFilter), | ||
Remote(RemoteFilter), | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct LocalFilterDefinition { | ||
pub run_with: String, | ||
pub script: String, | ||
impl FilterDefinition { | ||
pub fn from_value(value: Value) -> Result<Self> { | ||
let filter = match value["runWith"] { | ||
Value::String(_) => { | ||
let filter = serde_json::from_value::<LocalFilter>(value)?; | ||
FilterDefinition::Local(filter) | ||
} | ||
_ => { | ||
let filter = serde_json::from_value::<RemoteFilter>(value)?; | ||
FilterDefinition::Remote(filter) | ||
} | ||
}; | ||
Ok(filter) | ||
} | ||
|
||
pub fn is_remote(&self) -> bool { | ||
matches!(self, FilterDefinition::Remote(_)) | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct RemoteFilterDefinition { | ||
pub url: String, | ||
pub version: String, | ||
#[serde(rename_all = "camelCase", tag = "runWith")] | ||
#[enum_dispatch] | ||
pub enum LocalFilter { | ||
Deno(FilterDeno), | ||
Exe(FilterExe), | ||
Go(FilterGo), | ||
Nodejs(FilterNode), | ||
Python(FilterPython), | ||
} | ||
|
||
pub struct FilterArgs { | ||
pub struct FilterContext { | ||
pub name: String, | ||
pub script: PathBuf, | ||
pub filter_dir: PathBuf, | ||
pub dir: PathBuf, | ||
pub is_remote: bool, | ||
} | ||
|
||
impl FilterDefinition { | ||
pub fn to_filter(&self, name: &str, filter_dir: Option<PathBuf>) -> Result<Box<dyn Filter>> { | ||
let inner = || { | ||
let filter: Box<dyn Filter> = match self { | ||
FilterDefinition::Local(def) => { | ||
let args = FilterArgs::new(name, filter_dir, def)?; | ||
match def.run_with.as_str() { | ||
"deno" => Box::new(FilterDeno(args)), | ||
"go" => Box::new(FilterGo(args)), | ||
"nodejs" => Box::new(FilterNode(args)), | ||
"python" => Box::new(FilterPython(args)), | ||
filter_type => bail!("Filter type <b>{filter_type}</> not supported"), | ||
} | ||
} | ||
FilterDefinition::Remote(def) => { | ||
let filter_remote = FilterRemote::new(name)?; | ||
let is_latest = matches!(def.version.as_str(), "HEAD" | "latest"); | ||
if !is_latest && def.version != filter_remote.version { | ||
bail!( | ||
"Filter version mismatch\n\ | ||
<yellow> >></> Filter: {}\n\ | ||
<yellow> >></> Installed version: {}\n\ | ||
<yellow> >></> Required version: {}", | ||
name, | ||
filter_remote.version, | ||
def.version | ||
); | ||
} | ||
Box::new(filter_remote) | ||
} | ||
}; | ||
Ok(filter) | ||
}; | ||
inner().context(format!("Invalid filter definition for <b>{name}</>")) | ||
} | ||
} | ||
|
||
impl FilterArgs { | ||
fn new(name: &str, filter_dir: Option<PathBuf>, def: &LocalFilterDefinition) -> Result<Self> { | ||
let script = | ||
canonicalize(&def.script).context(format!("Failed to resolve path {}", def.script))?; | ||
let filter_dir = filter_dir.unwrap_or_else(|| { | ||
script | ||
.parent() | ||
.map(|path| path.to_path_buf()) | ||
.unwrap_or_else(|| PathBuf::from(".")) | ||
}); | ||
impl FilterContext { | ||
pub fn new(name: &str, is_remote: bool) -> Result<Self> { | ||
Ok(Self { | ||
name: name.to_owned(), | ||
script, | ||
filter_dir, | ||
dir: match is_remote { | ||
true => canonicalize(RemoteFilter::cache_dir(name)).map_err(|_| { | ||
anyhow!("Filter <b>{name}</> not installed, run \"rgl install\" to install it") | ||
})?, | ||
false => env::current_dir()?, | ||
}, | ||
is_remote, | ||
}) | ||
} | ||
|
||
pub fn filter_dir(&self, path: &str) -> Result<PathBuf> { | ||
if self.is_remote { | ||
Ok(self.dir.to_owned()) | ||
} else { | ||
let mut dir = PathBuf::from(path); | ||
dir.pop(); | ||
Ok(dir) | ||
} | ||
} | ||
} | ||
|
||
#[enum_dispatch(FilterDefinition, LocalFilter)] | ||
pub trait Filter { | ||
fn run(&self, context: &FilterContext, temp: &Path, run_args: &[String]) -> Result<()>; | ||
#[allow(unused_variables)] | ||
fn install_dependencies(&self, context: &FilterContext) -> Result<()> { | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.