-
-
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 #5 from shahen94/feature/linker
Linker: Combining all pipes into one result
- Loading branch information
Showing
21 changed files
with
284 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
craft.lock | ||
craft.lock | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"express": "^4.18.2", | ||
"mongoose": "^5.9.7", | ||
|
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,2 +1,3 @@ | ||
pub const CRAFT_VERBOSE_LOGGING: &str = "CRAFT_VERBOSE"; | ||
#[allow(dead_code)] | ||
pub const LOCK_FILE_NAME: &str = "craft.lock"; |
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,44 @@ | ||
use fs_extra::dir::CopyOptions; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
pub fn copy_dir(from: &Path, to: &Path) -> Result<(), Box<dyn std::error::Error>> { | ||
if to.exists() { | ||
fs::remove_dir_all(to).unwrap(); | ||
} | ||
|
||
fs::create_dir_all(to).unwrap(); | ||
|
||
let options = CopyOptions::new().overwrite(true); | ||
|
||
copy_recursive(from, to, &options) | ||
} | ||
|
||
fn copy_recursive( | ||
from: &std::path::Path, | ||
to: &std::path::Path, | ||
options: &CopyOptions, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
let from_meta = fs::metadata(from)?; | ||
|
||
if from_meta.is_dir() { | ||
let dir_entries = fs::read_dir(from)?; | ||
|
||
for entry in dir_entries { | ||
let entry = entry?; | ||
let entry_path = entry.path(); | ||
let entry_name = entry.file_name().into_string().unwrap(); // Convert OsString to String | ||
|
||
let dest_path = to.join(&entry_name); | ||
|
||
if entry_path.is_dir() { | ||
fs::create_dir_all(&dest_path)?; | ||
copy_recursive(&entry_path, &dest_path, options)?; | ||
} else { | ||
fs_extra::copy_items(&[entry_path], to, options)?; | ||
} | ||
} | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod copy; | ||
|
||
pub use copy::copy_dir; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,27 @@ use std::{collections::HashMap, env, path::PathBuf}; | |
|
||
use crate::{cache::TMP_CACHE_FOLDER, contracts::PipeArtifact, package::NpmPackage}; | ||
|
||
// ───────────────────────────────────────────────────────────────────────────── | ||
|
||
pub type ExtractArtifactsMap = HashMap<String, ExtractArtifactItem>; | ||
|
||
// ─── ExtractArtifacts ───────────────────────────────────────────────────────────── | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ExtractArtifacts { | ||
#[allow(dead_code)] | ||
tmp_cache_folder: PathBuf, | ||
tmp_cache: HashMap<String, ExtractArtifactItem>, | ||
tmp_cache: ExtractArtifactsMap, | ||
} | ||
|
||
// ─────────────────────────────────────────────────────────────────────────────── | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ExtractArtifactItem { | ||
#[allow(dead_code)] | ||
package: NpmPackage, | ||
pub package: NpmPackage, | ||
#[allow(dead_code)] | ||
unzip_at: PathBuf, | ||
pub unzip_at: PathBuf, | ||
} | ||
|
||
// ─────────────────────────────────────────────────────────────────────────────── | ||
|
@@ -55,7 +59,7 @@ impl ExtractArtifacts { | |
} | ||
|
||
pub fn add(&mut self, package: NpmPackage, unzip_at: PathBuf) { | ||
let name = package.name.clone(); | ||
let name = format!("{}@{}", package.name.clone(), package.version.clone()); | ||
let item = ExtractArtifactItem::new(package.clone(), unzip_at); | ||
|
||
self.tmp_cache.insert(name, item); | ||
|
@@ -69,9 +73,9 @@ impl ExtractArtifacts { | |
|
||
// ─────────────────────────────────────────────────────────────────────────────── | ||
|
||
impl PipeArtifact<Vec<ExtractArtifactItem>> for ExtractArtifacts { | ||
fn get_artifacts(&self) -> Vec<ExtractArtifactItem> { | ||
self.tmp_cache.values().cloned().collect() | ||
impl PipeArtifact<ExtractArtifactsMap> for ExtractArtifacts { | ||
fn get_artifacts(&self) -> ExtractArtifactsMap { | ||
self.tmp_cache.clone() | ||
} | ||
} | ||
|
||
|
@@ -101,7 +105,11 @@ mod tests { | |
extract_artifacts.add(package.clone(), PathBuf::from("/tmp/package")); | ||
|
||
assert_eq!( | ||
extract_artifacts.get("package").unwrap().package.version, | ||
extract_artifacts | ||
.get("[email protected]") | ||
.unwrap() | ||
.package | ||
.version, | ||
"1.0.0" | ||
); | ||
} | ||
|
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,17 @@ | ||
use std::path::PathBuf; | ||
|
||
// ───────────────────────────────────────────────────────────────────────────── | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct LinkArtifactItem { | ||
pub to: PathBuf, | ||
pub from: PathBuf, | ||
} | ||
|
||
// ───────────────────────────────────────────────────────────────────────────── | ||
|
||
impl LinkArtifactItem { | ||
pub fn new(from: PathBuf, to: PathBuf) -> Self { | ||
Self { from, to } | ||
} | ||
} |
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,7 +1,9 @@ | ||
mod download_artifacts; | ||
mod extract_artifacts; | ||
mod linker_artifacts; | ||
mod resolve_artifacts; | ||
|
||
pub use download_artifacts::{DownloadArtifacts, StoredArtifact}; | ||
pub use extract_artifacts::ExtractArtifacts; | ||
pub use resolve_artifacts::ResolveArtifacts; | ||
pub use extract_artifacts::{ExtractArtifacts, ExtractArtifactsMap}; | ||
pub use linker_artifacts::LinkArtifactItem; | ||
pub use resolve_artifacts::{ResolveArtifacts, ResolvedItem}; |
Oops, something went wrong.