main.rs

 1use std::process;
 2
 3#[tokio::main]
 4pub async fn main() -> Result<()> {
 5    let args = Args::parse();
 6
 7    let source_dir = source_dir
 8        .canonicalize()
 9        .context("failed to canonicalize source_dir")?;
10    let scratch_dir = scratch_dir
11        .canonicalize()
12        .context("failed to canonicalize scratch_dir")?;
13    extension_cli::run(source_dir, scratch_dir).await;
14
15    let output_dir = if args.output_dir.is_relative() {
16        env::current_dir()?.join(&args.output_dir)
17    } else {
18        args.output_dir
19    };
20
21    let archive_dir = output_dir.join("archive");
22    fs::remove_dir_all(&archive_dir).ok();
23    copy_extension_resources(&manifest, &extension_path, &archive_dir, fs.clone())
24        .await
25        .context("failed to copy extension resources")?;
26
27    let tar_output = Command::new("tar")
28        .current_dir(&output_dir)
29        .args(["-czvf", "archive.tar.gz", "-C", "archive", "."])
30        .output()
31        .context("failed to run tar")?;
32    if !tar_output.status.success() {
33        bail!(
34            "failed to create archive.tar.gz: {}",
35            String::from_utf8_lossy(&tar_output.stderr)
36        );
37    }
38
39    let extension_provides = extension_provides(&manifest);
40
41    let manifest_json = serde_json::to_string(&rpc::ExtensionApiManifest {
42        name: manifest.name,
43        version: manifest.version,
44        description: manifest.description,
45        authors: manifest.authors,
46        schema_version: Some(manifest.schema_version.0),
47        repository: manifest
48            .repository
49            .context("missing repository in extension manifest")?,
50        wasm_api_version: manifest.lib.version.map(|version| version.to_string()),
51        provides: extension_provides,
52    })?;
53    fs::remove_dir_all(&archive_dir)?;
54    fs::write(output_dir.join("manifest.json"), manifest_json.as_bytes())?;
55}