Skip to content

Commit 61eb173

Browse files
committed
fix: add auto type generation with a script
1 parent 177a48b commit 61eb173

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "2.0.0",
55
"type": "module",
66
"scripts": {
7+
"gentypes": "bun run src/lib/types/update.ts",
78
"dev": "vite dev",
89
"build": "vite build",
910
"preview": "vite preview",

src/lib/types/update.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { unlink } from "fs/promises"
2+
import { writeFile } from "fs/promises"
3+
import { join } from "path"
4+
5+
const url =
6+
"https://db.waspscripts.dev/api/v1/projects/default/types/typescript?included_schemas=public%2C%20storage"
7+
const outputPath = join(__dirname, "supabase.ts")
8+
9+
console.log(outputPath)
10+
11+
try {
12+
await unlink(outputPath)
13+
console.log("Old types file deleted successfully")
14+
} catch (err) {
15+
console.error("Error deleting old types file:", err)
16+
}
17+
18+
try {
19+
const response = await fetch(url, {
20+
headers: {
21+
accept: "application/json",
22+
authorization:
23+
"Basic " +
24+
Buffer.from(`${process.env.BASIC_AUTH_USER}:${process.env.BASIC_AUTH_PASS}`).toString(
25+
"base64"
26+
)
27+
}
28+
})
29+
30+
if (!response.ok) {
31+
throw new Error(`Request failed with status ${response.status}`)
32+
}
33+
34+
const json = await response.json()
35+
const tsCode = json.types
36+
await writeFile(outputPath, tsCode)
37+
38+
console.log(`Types file updated!`)
39+
} catch (err) {
40+
console.error("Error:", err)
41+
}

src/routes/Navigation.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,5 @@
257257
</form>
258258
</nav>
259259
<a href="https://waspscripts.com" class="bg-surface-300-700 py-2 text-center">
260-
This website is for <b>Simba 2.0</b>. Click here to visit the legacy version of the website.
260+
This website is for <b>Simba 2000</b>. Click here to visit the legacy version of the website.
261261
</a>

src/routes/scripts/[slug]/edit/+page.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
value={[$form.simba]}
288288
onValueChange={(e) => ($form.simba = e.value[0])}
289289
label="Simba:"
290+
ids={{ input: "simba" }}
290291
allowCustomValue={true}
291292
defaultInputValue={$form.simba}
292293
zIndex="1"
@@ -302,6 +303,7 @@
302303
value={[$form.wasplib]}
303304
onValueChange={(e) => ($form.wasplib = e.value[0])}
304305
label="WaspLib:"
306+
ids={{ input: "wasplib" }}
305307
allowCustomValue={true}
306308
defaultInputValue={$form.wasplib}
307309
zIndex="1"

src/routes/scripts/add/+page.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@
328328
value={[$form.simba]}
329329
onValueChange={(e) => ($form.simba = e.value[0])}
330330
label="Simba:"
331+
ids={{ input: "simba" }}
331332
allowCustomValue={true}
332333
defaultInputValue={$form.simba}
333334
zIndex="1"
@@ -343,6 +344,7 @@
343344
value={[$form.wasplib]}
344345
onValueChange={(e) => ($form.wasplib = e.value[0])}
345346
label="WaspLib:"
347+
ids={{ input: "wasplib" }}
346348
allowCustomValue={true}
347349
defaultInputValue={$form.wasplib}
348350
zIndex="1"

0 commit comments

Comments
 (0)