depot_js/
lib.rs

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::{bail, Result};
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::{package::PackageName, Workspace};
18
19mod commands;
20mod logger;
21mod utils;
22mod workspace;
23
24#[derive(clap::Parser, Default)]
25pub struct CommonArgs {
26  /// Only run the command for a given package and its dependencies
27  #[clap(short, long)]
28  package: Option<PackageName>,
29
30  /// Enable incremental compilation
31  #[clap(long)]
32  incremental: bool,
33
34  /// Disable fullscreen UI
35  #[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!("Failed to find `node` installed on your path. Depot requires NodeJS to be installed. See: https://nodejs.org/en/download/package-manager");
55  }
56
57  if utils::find_pnpm(None).is_none() {
58    bail!("Failed to find `pnpm` installed on your path. Depot requires pnpm to be installed. See: https://pnpm.io/installation")
59  }
60
61  let command = match command {
62    Command::New(args) => return NewCommand::new(args).await.run(),
63    command => command,
64  };
65
66  let ws = Workspace::load(None, common).await?;
67
68  // TODO: merge all tasks into a single task graph like Cargo
69  let command = match command {
70    Command::Init(args) => InitCommand::new(args).kind(),
71    Command::Build(args) => BuildCommand::new(args).kind(),
72    Command::Test(args) => TestCommand::new(args).kind(),
73    Command::Fmt(args) => FmtCommand::new(args).kind(),
74    Command::Clean(args) => CleanCommand::new(args).kind(),
75    Command::Doc(args) => DocCommand::new(args).kind(),
76    Command::Fix(args) => FixCommand::new(args).kind(),
77    Command::New(..) => unreachable!(),
78  };
79
80  ws.run(command).await?;
81
82  Ok(())
83}