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