-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathgenerate.ts
More file actions
47 lines (42 loc) · 1.68 KB
/
generate.ts
File metadata and controls
47 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { $ } from "bun";
const dry = process.argv.includes("--dry");
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}`;
const resp = await fetch(`https://registry.npmjs.org/${name}/${version}`);
if (resp.status !== 404) {
console.log("skipping", name, "version", version, "already exists");
continue;
}
console.log("generating", name, "version", version);
const result =
await $`pulumi package add terraform-provider ${provider.terraform} ${provider.version}`;
const output = result.stdout.toString();
const sdksPath = output.match(/at (\/[^\n]+)/)?.at(1);
const packageName = output.match(/for the (\S+) package/)?.at(1);
if (!sdksPath || !packageName) {
console.log("failed to parse output");
continue;
}
const path = `${sdksPath}/${packageName}`;
console.log("path", path);
process.chdir(path);
const pkg = Bun.file("package.json");
const json = await pkg.json();
json.name = name;
json.version = provider.version;
json.files = ["bin/", "README.md", "LICENSE"];
json.repository = {
type: "git",
url: "https://github.com/anomalyco/provider",
};
if (provider.suffix) json.version += "-" + provider.suffix;
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`;
if (!dry) await $`npm publish --access public`;
}