typescript-express-starter
Version:
Quick and Easy TypeScript Express Starter
86 lines (70 loc) β’ 2.8 kB
JavaScript
/**
* Template integrity validation script
*/
import { validateAllTemplates, cleanTemplate } from './validators.js';
import { ValidationError } from './errors.js';
import chalk from 'chalk';
import path from 'path';
import fs from 'fs';
async function main() {
console.log(chalk.blue.bold('\nπ Starting template integrity validation...\n'));
try {
const results = validateAllTemplates();
const templatesWithViolations = Object.entries(results).filter(([_, result]) => !result.valid);
if (templatesWithViolations.length === 0) {
console.log(chalk.green('β
All templates passed integrity validation!'));
return;
}
console.log(
chalk.yellow.bold(`β οΈ ${templatesWithViolations.length}κ° ν
νλ¦Ώμμ λ¬΄κ²°μ± μλ° λ°κ²¬:\n`),
);
for (const [templateName, result] of templatesWithViolations) {
console.log(chalk.red(`β ${templateName}:`));
result.violations.forEach((violation) => {
console.log(chalk.gray(` - ${violation}`));
});
console.log('');
}
// Ask for cleanup
const templateDir = path.join(process.cwd(), 'templates');
let totalRemoved = 0;
console.log(chalk.blue.bold('π§Ή Starting template cleanup...\n'));
for (const [templateName, _] of templatesWithViolations) {
const templatePath = path.join(templateDir, templateName);
const removedFiles = cleanTemplate(templatePath);
if (removedFiles.length > 0) {
console.log(chalk.green(`β
Removed ${removedFiles.length} files from ${templateName}:`));
removedFiles.forEach((file) => {
console.log(chalk.gray(` - ${file}`));
});
totalRemoved += removedFiles.length;
console.log('');
}
}
if (totalRemoved > 0) {
console.log(chalk.blue.bold(`π Total ${totalRemoved} files removed.\n`));
// Re-validate
console.log(chalk.blue('π Re-validating...\n'));
const revalidationResults = validateAllTemplates();
const stillViolating = Object.entries(revalidationResults).filter(
([_, result]) => !result.valid,
);
if (stillViolating.length === 0) {
console.log(chalk.green.bold('β
All templates now pass integrity validation!'));
} else {
console.log(chalk.red.bold(`β Still found issues in ${stillViolating.length} templates`));
stillViolating.forEach(([name, result]) => {
console.log(chalk.red(` - ${name}: ${result.violations.join(', ')}`));
});
}
}
} catch (error) {
console.error(chalk.red.bold('β μμμΉ λͺ»ν μ€λ₯ λ°μ:'));
console.error(error.stack || error.message);
process.exit(1);
}
}
if (import.meta.url === `file://${process.argv[1]}`) {
main();
}