import { type BuildConfig, copyDir, panic } from './util.ts';
import { join } from 'node:path';
import { execa } from 'execa';

const PACKAGE = 'supabase-auth-helpers-qwik';

export async function buildSupabaseAuthHelpers(config: BuildConfig) {
  const input = join(config.packagesDir, PACKAGE);

  const result = await execa('pnpm', ['build'], {
    stdout: 'inherit',
    cwd: input,
  });

  if (result.failed) {
    panic(`tsc failed`);
  }
  await copyDir(
    config,
    join(config.dtsDir, 'packages', PACKAGE, 'src'),
    join(input, 'lib', 'types')
  );
  console.log(`⚛️  ${PACKAGE}`);
}
