This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not sure *exactly* what this does but i basically just copied the parts i thought were relevant from the site code. We have a src dir, which is what needs to be watched, and an output dir, which is what needs to be analyzed, and a build command, which is what needs to be run when we wanna run the build.
- Loading branch information
Showing
2 changed files
with
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
const OUTPUT_DIR: &str = "dist"; | ||
const SRC_DIR: &str = "src"; | ||
|
||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct Bundle { | ||
#[serde(rename = "build-command")] | ||
build_command: Option<String>, | ||
#[serde(rename = "output-dir")] | ||
output_dir: Option<PathBuf>, | ||
#[serde(rename = "src-dir")] | ||
src_dir: Option<PathBuf>, | ||
} | ||
|
||
impl Bundle { | ||
fn dir_or_default(dir: &Option<PathBuf>, default: &str) -> PathBuf { | ||
match dir { | ||
Some(path) => path.to_owned(), | ||
None => PathBuf::from(default), | ||
} | ||
} | ||
|
||
pub fn output_dir(&self) -> Result<PathBuf, std::io::Error> { | ||
let current_dir = env::current_dir()?; | ||
let output_dir = current_dir.join(Bundle::dir_or_default(&self.output_dir, OUTPUT_DIR)); | ||
Ok(output_dir) | ||
} | ||
|
||
pub fn src_dir(&self) -> Result<PathBuf, std::io::Error> { | ||
let current_dir = env::current_dir()?; | ||
let src_dir = current_dir.join(Bundle::dir_or_default(&self.src_dir, SRC_DIR)); | ||
Ok(src_dir) | ||
} | ||
|
||
pub fn build_command(&self) -> Command { | ||
let args_string = match &self.build_command { | ||
Some(cmd) => cmd.to_owned(), | ||
None => "npm run build".to_string(), | ||
}; | ||
let args: Vec<&str> = args_string.split_whitespace().collect(); | ||
|
||
let command = if cfg!(target_os = "windows") { | ||
let mut c = Command::new("cmd"); | ||
c.arg("/C").args(args.as_slice()); | ||
c | ||
} else { | ||
let mut c = Command::new(args[0]); | ||
if args.len() > 1 { | ||
c.args(&args[1..]); | ||
} | ||
c | ||
}; | ||
|
||
command | ||
} | ||
} |
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