diff --git a/packages/database/package.json b/packages/database/package.json index c2c930638..113dd5ea5 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -14,7 +14,7 @@ "check-types": "npm run lint && supabase stop && npm run dbdiff", "lint": "tsx scripts/lint.ts", "lint:fix": "tsx scripts/lint.ts -f", - "build": "if [ $HOME != '/vercel' ]; then\n supabase start && supabase migrations up && (supabase gen types typescript --local --schema public > types.gen.ts)\nfi", + "build": "tsx scripts/build.ts", "gentypes:production": "supabase start && supabase gen types typescript --project-id \"$SUPABASE_PROJECT_ID\" --schema public > types.gen.ts", "dbdiff": "supabase stop && supabase db diff", "dbdiff:save": "supabase stop && supabase db diff -f", diff --git a/packages/database/scripts/build.ts b/packages/database/scripts/build.ts new file mode 100644 index 000000000..61b03763c --- /dev/null +++ b/packages/database/scripts/build.ts @@ -0,0 +1,19 @@ +import { execSync } from "node:child_process"; +import { writeFileSync } from "fs" +import { join, dirname } from "path"; +import { fileURLToPath } from "url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const projectRoot = join(__dirname, '..'); + +if (process.env.HOME !== '/vercel') { + try { + execSync('supabase start'); + execSync('supabase migrations up'); + const stdout = execSync('supabase gen types typescript --local --schema public', { encoding: 'utf8' }); + writeFileSync(join(projectRoot, 'types.gen.ts'), stdout); + } catch (err) { + console.error(err); + throw err; + } +}