@chahuadev/fix-comments
Version:
Professional Comment Standardization Tool v2.0.0 Beta - Advanced Pattern Recognition and Enhanced Context Detection for JavaScript/TypeScript projects with Smart Learning capabilities and enterprise security
158 lines (137 loc) • 5.08 kB
JavaScript
// Pre-publish validation script for v2.0.0-beta.1
// ตรวจสอบก่อน publish ขึ้น NPM สำหรับเวอร์ชัน Beta
const fs = require('fs');
const path = require('path');
// Import fix-comments.js to test new functions
let fixComments;
try {
fixComments = require('../fix-comments.js');
} catch (error) {
console.error(' Failed to import fix-comments.js:', error.message);
process.exit(1);
}
console.log(' Pre-publish validation for Beta v2.0.0-beta.1...\n');
// ตรวจสอบไฟล์สำคัญสำหรับ Beta release
const requiredFiles = [
'fix-comments.js',
'package.json',
'README.md',
'LICENSE',
'CHANGELOG.md',
'test-suite.js',
'scripts/pre-publish.js'
];
// ตรวจสอบ directories ที่ควรมี
const requiredDirs = [
'.backups',
'logs',
'scripts',
'.github/workflows'
];
let allValid = true;
requiredFiles.forEach(file => {
if (fs.existsSync(file)) {
const stats = fs.statSync(file);
console.log(` ${file} (${stats.size} bytes)`);
} else {
console.log(` Missing: ${file}`);
allValid = false;
}
});
// ตรวจสอบ package.json
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
console.log('\n Package validation:');
console.log(` Name: ${pkg.name}`);
console.log(` Version: ${pkg.version}`);
console.log(` Description: ${pkg.description ? '' : ''}`);
console.log(` Author: ${pkg.author ? '' : ''}`);
console.log(` License: ${pkg.license}`);
console.log(` Keywords: ${pkg.keywords ? pkg.keywords.length : 0} keywords`);
// ตรวจสอบ required directories
console.log('\n Directory validation:');
requiredDirs.forEach(dir => {
if (fs.existsSync(dir)) {
console.log(` ${dir} exists`);
} else {
console.log(` Missing directory: ${dir}`);
// Create directories if missing (for Beta)
try {
fs.mkdirSync(dir, { recursive: true });
console.log(` Created: ${dir}`);
} catch (error) {
console.log(` Failed to create: ${dir}`);
allValid = false;
}
}
});
// ทดสอบการทำงานของ CLI พร้อมฟีเจอร์ Beta
console.log('\n Testing CLI functionality...');
try {
const { execSync } = require('child_process');
// Test --version command
const versionOutput = execSync('node fix-comments.js --version', { encoding: 'utf8' });
if (versionOutput.includes('v2.0.0-beta.1')) {
console.log(' Version command works (Beta detected)');
} else {
console.log(' Version output incorrect');
allValid = false;
}
// Test --help command
const helpOutput = execSync('node fix-comments.js --help', { encoding: 'utf8' });
if (helpOutput.includes('Universal Code Magician') && helpOutput.includes('BETA')) {
console.log(' Help command works (Beta features detected)');
} else {
console.log(' Help output seems wrong or missing Beta info');
allValid = false;
}
} catch (error) {
console.log(' CLI test failed:', error.message);
allValid = false;
}
// Test new Beta functions
console.log('\n Testing Beta v2.0.0-beta.1 functions...');
try {
if (typeof fixComments.EnhancedPatternDetector === 'function') {
console.log(' EnhancedPatternDetector class available');
} else {
console.log(' Missing EnhancedPatternDetector class');
allValid = false;
}
if (typeof fixComments.ProfessionalLogger === 'function') {
console.log(' ProfessionalLogger class available');
} else {
console.log(' Missing ProfessionalLogger class');
allValid = false;
}
if (typeof fixComments.analyzeFileWithSmartLearning === 'function') {
console.log(' Smart Learning function available');
} else {
console.log(' Missing Smart Learning function');
allValid = false;
}
if (typeof fixComments.performCodeHealthCheck === 'function') {
console.log(' Code Health Check function available');
} else {
console.log(' Missing Code Health Check function');
allValid = false;
}
} catch (error) {
console.log(' Function test failed:', error.message);
allValid = false;
}
// ตรวจสอบ version ใน CHANGELOG
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
if (changelog.includes(`[${pkg.version}]`)) {
console.log(' Version documented in CHANGELOG');
} else {
console.log(` Version ${pkg.version} not found in CHANGELOG`);
}
console.log('\n' + '='.repeat(50));
if (allValid) {
console.log(' All validations passed! Ready to publish!');
process.exit(0);
} else {
console.log(' Some validations failed. Please fix before publishing.');
process.exit(1);
}