Skip to content

Commit 64cb7f5

Browse files
authored
ENG-428 Cross-platform build script in packages/database (#197)
* Build script * race condition identified by coderabbit * nitpicks from coderabbit
1 parent 901e473 commit 64cb7f5

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/database/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"check-types": "npm run lint && supabase stop && npm run dbdiff",
1515
"lint": "tsx scripts/lint.ts",
1616
"lint:fix": "tsx scripts/lint.ts -f",
17-
"build": "if [ $HOME != '/vercel' ]; then\n supabase start && supabase migrations up && (supabase gen types typescript --local --schema public > types.gen.ts)\nfi",
17+
"build": "tsx scripts/build.ts",
1818
"gentypes:production": "supabase start && supabase gen types typescript --project-id \"$SUPABASE_PROJECT_ID\" --schema public > types.gen.ts",
1919
"dbdiff": "supabase stop && supabase db diff",
2020
"dbdiff:save": "supabase stop && supabase db diff -f",

packages/database/scripts/build.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { execSync } from "node:child_process";
2+
import { writeFileSync } from "fs"
3+
import { join, dirname } from "path";
4+
import { fileURLToPath } from "url";
5+
6+
const __dirname = dirname(fileURLToPath(import.meta.url));
7+
const projectRoot = join(__dirname, '..');
8+
9+
if (process.env.HOME !== '/vercel') {
10+
try {
11+
execSync('supabase start');
12+
execSync('supabase migrations up');
13+
const stdout = execSync('supabase gen types typescript --local --schema public', { encoding: 'utf8' });
14+
writeFileSync(join(projectRoot, 'types.gen.ts'), stdout);
15+
} catch (err) {
16+
console.error(err);
17+
throw err;
18+
}
19+
}

0 commit comments

Comments
 (0)