#!/usr/bin/env node
import { rmSync } from 'node:fs';
import { join } from 'node:path';

const workspaceRoot = new URL('..', import.meta.url).pathname;
const packages = [
  'browser-host',
  'browser-kit',
  'cli',
  'contracts',
  'core',
  'federation',
  'omega-core',
  'sdk',
];

for (const rel of ['dist']) {
  rmSync(join(workspaceRoot, rel), { recursive: true, force: true });
}

for (const pkg of packages) {
  const pkgRoot = join(workspaceRoot, 'packages', pkg);
  rmSync(join(pkgRoot, 'dist'), { recursive: true, force: true });
  rmSync(join(pkgRoot, '.tsbuildinfo'), { force: true });

  const tarballs = [
    'open-matrix-contracts-0.1.0.tgz',
    'open-matrix-federation-0.2.0.tgz',
    'open-matrix-omega-core-0.1.0.tgz',
    'open-matrix-browser-host-0.1.0.tgz',
    'open-matrix-browser-kit-0.1.0.tgz',
    'open-matrix-cli-0.1.0.tgz',
    'open-matrix-core-0.1.0.tgz',
    'open-matrix-sdk-0.1.0.tgz',
  ];
  for (const tarball of tarballs) {
    rmSync(join(pkgRoot, tarball), { force: true });
  }
}
