posthog_cli/sourcemaps/plain/
mod.rs

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