diff --git a/justfile b/justfile index fa61b27a..dcae9f0a 100644 --- a/justfile +++ b/justfile @@ -15,10 +15,13 @@ install-requirements: build-wasm-components: cargo component build -p pulumi_wasm \ - -p pulumi_wasm_random_provider \ - -p pulumi_wasm_docker_provider \ -p pulumi_wasm_example_simple \ -p pulumi_wasm_example_docker + # DO NOT EDIT - BUILD-WASM-COMPONENTS - START + cargo component build \ + -p pulumi_wasm_docker_provider \ + -p pulumi_wasm_random_provider \ + # DO NOT EDIT - BUILD-WASM-COMPONENTS - END cargo run -p cargo-pulumi -- -p pulumi_wasm_example_simple cargo run -p cargo-pulumi -- -p pulumi_wasm_example_docker @@ -36,13 +39,13 @@ fmt-clippy: regenerate-provider-list: cargo run -p regenerate_providers -# DO NOT EDIT - START +# DO NOT EDIT - REGENERATE-PROVIDERS - START regenerate-providers: cargo run -p cargo-pulumi-gen -- gen-provider --remove true --schema providers/docker.json --output providers/pulumi_wasm_provider_docker cargo run -p cargo-pulumi-gen -- gen-rust --remove true --schema providers/docker.json --output providers/pulumi_wasm_provider_docker_rust cargo run -p cargo-pulumi-gen -- gen-provider --remove true --schema providers/random.json --output providers/pulumi_wasm_provider_random cargo run -p cargo-pulumi-gen -- gen-rust --remove true --schema providers/random.json --output providers/pulumi_wasm_provider_random_rust -# DO NOT EDIT - END +# DO NOT EDIT - REGENERATE-PROVIDERS - END test: cargo nextest run --workspace diff --git a/regenerate_providers/src/main.rs b/regenerate_providers/src/main.rs index ea8f35bb..de7a7a67 100644 --- a/regenerate_providers/src/main.rs +++ b/regenerate_providers/src/main.rs @@ -2,20 +2,20 @@ use std::fs; use std::process::Command; #[derive(Debug)] -struct Provider { - name: String, - version: String, +struct Provider<'a> { + name: &'a str, + version: &'a str, } fn main() { let providers = vec![ Provider { - name: String::from("docker"), - version: String::from("4.5.3"), + name: "docker", + version: "4.5.3", }, Provider { - name: String::from("random"), - version: String::from("4.15.0"), + name: "random", + version: "4.15.0", }, ]; @@ -63,18 +63,37 @@ fn update_cargo_toml(providers: &[Provider]) { fn update_justfile(providers: &[Provider]) { let content = fs::read_to_string("justfile").expect("Failed to read justfile"); + let content = replace_regenerate_providers(providers, &content); + let content = replace_build_wasm_components(providers, &content); + fs::write("justfile", content).expect("Failed to write to justfile"); +} + +fn replace_regenerate_providers(providers: &[Provider], content: &str) -> String { let mut replacement = String::new(); for provider in providers { replacement.push_str(&format!(" cargo run -p cargo-pulumi-gen -- gen-provider --remove true --schema providers/{}.json --output providers/pulumi_wasm_provider_{}\n", provider.name, provider.name)); replacement.push_str(&format!(" cargo run -p cargo-pulumi-gen -- gen-rust --remove true --schema providers/{}.json --output providers/pulumi_wasm_provider_{}_rust\n", provider.name, provider.name)); } - let start_marker = "# DO NOT EDIT - START\nregenerate-providers:"; - let end_marker = "# DO NOT EDIT - END"; - let new_content = replace_between_markers(&content, start_marker, end_marker, &replacement); + let start_marker = "# DO NOT EDIT - REGENERATE-PROVIDERS - START\nregenerate-providers:"; + let end_marker = "# DO NOT EDIT - REGENERATE-PROVIDERS - END"; + replace_between_markers(content, start_marker, end_marker, &replacement) +} + +fn replace_build_wasm_components(providers: &[Provider], content: &str) -> String { + let mut replacement = String::new(); + for provider in providers { + replacement.push_str(&format!( + " -p pulumi_wasm_{}_provider \\\n", + provider.name + )); + } - fs::write("justfile", new_content).expect("Failed to write to justfile"); + let start_marker = + " # DO NOT EDIT - BUILD-WASM-COMPONENTS - START\n cargo component build \\"; + let end_marker = " # DO NOT EDIT - BUILD-WASM-COMPONENTS - END"; + replace_between_markers(content, start_marker, end_marker, &replacement) } fn replace_between_markers(