File size: 5,297 Bytes
1e2511f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env node

// Pre-publish validation script for v3.0.1-beta (FINAL BETA)
// ตรวจสอบก่อน publish ขึ้น NPM สำหรับเวอร์ชัน Final 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 FINAL BETA v3.0.1-beta...\n');

// ตรวจสอบไฟล์สำคัญสำหรับ Final Beta release
const requiredFiles = [
    'fix-comments.js',
    'package.json',
    'README.md',
    'LICENSE',
    'CHANGELOG.md',
    '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('v3.0.1-beta')) {
        console.log(' Version command works (Final Beta v3.0.1-beta detected)');
    } else {
        console.log(' Version output incorrect - should show v3.0.1-beta');
        allValid = false;
    }

    // Test --help command
    const helpOutput = execSync('node fix-comments.js --help', { encoding: 'utf8' });
    if (helpOutput.includes('Universal Comment Fixer Tool') && helpOutput.includes('FINAL BETA')) {
        console.log(' Help command works (Final Beta features detected)');
    } else {
        console.log(' Help output seems wrong or missing Final Beta info');
        allValid = false;
    }

} catch (error) {
    console.log(' CLI test failed:', error.message);
    allValid = false;
}

// Test Final Beta functions
console.log(' Testing Final Beta v3.0.1-beta 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(60));
if (allValid) {
    console.log(' All validations passed! Ready for FINAL BETA publish!');
    console.log(' Next step: npm publish --tag beta');
    console.log(' Remember: This is the FINAL BETA before v1.0.0 (Q1 2026)');
    process.exit(0);
} else {
    console.log(' Some validations failed. Please fix before publishing.');
    process.exit(1);
}