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::{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  /// 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!(
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  // TODO: merge all tasks into a single task graph like Cargo
73  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}