1#![warn(clippy::pedantic)]
2#![allow(
3 clippy::format_collect,
4 clippy::similar_names,
5 clippy::module_name_repetitions,
6 clippy::single_match_else,
7 clippy::items_after_statements
8)]
9
10use self::commands::Command;
11use anyhow::{Result, bail};
12use clap::Parser;
13use commands::{
14 build::BuildCommand, clean::CleanCommand, doc::DocCommand, fix::FixCommand, fmt::FmtCommand,
15 init::InitCommand, new::NewCommand, test::TestCommand,
16};
17use workspace::{Workspace, package::PackageName};
18
19mod commands;
20mod logger;
21mod utils;
22mod workspace;
23
24#[derive(clap::Parser, Default)]
25pub struct CommonArgs {
26 #[clap(short, long)]
28 package: Option<PackageName>,
29
30 #[clap(long)]
32 incremental: bool,
33
34 #[clap(long)]
36 no_fullscreen: bool,
37}
38
39#[derive(clap::Parser)]
40#[command(name = "depot", author, version, about, long_about = None)]
41struct Args {
42 #[command(subcommand)]
43 command: Command,
44
45 #[command(flatten)]
46 common: CommonArgs,
47}
48
49#[allow(clippy::missing_errors_doc)]
50pub async fn run() -> Result<()> {
51 let Args { command, common } = Args::parse();
52
53 if utils::find_node().is_none() {
54 bail!(
55 "Failed to find `node` installed on your path. Depot requires NodeJS to be installed. See: https://nodejs.org/en/download/package-manager"
56 );
57 }
58
59 if utils::find_pnpm(None).is_none() {
60 bail!(
61 "Failed to find `pnpm` installed on your path. Depot requires pnpm to be installed. See: https://pnpm.io/installation"
62 )
63 }
64
65 let command = match command {
66 Command::New(args) => return NewCommand::new(args).await.run(),
67 command => command,
68 };
69
70 let ws = Workspace::load(None, common).await?;
71
72 let command = match command {
74 Command::Init(args) => InitCommand::new(args).kind(),
75 Command::Build(args) => BuildCommand::new(args).kind(),
76 Command::Test(args) => TestCommand::new(args).kind(),
77 Command::Fmt(args) => FmtCommand::new(args).kind(),
78 Command::Clean(args) => CleanCommand::new(args).kind(),
79 Command::Doc(args) => DocCommand::new(args).kind(),
80 Command::Fix(args) => FixCommand::new(args).kind(),
81 Command::New(..) => unreachable!(),
82 };
83
84 ws.run(command).await?;
85
86 Ok(())
87}