import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { itemsDir } from './data-path';

const SOURCE_PATH = resolve(import.meta.dir, 'tool-loader-source.ts');

export function ensureToolLoader(): void {
  const targetDir = join(itemsDir('extensions'), 'tool-loader');
  const targetFile = join(targetDir, 'index.ts');

  mkdirSync(targetDir, { recursive: true });

  const source = readFileSync(SOURCE_PATH, 'utf-8');
  writeFileSync(targetFile, source, 'utf-8');

  console.log('[bootstrap] Wrote tool-loader extension →', targetFile);
}
