Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
WIP: coalesce bundler TargetType under javascript, using config to di…
Browse files Browse the repository at this point in the history
…stinguish
  • Loading branch information
xortive committed Dec 11, 2020
1 parent dc367dd commit cc82568
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 52 deletions.
35 changes: 16 additions & 19 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ use std::process::Command;
pub fn build_target(target: &Target) -> Result<String, failure::Error> {
let target_type = &target.target_type;
match target_type {
TargetType::JavaScript => {
let msg = "JavaScript project found. Skipping unnecessary build!".to_string();
Ok(msg)
}
TargetType::JavaScript => match &target.bundle_config {
None => {
let msg = "JavaScript project found. Skipping unnecessary build!".to_string();
Ok(msg)
}
Some(config) => {
if config.build_command().spawn()?.wait()?.success() {
Ok(String::from("Build completed successfully!"))
} else {
Err(failure::format_err!(
"Command `{:?}` exited with non-zero exit code!",
config.build_command()
))
}
}
},
TargetType::Rust => {
let _ = which::which("rustc").map_err(|e| {
failure::format_err!(
Expand Down Expand Up @@ -45,21 +57,6 @@ pub fn build_target(target: &Target) -> Result<String, failure::Error> {
}
Err(e) => Err(e),
},

TargetType::Bundler => match &target.bundle_config {
None => Err(failure::err_msg("Please specify bundler options!")),
Some(config) => {
if config.build_command().spawn()?.wait()?.success() {
let input = &config.output_dir()?;
Ok(String::from("ok"))
} else {
Err(failure::format_err!(
"Command `{:?}` exited with non-zero exit code!",
config.build_command()
))
}
}
},
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/settings/toml/target_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub enum TargetType {
JavaScript,
Rust,
Webpack,
Bundler,
}

impl Default for TargetType {
Expand All @@ -24,7 +23,6 @@ impl fmt::Display for TargetType {
TargetType::JavaScript => "js",
TargetType::Rust => "rust",
TargetType::Webpack => "webpack",
TargetType::Bundler => "bundler",
};
write!(f, "{}", printable)
}
Expand All @@ -38,7 +36,6 @@ impl FromStr for TargetType {
"javascript" => Ok(TargetType::JavaScript),
"rust" => Ok(TargetType::Rust),
"webpack" => Ok(TargetType::Webpack),
"bundler" => Ok(TargetType::Bundler),
_ => failure::bail!("{} is not a valid wrangler build type!", s),
}
}
Expand Down
1 change: 0 additions & 1 deletion src/upload/form/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ pub fn build(

build_form(&assets, session_config)
}
TargetType::Bundler => todo!(),
}
}

Expand Down
59 changes: 30 additions & 29 deletions src/watch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ignore::overrides::OverrideBuilder;
use ignore::WalkBuilder;
pub use watcher::wait_for_changes;

use crate::build::{build_target, command};
use crate::build::command;
use crate::settings::toml::{Target, TargetType};
use crate::terminal::message::{Message, StdOut};
use crate::wranglerjs;
Expand Down Expand Up @@ -103,34 +103,35 @@ pub fn watch_and_build(
}
TargetType::Webpack => {
wranglerjs::run_build_and_watch(target, tx)?;
}
TargetType::Bundler => {
let (tx, rx) = mpsc::channel::<notify::DebouncedEvent>();
let mut watcher = notify::watcher(tx, COOLDOWN_PERIOD)?;

watcher.watch(
&target.bundle_config.clone().unwrap().src_dir()?,
notify::RecursiveMode::Recursive,
)?;

let mut is_first = true;

loop {
match rx.recv() {
Ok(_) => {
if is_first {
is_first = false;
StdOut::info("Ignoring stale first change");
continue;
} else {
let output = build_target(target)?;
StdOut::success(&format!("{}\nUploading...", output));
}
}
Err(_) => StdOut::user_error("Something went wrong while watching."),
}
}
}
} /*
TargetType::Bundler => {
let (tx, rx) = mpsc::channel::<notify::DebouncedEvent>();
let mut watcher = notify::watcher(tx, COOLDOWN_PERIOD)?;
watcher.watch(
&target.bundle_config.clone().unwrap().src_dir()?,
notify::RecursiveMode::Recursive,
)?;
let mut is_first = true;
loop {
match rx.recv() {
Ok(_) => {
if is_first {
is_first = false;
StdOut::info("Ignoring stale first change");
continue;
} else {
let output = build_target(target)?;
StdOut::success(&format!("{}\nUploading...", output));
}
}
Err(_) => StdOut::user_error("Something went wrong while watching."),
}
}
}
*/
}

Ok(())
Expand Down

0 comments on commit cc82568

Please sign in to comment.