import { defineConfig, type Options } from 'tsup';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const assetsDir = path.resolve(__dirname, '../../crates/auroraview-core/src/assets/js');

const commonOptions: Partial<Options> = {
  format: ['iife'],
  outDir: assetsDir,
  clean: false,
  minify: false,
  sourcemap: false,
  splitting: false,
  treeshake: true,
  noExternal: [/.*/],
  outExtension: () => ({ js: '.js' }),
  banner: {
    js: '// Generated by @auroraview/sdk',
  },
};

export default defineConfig([
  // Core bridge scripts (IIFE format for injection)
  {
    ...commonOptions,
    entry: {
      'core/event_bridge': 'src/inject/event_bridge.ts',
      'core/state_bridge': 'src/inject/state_bridge.ts',
      'core/bridge_stub': 'src/inject/bridge_stub.ts',
    },
  },
  // Plugin scripts (IIFE format for injection)
  {
    ...commonOptions,
    entry: {
      'plugins/fs': 'src/inject/plugins/fs.ts',
      'plugins/dialog': 'src/inject/plugins/dialog.ts',
      'plugins/clipboard': 'src/inject/plugins/clipboard.ts',
      'plugins/shell': 'src/inject/plugins/shell.ts',
    },
  },
]);
