MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / run

Function run

cli/src/build.rs:34–85  ·  view source on GitHub ↗
(manifest_path: &Path, out_dir: PathBuf)

Source from the content-addressed store, hash-verified

32const INDEX_HTML: &str = include_str!("templates/dist.html");
33
34pub fn run(manifest_path: &Path, out_dir: PathBuf) -> Result<()> {
35 let t0 = Instant::now();
36 let manifest = Manifest::load(manifest_path)?;
37 // `Path::parent` returns Some("") for a bare filename, so collapse that to "." explicitly.
38 let project = match manifest_path.parent() {
39 Some(p) if !p.as_os_str().is_empty() => p.to_path_buf(),
40 _ => PathBuf::from("."),
41 };
42
43 fs::create_dir_all(&out_dir).with_context(|| format!("creating {}", out_dir.display()))?;
44
45 let sp = crate::ui::spinner("vendoring runtime");
46 match vendor_runtime(&out_dir) {
47 Ok(()) => sp.done("vendored runtime"),
48 Err(e) => { sp.fail("failed to vendor runtime"); return Err(e); }
49 }
50
51 let sp = crate::ui::spinner("fetching compiler.wasm");
52 let compiler_bytes = match fetch(COMPILER_WASM).context("fetching compiler.wasm") {
53 Ok(b) => b,
54 Err(e) => { sp.fail("failed to fetch compiler.wasm"); return Err(e); }
55 };
56 fs::write(out_dir.join("compiler.wasm"), &compiler_bytes)?;
57 sp.done("fetched compiler.wasm");
58
59 let scripts = collect_scripts(&project, &out_dir);
60 let imports = crawl_imports(&scripts);
61 let sp = crate::ui::spinner("vendoring packages");
62 let (vendored_imports, vendored_host) = match vendor_packages(&manifest, &imports, &out_dir) {
63 Ok(v) => v,
64 Err(e) => { sp.fail("failed to vendor packages"); return Err(e); }
65 };
66 sp.done("vendored packages");
67 let script_count = copy_scripts(&scripts, &project, &out_dir)?;
68
69 let rewritten = rewrite_manifest(&manifest, &vendored_imports, &vendored_host);
70 let pretty = serde_json::to_string_pretty(&rewritten)?;
71 fs::write(out_dir.join("packages.json"), format!("{pretty}\n"))?;
72
73 let entry = find_entry(&scripts, &project);
74 fs::write(out_dir.join("index.html"), index_html(&entry))?;
75
76 crate::ui::build_report(
77 &out_dir,
78 RUNTIME_FILES.len(),
79 vendored_imports.len() + vendored_host.len(),
80 script_count,
81 dir_size(&out_dir)?,
82 t0.elapsed(),
83 );
84 Ok(())
85}
86
87/// Fetch the runtime JS modules into `dist/runtime/` mirroring their CDN layout.
88fn vendor_runtime(out_dir: &Path) -> Result<()> {

Callers

nothing calls this directly

Calls 15

loadFunction · 0.85
spinnerFunction · 0.85
vendor_runtimeFunction · 0.85
fetchFunction · 0.85
collect_scriptsFunction · 0.85
crawl_importsFunction · 0.85
vendor_packagesFunction · 0.85
copy_scriptsFunction · 0.85
rewrite_manifestFunction · 0.85
find_entryFunction · 0.85
build_reportFunction · 0.85
dir_sizeFunction · 0.85

Tested by

no test coverage detected