gbu-accessibility-package 3.11.0 → 3.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli.js CHANGED
@@ -32,12 +32,11 @@ const options = {
32
32
  dlOnly: false,
33
33
  brokenLinksOnly: false,
34
34
  unusedFilesOnly: false,
35
+ unusedFilesListOnly: false,
36
+ deleteUnusedFilesFromList: false,
35
37
  deadCodeOnly: false,
36
38
  fileSizeOnly: false,
37
- metaCheckOnly: false,
38
- metaFixOnly: false,
39
- fullReport: false,
40
- reportOutput: null,
39
+ listFile: 'unused-files-list.txt',
41
40
  // Enhanced alt options
42
41
  enhancedAlt: false,
43
42
  altCreativity: 'balanced', // conservative, balanced, creative
@@ -133,31 +132,42 @@ for (let i = 0; i < args.length; i++) {
133
132
  case '--google-tag-manager':
134
133
  options.gtmCheckOnly = true;
135
134
  break;
136
- case '--unused-files':
137
- options.unusedFilesOnly = true;
138
- break;
139
- case '--dead-code':
140
- options.deadCodeOnly = true;
141
- break;
142
- case '--file-size':
143
- case '--size-check':
144
- options.fileSizeOnly = true;
145
- break;
135
+ case '--check-meta':
146
136
  case '--meta-check':
147
- options.metaCheckOnly = true;
137
+ options.checkMetaOnly = true;
148
138
  break;
139
+ case '--fix-meta':
149
140
  case '--meta-fix':
150
- options.metaFixOnly = true;
141
+ options.fixMetaOnly = true;
151
142
  break;
152
143
  case '--full-report':
153
- case '--export-report':
154
144
  case '--report':
145
+ case '--excel-report':
155
146
  options.fullReport = true;
156
147
  break;
157
- case '--report-output':
158
148
  case '-o':
149
+ case '--output':
159
150
  options.reportOutput = args[++i];
160
151
  break;
152
+ case '--unused-files':
153
+ options.unusedFilesOnly = true;
154
+ break;
155
+ case '--unused-files-list':
156
+ options.unusedFilesListOnly = true;
157
+ break;
158
+ case '--delete-unused-files':
159
+ options.deleteUnusedFilesFromList = true;
160
+ break;
161
+ case '--list-file':
162
+ options.listFile = args[++i];
163
+ break;
164
+ case '--dead-code':
165
+ options.deadCodeOnly = true;
166
+ break;
167
+ case '--file-size':
168
+ case '--size-check':
169
+ options.fileSizeOnly = true;
170
+ break;
161
171
  case '--auto-fix-headings':
162
172
  options.autoFixHeadings = true;
163
173
  break;
@@ -217,13 +227,16 @@ Options:
217
227
  --broken-links Check for broken external links only (no auto-fix)
218
228
  --404-resources Check for missing local resources only (no auto-fix)
219
229
  --gtm-check Check Google Tag Manager installation (no auto-fix)
230
+ --check-meta Check meta tags and Open Graph Protocol (no auto-fix)
231
+ --fix-meta Auto-fix missing meta tags and OGP tags
232
+ --full-report Generate comprehensive Excel report (all checks)
233
+ -o, --output <file> Output path for Excel report (use with --full-report)
220
234
  --unused-files Check for unused files in project (no auto-fix)
235
+ --unused-files-list Create unused-files-list.txt from detected unused files
236
+ --delete-unused-files Delete all files listed in unused-files-list.txt
237
+ --list-file <file> Custom list file name/path inside target directory
221
238
  --dead-code Check for dead code in CSS and JavaScript (no auto-fix)
222
239
  --file-size, --size-check Check file sizes and suggest optimizations (no auto-fix)
223
- --meta-check Check Meta Tags and Open Graph Protocol (no auto-fix)
224
- --meta-fix Auto-fix Meta Tags syntax and typos
225
- --full-report Generate comprehensive Excel report (all checks)
226
- --report-output, -o Output path for report file (default: accessibility-report-YYYY-MM-DD.xlsx)
227
240
  --enhanced-alt Use enhanced alt attribute analysis and generation
228
241
  --alt-creativity <mode> Alt text creativity: conservative, balanced, creative (default: balanced)
229
242
  --include-emotions Include emotional descriptors in alt text
@@ -258,13 +271,17 @@ Examples:
258
271
  node cli.js --broken-links # Check for broken external links only
259
272
  node cli.js --404-resources # Check for missing local resources only
260
273
  node cli.js --gtm-check # Check Google Tag Manager installation
274
+ node cli.js --check-meta # Check meta tags and Open Graph Protocol
275
+ node cli.js --fix-meta # Auto-fix missing meta tags and OGP
276
+ node cli.js --fix-meta --dry-run # Preview meta tag fixes
277
+ node cli.js --full-report # Generate comprehensive Excel report
278
+ node cli.js --full-report ./project -o report.xlsx # Custom output path
261
279
  node cli.js --unused-files # Check for unused files in project
280
+ node cli.js --unused-files-list # Create ./unused-files-list.txt
281
+ node cli.js --delete-unused-files # Delete files listed in ./unused-files-list.txt
282
+ node cli.js --delete-unused-files --dry-run # Preview files that would be deleted
262
283
  node cli.js --dead-code # Check for dead CSS and JavaScript code
263
284
  node cli.js --file-size # Check file sizes and suggest optimizations
264
- node cli.js --meta-check # Check Meta Tags and Open Graph Protocol
265
- node cli.js --meta-fix # Auto-fix Meta Tags syntax and typos
266
- node cli.js --full-report # Generate comprehensive Excel report
267
- node cli.js --full-report ./project -o report.xlsx # Custom output path
268
285
  node cli.js --cleanup-only # Only cleanup duplicate roles
269
286
  node cli.js ./src # Fix src directory (comprehensive)
270
287
  node cli.js -l en --dry-run ./dist # Preview comprehensive fixes in English
@@ -323,17 +340,17 @@ async function main() {
323
340
  });
324
341
 
325
342
  try {
326
- // Handle Full Report mode first (independent, doesn't need other options)
343
+ // Handle Full Report mode first
327
344
  if (options.fullReport) {
328
345
  console.log(chalk.blue('📊 Đang tạo báo cáo toàn diện...'));
329
346
  await fixer.generateFullReport(options.directory, options.reportOutput);
330
- process.exit(0);
347
+ return;
331
348
  }
332
349
 
333
350
  // Handle different modes - All modes now include cleanup
334
351
  if (options.cleanupOnly || options.altOnly || options.langOnly || options.roleOnly || options.ariaLabelOnly ||
335
352
  options.formsOnly || options.nestedOnly || options.buttonsOnly || options.linksOnly || options.landmarksOnly ||
336
- options.headingsOnly || options.dlOnly || options.linksCheckOnly || options.brokenLinksOnly || options.missingResourcesOnly || options.gtmCheckOnly || options.unusedFilesOnly || options.deadCodeOnly || options.fileSizeOnly || options.metaCheckOnly || options.metaFixOnly) {
353
+ options.headingsOnly || options.dlOnly || options.linksCheckOnly || options.brokenLinksOnly || options.missingResourcesOnly || options.gtmCheckOnly || options.checkMetaOnly || options.fixMetaOnly || options.unusedFilesOnly || options.unusedFilesListOnly || options.deleteUnusedFilesFromList || options.deadCodeOnly || options.fileSizeOnly) {
337
354
  // Individual modes - handle each separately, then run cleanup
338
355
  } else {
339
356
  // Default mode: Run comprehensive fix (all fixes including cleanup)
@@ -625,6 +642,22 @@ async function main() {
625
642
  showCompletionMessage(options, 'Kiểm tra GTM');
626
643
  return;
627
644
 
645
+ } else if (options.checkMetaOnly) {
646
+ // Check meta tags only (no fixes)
647
+ console.log(chalk.blue('🏷️ Đang kiểm tra meta tags và Open Graph Protocol...'));
648
+ await fixer.checkMetaTags(options.directory);
649
+
650
+ showCompletionMessage(options, 'Kiểm tra meta tags');
651
+ return;
652
+
653
+ } else if (options.fixMetaOnly) {
654
+ // Fix meta tags
655
+ console.log(chalk.blue('🔧 Đang tự động sửa meta tags...'));
656
+ await fixer.fixMetaTags(options.directory, { dryRun: options.dryRun, backup: options.backupFiles });
657
+
658
+ showCompletionMessage(options, 'Sửa meta tags');
659
+ return;
660
+
628
661
  } else if (options.unusedFilesOnly) {
629
662
  // Check unused files only (no fixes, no cleanup)
630
663
  console.log(chalk.blue('🗂️ Đang kiểm tra file không sử dụng...'));
@@ -641,6 +674,39 @@ async function main() {
641
674
 
642
675
  showCompletionMessage(options, 'Kiểm tra file không sử dụng');
643
676
  return;
677
+
678
+ } else if (options.unusedFilesListOnly) {
679
+ console.log(chalk.blue('📝 Đang tạo danh sách file không sử dụng...'));
680
+ const listResults = await fixer.generateUnusedFilesList(options.directory, options.listFile);
681
+
682
+ console.log(chalk.green(`\n✅ Đã tạo file list: ${listResults.outputPath}`));
683
+ console.log(chalk.gray(`📊 ${listResults.unusedCount} path đã được ghi vào list`));
684
+ console.log(chalk.gray('💡 Danh sách dùng path tương đối so với thư mục target và có thể dùng lại với --delete-unused-files'));
685
+ return;
686
+
687
+ } else if (options.deleteUnusedFilesFromList) {
688
+ console.log(chalk.blue('🗑️ Đang xóa file theo danh sách unused files...'));
689
+ const deleteResults = await fixer.deleteUnusedFilesFromList(options.directory, options.listFile, {
690
+ dryRun: options.dryRun
691
+ });
692
+
693
+ console.log(chalk.green(`\n✅ ${options.dryRun ? 'Đã mô phỏng xóa' : 'Đã xử lý xóa'} ${deleteResults.deletedCount} file từ list`));
694
+ console.log(chalk.gray(`📄 File list: ${deleteResults.listPath}`));
695
+
696
+ if (deleteResults.missingCount > 0) {
697
+ console.log(chalk.yellow(`⚠️ ${deleteResults.missingCount} file trong list không còn tồn tại`));
698
+ }
699
+
700
+ if (deleteResults.skippedCount > 0) {
701
+ console.log(chalk.yellow(`⚠️ ${deleteResults.skippedCount} entry bị bỏ qua vì không an toàn hoặc không hợp lệ`));
702
+ }
703
+
704
+ if (options.dryRun) {
705
+ console.log(chalk.cyan('\n💡 Đây là chế độ xem trước. Chạy lại không kèm --dry-run để xóa thật.'));
706
+ } else {
707
+ console.log(chalk.gray('💡 File list được giữ nguyên để bạn có thể đối chiếu sau khi xóa'));
708
+ }
709
+ return;
644
710
 
645
711
  } else if (options.deadCodeOnly) {
646
712
  // Check dead code only (no fixes, no cleanup)
@@ -665,42 +731,6 @@ async function main() {
665
731
 
666
732
  showCompletionMessage(options, 'Phân tích kích thước file');
667
733
  return;
668
-
669
- } else if (options.metaCheckOnly) {
670
- // Check Meta Tags and Open Graph Protocol only (no fixes, no cleanup)
671
- console.log(chalk.blue('🏷️ Đang kiểm tra Meta Tags và Open Graph Protocol...'));
672
- const metaResults = await fixer.checkMetaTags(options.directory);
673
- const filesWithOG = metaResults.filter(r => r.metaAnalysis?.hasOpenGraph).length;
674
- const filesWithIssues = metaResults.filter(r => r.metaAnalysis?.issues?.length > 0).length;
675
- const totalIssues = metaResults.reduce((sum, r) => sum + (r.metaAnalysis?.issues?.length || 0), 0);
676
-
677
- console.log(chalk.green(`\n✅ Phân tích hoàn tất: ${metaResults.length} file`));
678
- console.log(chalk.green(` ✅ File có Open Graph: ${filesWithOG}`));
679
- if (filesWithIssues > 0) {
680
- console.log(chalk.yellow(` ⚠️ ${filesWithIssues} file có vấn đề (${totalIssues} vấn đề)`));
681
- }
682
- console.log(chalk.gray('💡 Open Graph Protocol cần có 4 thẻ bắt buộc: og:title, og:type, og:image, og:url'));
683
-
684
- showCompletionMessage(options, 'Kiểm tra Meta Tags');
685
- return;
686
-
687
- } else if (options.metaFixOnly) {
688
- // Auto-fix Meta Tags syntax and typos
689
- console.log(chalk.blue('🔧 Đang sửa Meta Tags và Open Graph Protocol...'));
690
- const fixResults = await fixer.fixMetaTags(options.directory);
691
- const filesFixed = fixResults.filter(r => r.status === 'fixed').length;
692
- const totalFixes = fixResults.reduce((sum, r) => sum + (r.fixes || 0), 0);
693
-
694
- console.log(chalk.green(`\n✅ Xử lý hoàn tất: ${fixResults.length} file`));
695
- if (filesFixed > 0) {
696
- console.log(chalk.green(` ✅ Đã sửa: ${filesFixed} file (${totalFixes} vấn đề)`));
697
- } else {
698
- console.log(chalk.green(` ✅ Không có lỗi cú pháp hoặc chính tả cần sửa`));
699
- }
700
- console.log(chalk.gray('💡 Chức năng này sửa lỗi chính tả OG property và cú pháp sai (name= thay vì property=)'));
701
-
702
- showCompletionMessage(options, 'Sửa Meta Tags');
703
- return;
704
734
  }
705
735
 
706
736
  } catch (error) {
@@ -710,4 +740,4 @@ async function main() {
710
740
  }
711
741
 
712
742
  // Run the CLI
713
- main();
743
+ main();