Skip to main content

source_map_tauri/
lib.rs

1pub mod cli;
2pub mod config;
3pub mod discovery;
4pub mod frontend;
5pub mod ids;
6pub mod linker;
7pub mod lsp;
8pub mod meili;
9pub mod model;
10pub mod output;
11pub mod projects;
12pub mod r#rust;
13pub mod scan;
14pub mod security;
15pub mod sourcemaps;
16pub mod tauri_config;
17pub mod validate;
18
19use anyhow::Result;
20use clap::Parser;
21
22use crate::cli::{Cli, Command};
23
24pub fn run() -> Result<()> {
25    let cli = Cli::parse();
26    let config = config::ResolvedConfig::from_cli(&cli)?;
27
28    match &cli.command {
29        Command::Init => config::init_project(&config),
30        Command::Doctor => {
31            let report = discovery::doctor(&config)?;
32            let mut value = serde_json::to_value(report)?;
33            if let Some(health) = meili::doctor_health(&config) {
34                value["meilisearch_health"] = health;
35            }
36            println!("{}", serde_json::to_string_pretty(&value)?);
37            Ok(())
38        }
39        Command::Scan { out } => {
40            let runtime = config.with_output_override(out.clone());
41            let bundle = scan::scan_project(&runtime)?;
42            output::write_scan_bundle(&runtime.output_dir, &bundle)?;
43            println!("{}", serde_json::to_string_pretty(&bundle.summary)?);
44            Ok(())
45        }
46        Command::Upload {
47            meili_url,
48            meili_key,
49            index,
50            input,
51            edges,
52            warnings,
53            wait,
54            batch_size,
55        } => meili::upload(
56            &config,
57            meili::UploadRequest {
58                meili_url: meili_url.as_deref(),
59                meili_key: meili_key.as_deref(),
60                index: index.as_deref(),
61                input,
62                edges: edges.as_ref().map(|path| path.as_path()),
63                warnings: warnings.as_ref().map(|path| path.as_path()),
64                wait: *wait,
65                _batch_size: *batch_size,
66            },
67        ),
68        Command::Reindex {
69            meili_url,
70            meili_key,
71            index,
72            out,
73            wait,
74            batch_size,
75        } => {
76            let runtime = config.with_output_override(out.clone());
77            let mut bundle = scan::scan_project(&runtime)?;
78            if let Some(index_name) = index.as_ref() {
79                bundle.project_info.index_uid = index_name.clone();
80            }
81            output::write_scan_bundle(&runtime.output_dir, &bundle)?;
82            meili::upload(
83                &runtime,
84                meili::UploadRequest {
85                    meili_url: meili_url.as_deref(),
86                    meili_key: meili_key.as_deref(),
87                    index: index.as_deref(),
88                    input: &runtime.output_dir.join("artifacts.ndjson"),
89                    edges: Some(&runtime.output_dir.join("edges.ndjson")),
90                    warnings: Some(&runtime.output_dir.join("warnings.ndjson")),
91                    wait: *wait,
92                    _batch_size: *batch_size,
93                },
94            )
95        }
96        Command::Search {
97            meili_url,
98            meili_key,
99            index,
100            query,
101            filter,
102            limit,
103        } => meili::search(
104            &config,
105            meili_url.as_deref(),
106            meili_key.as_deref(),
107            index.as_deref(),
108            query,
109            filter.as_deref(),
110            *limit,
111        ),
112        Command::Trace {
113            bundle,
114            line,
115            column,
116        } => {
117            let result =
118                sourcemaps::trace::trace_bundle_frame(&config.root, bundle, *line, *column)?;
119            println!("{}", serde_json::to_string_pretty(&result)?);
120            Ok(())
121        }
122        Command::Validate { input } => {
123            validate::validate_output_dir(input)?;
124            println!("validation ok");
125            Ok(())
126        }
127        Command::PrintSchema { kind } => {
128            println!(
129                "{}",
130                serde_json::to_string_pretty(&model::schema_for_kind(kind)?)?
131            );
132            Ok(())
133        }
134    }
135}