Skip to main content

cg_bundler/
lib.rs

1//! Rust Singler - A Rust code bundler for creating single-file applications
2//!
3//! This library provides functionality to bundle Rust projects into single source files,
4//! combining multiple modules and dependencies into a single, self-contained file.
5
6pub mod bundler;
7pub mod cargo_project;
8pub mod error;
9pub mod file_manager;
10pub mod transformer;
11
12// Re-export main types for convenience
13pub use bundler::Bundler;
14pub use cargo_project::CargoProject;
15pub use error::{BundlerError, Result};
16pub use transformer::{CodeTransformer, TransformConfig};
17
18use std::path::Path;
19
20/// Creates a single-source-file version of a Cargo package.
21///
22/// This is a convenience function that uses the default bundler configuration.
23/// For more control over the bundling process, use `Bundler::new()` directly.
24///
25/// # Arguments
26///
27/// * `package_path` - Path to the Cargo project directory
28///
29/// # Returns
30///
31/// A string containing the bundled source code
32///
33/// # Errors
34///
35/// Returns a `BundlerError` if the project cannot be bundled due to:
36/// - Invalid project structure
37/// - Missing files
38/// - Parsing errors
39/// - IO errors
40///
41/// # Example
42///
43/// ```rust,no_run
44/// use cg_bundler::bundle;
45///
46/// let bundled_code = bundle("./my_project").unwrap();
47/// println!("{}", bundled_code);
48/// ```
49pub fn bundle<P: AsRef<Path>>(package_path: P) -> Result<String> {
50    let bundler = Bundler::new();
51    bundler.bundle(package_path)
52}