posthog_cli/commands/sourcemap/
inject.rs1use anyhow::{anyhow, bail, Ok, Result};
2use std::path::{Path, PathBuf};
3use tracing::info;
4use uuid;
5
6use crate::utils::sourcemaps::read_pairs;
7
8pub fn inject(directory: &Path, _output: &Option<PathBuf>) -> Result<()> {
9 let directory = directory.canonicalize().map_err(|e| {
10 anyhow!(
11 "Directory '{}' not found or inaccessible: {}",
12 directory.display(),
13 e
14 )
15 })?;
16 info!("Processing directory: {}", directory.display());
17 let mut pairs = read_pairs(&directory)?;
18 if pairs.is_empty() {
19 bail!("No source files found");
20 }
21 info!("Found {} pairs", pairs.len());
22 for pair in &mut pairs {
23 let chunk_id = uuid::Uuid::now_v7().to_string();
24 pair.add_chunk_id(chunk_id)?;
25 }
26 for pair in &pairs {
28 pair.write()?;
29 }
30 info!("Finished processing directory");
31 Ok(())
32}