Skip to main content

infinity_build_js/
lib.rs

1pub mod bundler;
2pub mod config;
3mod package;
4mod templates;
5
6pub use bundler::JsBundler;
7pub use config::{Instrument, JsBuildConfig, ModuleAlias, SimulatorPackage, SimulatorPackageKind};
8
9use infinity_build_core::{BuildResult, Builder, SimpleArtifact};
10use std::path::Path;
11
12/// Build every instrument in `config`, applying an optional name
13/// filter (regex). This is the "I just want to build everything"
14/// helper; if you need finer control (per-instrument progress,
15/// per-instrument failure handling), construct [`JsBundler`] yourself
16/// and drive each [`Instrument`] through it.
17///
18/// Returns one [`SimpleArtifact`] per *successfully built* instrument
19/// in the order they appear in the config.
20pub fn build_all(
21    config: &JsBuildConfig,
22    project_root: &Path,
23    filter: Option<&regex::Regex>,
24    options: &bundler::BundleOptions,
25) -> BuildResult<Vec<SimpleArtifact>> {
26    let bundler = JsBundler::new(project_root, options.clone());
27    let mut out = Vec::new();
28    for instrument in &config.instruments {
29        if let Some(re) = filter {
30            if !re.is_match(&instrument.name) {
31                continue;
32            }
33        }
34        let input = bundler::JsBuildInput {
35            instrument: instrument.clone(),
36            package: config.package.clone(),
37        };
38        let artifact = bundler.build(&input)?;
39        out.push(artifact.into());
40    }
41    Ok(out)
42}