-
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
1 parent
ba3c455
commit b80a72a
Showing
13 changed files
with
96 additions
and
123 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
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
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
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,13 @@ | ||
use colored::Colorize; | ||
pub fn load_env(data: Option<bool>) { | ||
if let Some(data) = data { | ||
if data { | ||
if dotenv::dotenv().is_err() { | ||
println!( | ||
"{}", | ||
format!("no .env file found continuing without loading dotenv").dimmed(), | ||
); | ||
} | ||
} | ||
} | ||
} |
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,2 @@ | ||
pub mod load_env; | ||
pub mod run_utils; |
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,55 @@ | ||
use crate::{CONFIG, DOTDIPLO}; | ||
use anyhow::Result; | ||
use serde_json::json; | ||
use std::{ | ||
collections::HashMap, | ||
fs::{create_dir_all, write}, | ||
process::Command, | ||
}; | ||
|
||
pub fn create_deps(dependencies: &HashMap<String, String>) { | ||
create_dir_all(&*DOTDIPLO).unwrap(); | ||
let mut data: Vec<String> = vec![]; | ||
for (_, value) in dependencies.iter() { | ||
data.push(format!("export * from \"{}\"", value)) | ||
} | ||
write(format!("{}/deps.ts", &*DOTDIPLO), data.join("\n")).unwrap() | ||
} | ||
|
||
pub fn ensure_dependencies() -> Result<()> { | ||
if let Some(dependencies) = &CONFIG.dependencies { | ||
create_deps(dependencies); | ||
if let Some(import_map) = CONFIG.import_map { | ||
if import_map { | ||
let imports = json!({ "imports": dependencies }); | ||
write( | ||
format!("{}/import_map.json", &*DOTDIPLO), | ||
serde_json::to_string(&imports)?, | ||
)?; | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn append_extra_args(input: String, extra_args: Vec<String>) -> String { | ||
let mut data = "deno run ".to_owned(); | ||
//Allow inserting the import-map and future things | ||
data.push_str(&extra_args.join(" ")); | ||
input.replace("deno run", &data) | ||
} | ||
|
||
pub fn run_script(command: String) -> Result<()> { | ||
let mut parts = command.trim().split_whitespace(); | ||
|
||
let command = parts.next().unwrap(); | ||
|
||
let args = parts; | ||
|
||
let mut out = Command::new(command).args(args).spawn()?; | ||
|
||
if let Err(error) = out.wait() { | ||
println!("{}", error); | ||
} | ||
Ok(()) | ||
} |