import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';

const entries = ['index', 'constants'];

function* build() {
  // ESM builds
  yield {
    input: Object.fromEntries(entries.map(e => [e, `src/${e}.ts`])),
    output: {
      dir: 'dist',
      entryFileNames: '[name].mjs',
      format: 'esm'
    },
    plugins: [typescript({ declaration: false })]
  };

  // CJS builds
  yield {
    input: Object.fromEntries(entries.map(e => [e, `src/${e}.ts`])),
    output: {
      dir: 'dist',
      entryFileNames: '[name].cjs',
      format: 'cjs',
      exports: 'named'
    },
    plugins: [typescript({ declaration: false })]
  };

  // ESM type declarations (.d.mts)
  yield {
    input: Object.fromEntries(entries.map(e => [e, `src/${e}.ts`])),
    output: {
      dir: 'dist',
      entryFileNames: '[name].d.mts'
    },
    plugins: [dts({ respectExternal: true })]
  };

  // CJS type declarations (.d.cts)
  yield {
    input: Object.fromEntries(entries.map(e => [e, `src/${e}.ts`])),
    output: {
      dir: 'dist',
      entryFileNames: '[name].d.cts'
    },
    plugins: [dts({ respectExternal: true })]
  };
}

export default [...build()];

