Skip to content

Commit

Permalink
feat(cli): added support for watching snoop and build commands
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jan 9, 2023
1 parent d2f7fa3 commit c9808fb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
30 changes: 27 additions & 3 deletions packages/perseus-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use command_group::stdlib::CommandGroup;
use directories::ProjectDirs;
use fmterr::fmt_err;
use notify::{recommended_watcher, RecursiveMode, Watcher};
use perseus_cli::parse::{CheckOpts, ExportOpts, ServeOpts, SnoopSubcommand};
use perseus_cli::parse::{
BuildOpts, CheckOpts, ExportOpts, ServeOpts, SnoopServeOpts, SnoopSubcommand,
};
use perseus_cli::{
build, check_env, delete_artifacts, deploy, export, init, new,
parse::{Opts, Subcommand},
Expand Down Expand Up @@ -117,11 +119,29 @@ async fn core(dir: PathBuf) -> Result<i32, Error> {
custom_watch,
..
})
| Subcommand::Build(BuildOpts {
watch,
custom_watch,
..
})
| Subcommand::Serve(ServeOpts {
watch,
custom_watch,
..
})
| Subcommand::Snoop(SnoopSubcommand::Build {
watch,
custom_watch,
})
| Subcommand::Snoop(SnoopSubcommand::WasmBuild {
watch,
custom_watch,
})
| Subcommand::Snoop(SnoopSubcommand::Serve(SnoopServeOpts {
watch,
custom_watch,
..
}))
| Subcommand::Check(CheckOpts {
watch,
custom_watch,
Expand Down Expand Up @@ -355,9 +375,13 @@ async fn core_watch(dir: PathBuf, opts: Opts) -> Result<i32, Error> {
create_dist(&dir)?;
let tools = Tools::new(&dir, &opts).await?;
match snoop_subcmd {
SnoopSubcommand::Build => snoop_build(dir, &tools, &opts)?,
SnoopSubcommand::WasmBuild => snoop_wasm_build(dir, &tools, &opts)?,
SnoopSubcommand::Build { .. } => snoop_build(dir, &tools, &opts)?,
SnoopSubcommand::WasmBuild { .. } => snoop_wasm_build(dir, &tools, &opts)?,
SnoopSubcommand::Serve(ref snoop_serve_opts) => {
// Warn the user about the perils of watching `snoop serve`
if snoop_serve_opts.watch {
eprintln!("[WARNING]: Watching `snoop serve` may not be a good idea, because it requires you to have run `perseus build` first. It's not recommended to do this unless you have `perseus build` on a separate watch loop.");
}
snoop_server(dir, snoop_serve_opts, &tools, &opts)?
}
}
Expand Down
38 changes: 36 additions & 2 deletions packages/perseus-cli/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ pub struct BuildOpts {
/// Build for production
#[clap(long)]
pub release: bool,
/// Watch the files in your working directory for changes (excluding
/// `target/` and `dist/`)
#[clap(short, long)]
pub watch: bool,
/// Marks a specific file/directory to be watched (directories will be
/// recursively watched)
#[clap(long)]
pub custom_watch: Vec<String>,
}
/// Exports your app to purely static files
#[derive(Parser, Clone)]
Expand Down Expand Up @@ -226,9 +234,27 @@ pub struct InitOpts {
pub enum SnoopSubcommand {
/// Snoops on the static generation process (this will let you see `dbg!`
/// calls and the like)
Build,
Build {
/// Watch the files in your working directory for changes (excluding
/// `target/` and `dist/`)
#[clap(short, long)]
watch: bool,
/// Marks a specific file/directory to be watched (directories will be
/// recursively watched)
#[clap(long)]
custom_watch: Vec<String>,
},
/// Snoops on the Wasm building process (mostly for debugging errors)
WasmBuild,
WasmBuild {
/// Watch the files in your working directory for changes (excluding
/// `target/` and `dist/`)
#[clap(short, long)]
watch: bool,
/// Marks a specific file/directory to be watched (directories will be
/// recursively watched)
#[clap(long)]
custom_watch: Vec<String>,
},
/// Snoops on the server process (run `perseus build` before this)
Serve(SnoopServeOpts),
}
Expand All @@ -241,6 +267,14 @@ pub struct SnoopServeOpts {
/// The port to host your exported app on
#[clap(long, default_value = "8080")]
pub port: u16,
/// Watch the files in your working directory for changes (excluding
/// `target/` and `dist/`)
#[clap(short, long)]
pub watch: bool,
/// Marks a specific file/directory to be watched (directories will be
/// recursively watched)
#[clap(long)]
pub custom_watch: Vec<String>,
}

#[derive(Parser, Clone)]
Expand Down

0 comments on commit c9808fb

Please sign in to comment.