/**
 * scripts/generate-docs/lib/stats.ts
 * Counts the moving parts that should appear in the stats bar on index.html.
 * Numbers are derived from the filesystem so they can never go stale.
 */
import { sync as globSync } from 'glob';
import { join } from 'node:path';
import { parseAllSkills } from './skill-parser';

const REPO_ROOT = join(__dirname, '..', '..', '..');

export interface Stats {
  skills: number;
  agents: number;
  hooks: number;
  cliCommands: number;
}

function count(glob: string): number {
  return globSync(glob.replace(/\\/g, '/'), { cwd: REPO_ROOT }).length;
}

export function collectStats(): Stats {
  return {
    skills: parseAllSkills().length,
    agents: count('templates/agents/*.md'),
    hooks: count('templates/hooks/*.{sh,js,mjs,cjs}'),
    // CLI commands = TypeScript files in src/commands/ excluding the barrel index.ts
    cliCommands: globSync('src/commands/*.ts', { cwd: REPO_ROOT })
      .filter((f) => !/[\\/]index\.ts$/.test(f)).length,
  };
}
