const fs = require('fs');
const path = require('path');

const keepFiles = [
  'app.js',
  'package.json',
  'package-lock.json',
  '.htaccess',
  'README.md'
];

const items = fs.readdirSync(__dirname);
items.forEach(item => {
  const fullPath = path.join(__dirname, item);
  const stat = fs.statSync(fullPath);
  
  if (stat.isFile() && item.endsWith('.js')) {
    if (!keepFiles.includes(item) && item !== 'clean-useless-files.js') {
      fs.unlinkSync(fullPath);
      console.log(`Deleted unused file: ${item}`);
    }
  }
});

// Self-delete
try {
  fs.unlinkSync(__filename);
  console.log('Successfully self-deleted clean-useless-files.js');
} catch (err) {
  console.error('Failed self-delete:', err);
}
