Skip to content

Commit

Permalink
switch to toml to avoid json formatting issues and conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Oct 12, 2024
1 parent 8343b59 commit 21f66b4
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sdks
node_modules
29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,21 @@ This repository automatically generates pulumi packages from terraform providers

### Adding a provider

Submit a PR to add a provider to the `providers.json` file.
Submit a PR to add a <provider>.toml to the `metadata` folder

```json
[
{
"name": "planetscale",
"terraform": "planetscale/planetscale",
"version": "0.0.7"
},
]
```toml
name = "planetscale"
terraform = "planetscale/planetscale"
version = "0.0.7"
```

### Updating a provider

Submit a PR bumping the version number. If something went wrong and we need to regenerate the same version add a `suffix` to the provider with an incrementing number.

```json
[
{
"name": "planetscale",
"terraform": "planetscale/planetscale",
"version": "0.0.7",
"suffix": "1"
},
]
```toml
name = "planetscale"
terraform = "planetscale/planetscale"
version = "0.0.7"
suffix = "1"
```
Binary file added bun.lockb
Binary file not shown.
28 changes: 20 additions & 8 deletions generate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import providers from "./providers.json";
import { $ } from "bun";

for (const provider of providers) {
for (const file of new Bun.Glob("*").scanSync("metadata")) {
const provider = await import(`./metadata/${file}`);
const version = [provider.version, provider.suffix].filter(Boolean).join("-");
const name = `@sst-provider/${provider.name}`;
// check if version exists on npm
const resp = await fetch(`https://registry.npmjs.org/${name}/${version}`);
if (resp.status !== 404) {
console.log("skipping", name, "version", version, "already exists");
Expand All @@ -13,17 +12,30 @@ for (const provider of providers) {
console.log("generating", name, "version", version);
const result =
await $`pulumi package add terraform-provider ${provider.terraform} ${provider.version}`;
console.log(result.stdout.toString());
const path = result.stdout.toString().match(/at (\/[^\n]+)/)[1];
const path = result.stdout
.toString()
.match(/at (\/[^\n]+)/)
?.at(1);
if (!path) {
console.log("failed to find path");
continue;
}
console.log("path", path);
process.chdir(path);
const file = Bun.file("package.json");
const json = await file.json();

const pkg = Bun.file("package.json");
const json = await pkg.json();
json.name = name;
json.version = provider.version;
json.files = ["bin/", "README.md", "LICENSE"];
if (provider.suffix) json.version += "-" + provider.suffix;
await Bun.write(file, JSON.stringify(json, null, 2));
await Bun.write(pkg, JSON.stringify(json, null, 2));

const tsconfig = Bun.file("tsconfig.json");
const tsjson = await tsconfig.json();
tsjson.compilerOptions.skipLibCheck = true;
await Bun.write(tsconfig, JSON.stringify(tsjson, null, 2));

await $`bun install && bun run build`;
await $`npm publish --access public`;
}
4 changes: 4 additions & 0 deletions metadata/cloudflare5.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "cloudflare5"
terraform = "cloudflare/cloudflare"
version = "5.0.0-alpha1"
suffix = "1"
3 changes: 3 additions & 0 deletions metadata/momento.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "momento"
terraform = "momentohq/momento"
version = "0.2.2"
3 changes: 3 additions & 0 deletions metadata/neon.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "neon"
terraform = "kislerdm/neon"
version = "0.6.3"
3 changes: 3 additions & 0 deletions metadata/planetscale.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "planetscale"
terraform = "planetscale/planetscale"
version = "0.0.7"
3 changes: 3 additions & 0 deletions metadata/supabase.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "supabase"
terraform = "supabase/supabase"
version = "1.4.1"
3 changes: 3 additions & 0 deletions metadata/turso.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "turso"
terraform = "registry.terraform.io/jpedroh/turso"
version = "0.2.1"
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@types/bun": "^1.1.11"
}
}
33 changes: 0 additions & 33 deletions providers.json

This file was deleted.

0 comments on commit 21f66b4

Please sign in to comment.