posthog_cli/sourcemaps/
mod.rs

1use clap::Subcommand;
2use core::str;
3use std::path::PathBuf;
4
5pub mod constant;
6pub mod inject;
7pub mod source_pair;
8pub mod upload;
9
10use crate::sourcemaps::inject::InjectArgs;
11use crate::sourcemaps::upload::UploadArgs;
12
13#[derive(clap::Args)]
14pub struct ProcessArgs {
15    /// The directory containing the bundled chunks
16    #[arg(short, long)]
17    pub directory: PathBuf,
18
19    /// One or more directory glob patterns to ignore
20    #[arg(short, long)]
21    pub ignore: Vec<String>,
22
23    /// The project name associated with the uploaded chunks. Required to have the uploaded chunks associated with
24    /// a specific release. We will try to auto-derive this from git information if not provided. Strongly recommended
25    /// to be set explicitly during release CD workflows.
26    #[arg(long)]
27    pub project: Option<String>,
28
29    /// The version of the project - this can be a version number, semantic version, or a git commit hash. Required
30    /// to have the uploaded chunks associated with a specific release. Overrides release information set during
31    /// injection. Strongly prefer setting release information during injection.
32    #[arg(long)]
33    pub version: Option<String>,
34
35    /// Whether to delete the source map files after uploading them
36    #[arg(long, default_value = "false")]
37    pub delete_after: bool,
38
39    /// Whether to skip SSL verification when uploading chunks - only use when using self-signed certificates for
40    /// self-deployed instances
41    #[arg(long, default_value = "false")]
42    pub skip_ssl_verification: bool,
43
44    /// The maximum number of chunks to upload in a single batch
45    #[arg(long, default_value = "50")]
46    pub batch_size: usize,
47}
48
49#[derive(Subcommand)]
50pub enum SourcemapCommand {
51    /// Inject each bundled chunk with a posthog chunk ID
52    Inject(InjectArgs),
53    /// Upload the bundled chunks to PostHog
54    Upload(UploadArgs),
55    /// Run inject and upload in one command
56    Process(ProcessArgs),
57}
58
59impl From<ProcessArgs> for (InjectArgs, UploadArgs) {
60    fn from(args: ProcessArgs) -> Self {
61        let inject_args = InjectArgs {
62            directory: args.directory.clone(),
63            ignore: args.ignore.clone(),
64            project: args.project,
65            version: args.version,
66        };
67
68        let upload_args = UploadArgs {
69            directory: args.directory,
70            ignore: args.ignore,
71            delete_after: args.delete_after,
72            skip_ssl_verification: args.skip_ssl_verification,
73            batch_size: args.batch_size,
74        };
75
76        (inject_args, upload_args)
77    }
78}