@knowcode/doc-builder 1.2.8 → 1.2.10
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/CHANGELOG.md +28 -0
- package/lib/core-builder.js +85 -9
- package/lib/deploy.js +78 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,34 @@ All notable changes to @knowcode/doc-builder will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.2.10] - 2025-07-19
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **Critical fix**: Now properly replaces old directory listing index.html files
|
|
12
|
+
- Detects and replaces index.html if it's under 3KB (likely a directory listing)
|
|
13
|
+
- Detects and replaces index.html if it doesn't contain doc-builder markers
|
|
14
|
+
- Fixes the issue where gasworld.vercel.app showed a directory listing instead of documentation
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- Smart detection of outdated or non-doc-builder index.html files
|
|
18
|
+
- Automatic replacement of directory listing pages with proper documentation
|
|
19
|
+
- Clear logging when replacing an existing index.html file
|
|
20
|
+
|
|
21
|
+
## [1.2.9] - 2025-07-19
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- Comprehensive console logging for debugging index.html creation
|
|
25
|
+
- Detailed file existence checks with paths and sizes
|
|
26
|
+
- File copy verification with size comparison
|
|
27
|
+
- List of HTML files found during build and deployment
|
|
28
|
+
- Error handling with detailed error messages
|
|
29
|
+
- Final verification step to confirm index.html exists
|
|
30
|
+
|
|
31
|
+
### Improved
|
|
32
|
+
- Much more verbose output to help diagnose deployment issues
|
|
33
|
+
- Clear indication of what files are being processed
|
|
34
|
+
- Better error reporting when file operations fail
|
|
35
|
+
|
|
8
36
|
## [1.2.8] - 2025-07-19
|
|
9
37
|
|
|
10
38
|
### Changed
|
package/lib/core-builder.js
CHANGED
|
@@ -460,6 +460,14 @@ async function buildDocumentation(config) {
|
|
|
460
460
|
const files = await getAllMarkdownFiles(docsDir);
|
|
461
461
|
console.log(chalk.green(`✅ Found ${files.length} markdown files${readmeGenerated ? ' (including auto-generated README)' : ''}`));
|
|
462
462
|
|
|
463
|
+
// Log the files found
|
|
464
|
+
if (files.length > 0) {
|
|
465
|
+
console.log(chalk.gray(' Found files:'));
|
|
466
|
+
files.forEach(file => {
|
|
467
|
+
console.log(chalk.gray(` - ${file.relativePath} → ${file.urlPath}`));
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
|
|
463
471
|
console.log(chalk.blue('📝 Processing files...'));
|
|
464
472
|
for (const file of files) {
|
|
465
473
|
const outputPath = path.join(outputDir, file.urlPath);
|
|
@@ -499,23 +507,91 @@ async function buildDocumentation(config) {
|
|
|
499
507
|
const indexSourcePath = path.join(outputDir, 'index.html'); // from index.md
|
|
500
508
|
const readmePath = path.join(outputDir, 'README.html');
|
|
501
509
|
|
|
502
|
-
console.log(chalk.blue('📄 Checking for index.html creation...'));
|
|
503
|
-
console.log(chalk.gray(` -
|
|
504
|
-
console.log(chalk.gray(` -
|
|
510
|
+
console.log(chalk.blue('\n📄 Checking for index.html creation...'));
|
|
511
|
+
console.log(chalk.gray(` - Output directory: ${outputDir}`));
|
|
512
|
+
console.log(chalk.gray(` - Index path: ${indexPath}`));
|
|
513
|
+
console.log(chalk.gray(` - README path: ${readmePath}`));
|
|
514
|
+
console.log(chalk.gray(` - index.html exists: ${fs.existsSync(indexPath)}`));
|
|
515
|
+
console.log(chalk.gray(` - README.html exists: ${fs.existsSync(readmePath)}`));
|
|
516
|
+
|
|
517
|
+
// List all HTML files in output directory
|
|
518
|
+
if (fs.existsSync(outputDir)) {
|
|
519
|
+
const htmlFiles = fs.readdirSync(outputDir).filter(f => f.endsWith('.html'));
|
|
520
|
+
console.log(chalk.gray(` - HTML files in output: [${htmlFiles.join(', ')}]`));
|
|
521
|
+
} else {
|
|
522
|
+
console.log(chalk.red(` - ERROR: Output directory does not exist!`));
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// Check if we need to create/replace index.html
|
|
526
|
+
let shouldCreateIndex = false;
|
|
505
527
|
|
|
506
528
|
if (!fs.existsSync(indexPath)) {
|
|
529
|
+
console.log(chalk.yellow('⚠️ index.html does not exist, need to create it'));
|
|
530
|
+
shouldCreateIndex = true;
|
|
531
|
+
} else {
|
|
532
|
+
// Check if existing index.html is likely a directory listing or outdated
|
|
533
|
+
const indexStats = fs.statSync(indexPath);
|
|
534
|
+
const indexContent = fs.readFileSync(indexPath, 'utf8');
|
|
535
|
+
|
|
536
|
+
// Check if it's a small file (likely directory listing) or contains directory listing markers
|
|
537
|
+
if (indexStats.size < 3000 || indexContent.includes('<title>Documentation</title>') && indexContent.includes('<ul>') && !indexContent.includes('class="navigation"')) {
|
|
538
|
+
console.log(chalk.yellow('⚠️ Existing index.html appears to be a directory listing (size: ' + indexStats.size + ' bytes), will replace it'));
|
|
539
|
+
shouldCreateIndex = true;
|
|
540
|
+
} else if (!indexContent.includes('@knowcode/doc-builder')) {
|
|
541
|
+
console.log(chalk.yellow('⚠️ Existing index.html was not created by doc-builder, will replace it'));
|
|
542
|
+
shouldCreateIndex = true;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (shouldCreateIndex) {
|
|
507
547
|
if (fs.existsSync(readmePath)) {
|
|
508
|
-
|
|
509
|
-
|
|
548
|
+
console.log(chalk.blue(' → Found README.html, copying to index.html'));
|
|
549
|
+
try {
|
|
550
|
+
await fs.copy(readmePath, indexPath);
|
|
551
|
+
console.log(chalk.green('✅ Successfully created index.html from README.html'));
|
|
552
|
+
|
|
553
|
+
// Verify the copy worked
|
|
554
|
+
if (fs.existsSync(indexPath)) {
|
|
555
|
+
const stats = fs.statSync(indexPath);
|
|
556
|
+
console.log(chalk.gray(` - index.html size: ${stats.size} bytes`));
|
|
557
|
+
} else {
|
|
558
|
+
console.log(chalk.red(' - ERROR: index.html was not created!'));
|
|
559
|
+
}
|
|
560
|
+
} catch (error) {
|
|
561
|
+
console.log(chalk.red(` - ERROR copying README.html: ${error.message}`));
|
|
562
|
+
}
|
|
510
563
|
} else {
|
|
511
564
|
// No README.html, create informative default page
|
|
512
565
|
console.log(chalk.yellow('⚠️ No README.html found, creating default index.html'));
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
566
|
+
try {
|
|
567
|
+
const defaultIndex = await createDefaultIndexPage(outputDir, config, packageJson.version);
|
|
568
|
+
await fs.writeFile(indexPath, defaultIndex);
|
|
569
|
+
console.log(chalk.green('✅ Created default index.html with instructions'));
|
|
570
|
+
|
|
571
|
+
// Verify the write worked
|
|
572
|
+
if (fs.existsSync(indexPath)) {
|
|
573
|
+
const stats = fs.statSync(indexPath);
|
|
574
|
+
console.log(chalk.gray(` - index.html size: ${stats.size} bytes`));
|
|
575
|
+
} else {
|
|
576
|
+
console.log(chalk.red(' - ERROR: default index.html was not created!'));
|
|
577
|
+
}
|
|
578
|
+
} catch (error) {
|
|
579
|
+
console.log(chalk.red(` - ERROR creating default index.html: ${error.message}`));
|
|
580
|
+
}
|
|
516
581
|
}
|
|
517
582
|
} else {
|
|
518
|
-
console.log(chalk.gray('ℹ️ index.html already exists
|
|
583
|
+
console.log(chalk.gray('ℹ️ index.html already exists and appears valid'));
|
|
584
|
+
const stats = fs.statSync(indexPath);
|
|
585
|
+
console.log(chalk.gray(` - Existing index.html size: ${stats.size} bytes`));
|
|
586
|
+
console.log(chalk.gray(` - Keeping existing index.html (likely from index.md or custom page)`));
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// Final verification
|
|
590
|
+
console.log(chalk.blue('\n📋 Final index.html check:'));
|
|
591
|
+
if (fs.existsSync(indexPath)) {
|
|
592
|
+
console.log(chalk.green(` ✅ index.html exists at: ${indexPath}`));
|
|
593
|
+
} else {
|
|
594
|
+
console.log(chalk.red(` ❌ index.html is MISSING at: ${indexPath}`));
|
|
519
595
|
}
|
|
520
596
|
|
|
521
597
|
console.log(chalk.green('✅ Documentation build complete!'));
|
package/lib/deploy.js
CHANGED
|
@@ -346,17 +346,73 @@ async function prepareDeployment(config) {
|
|
|
346
346
|
console.log(chalk.blue(`\n📦 Preparing deployment with @knowcode/doc-builder v${packageJson.version}`));
|
|
347
347
|
|
|
348
348
|
// Create index.html from README.html if needed
|
|
349
|
+
console.log(chalk.blue('\n📁 Deployment preparation - index.html check:'));
|
|
349
350
|
const indexPath = path.join(outputDir, 'index.html');
|
|
350
|
-
|
|
351
|
+
const readmePath = path.join(outputDir, 'README.html');
|
|
352
|
+
|
|
353
|
+
console.log(chalk.gray(` - Output directory: ${outputDir}`));
|
|
354
|
+
console.log(chalk.gray(` - Output dir exists: ${fs.existsSync(outputDir)}`));
|
|
355
|
+
|
|
356
|
+
if (fs.existsSync(outputDir)) {
|
|
357
|
+
const files = fs.readdirSync(outputDir);
|
|
358
|
+
const htmlFiles = files.filter(f => f.endsWith('.html'));
|
|
359
|
+
console.log(chalk.gray(` - Total files: ${files.length}`));
|
|
360
|
+
console.log(chalk.gray(` - HTML files: [${htmlFiles.slice(0, 5).join(', ')}${htmlFiles.length > 5 ? '...' : ''}]`));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
console.log(chalk.gray(` - Checking index.html: ${fs.existsSync(indexPath) ? 'exists' : 'missing'}`));
|
|
364
|
+
console.log(chalk.gray(` - Index path: ${indexPath}`));
|
|
365
|
+
|
|
366
|
+
// Check if we need to create/replace index.html
|
|
367
|
+
let shouldCreateIndex = false;
|
|
351
368
|
|
|
352
369
|
if (!fs.existsSync(indexPath)) {
|
|
353
|
-
|
|
354
|
-
|
|
370
|
+
console.log(chalk.yellow(' ⚠️ index.html is missing, attempting to create...'));
|
|
371
|
+
shouldCreateIndex = true;
|
|
372
|
+
} else {
|
|
373
|
+
// Check if existing index.html needs replacement
|
|
374
|
+
const indexStats = fs.statSync(indexPath);
|
|
375
|
+
const indexContent = fs.readFileSync(indexPath, 'utf8');
|
|
376
|
+
|
|
377
|
+
if (indexStats.size < 3000 || (indexContent.includes('<title>Documentation</title>') && indexContent.includes('<ul>') && !indexContent.includes('class="navigation"'))) {
|
|
378
|
+
console.log(chalk.yellow(` ⚠️ Existing index.html appears to be a directory listing (${indexStats.size} bytes), will replace`));
|
|
379
|
+
shouldCreateIndex = true;
|
|
380
|
+
} else if (!indexContent.includes('@knowcode/doc-builder')) {
|
|
381
|
+
console.log(chalk.yellow(' ⚠️ Existing index.html was not created by doc-builder, will replace'));
|
|
382
|
+
shouldCreateIndex = true;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (shouldCreateIndex) {
|
|
387
|
+
console.log(chalk.gray(` - Checking README.html: ${fs.existsSync(readmePath) ? 'exists' : 'missing'}`));
|
|
388
|
+
console.log(chalk.gray(` - README path: ${readmePath}`));
|
|
355
389
|
|
|
356
390
|
if (fs.existsSync(readmePath)) {
|
|
357
391
|
// Copy README.html to index.html for proper root page
|
|
358
|
-
|
|
359
|
-
|
|
392
|
+
console.log(chalk.blue(' → Copying README.html to index.html...'));
|
|
393
|
+
try {
|
|
394
|
+
fs.copyFileSync(readmePath, indexPath);
|
|
395
|
+
console.log(chalk.green(' ✅ Successfully copied README.html to index.html'));
|
|
396
|
+
|
|
397
|
+
// Verify the copy
|
|
398
|
+
if (fs.existsSync(indexPath)) {
|
|
399
|
+
const readmeStats = fs.statSync(readmePath);
|
|
400
|
+
const indexStats = fs.statSync(indexPath);
|
|
401
|
+
console.log(chalk.gray(` - README.html size: ${readmeStats.size} bytes`));
|
|
402
|
+
console.log(chalk.gray(` - index.html size: ${indexStats.size} bytes`));
|
|
403
|
+
|
|
404
|
+
if (readmeStats.size === indexStats.size) {
|
|
405
|
+
console.log(chalk.green(' ✅ File sizes match - copy successful'));
|
|
406
|
+
} else {
|
|
407
|
+
console.log(chalk.yellow(' ⚠️ File sizes do not match!'));
|
|
408
|
+
}
|
|
409
|
+
} else {
|
|
410
|
+
console.log(chalk.red(' ❌ ERROR: index.html was not created after copy!'));
|
|
411
|
+
}
|
|
412
|
+
} catch (error) {
|
|
413
|
+
console.log(chalk.red(` ❌ ERROR copying file: ${error.message}`));
|
|
414
|
+
console.log(chalk.red(` - Error stack: ${error.stack}`));
|
|
415
|
+
}
|
|
360
416
|
} else {
|
|
361
417
|
// If no README.html, find first available HTML file or create informative page
|
|
362
418
|
console.log(chalk.yellow('⚠️ No README.html found, looking for other HTML files...'));
|
|
@@ -403,16 +459,31 @@ async function prepareDeployment(config) {
|
|
|
403
459
|
}
|
|
404
460
|
}
|
|
405
461
|
} else {
|
|
406
|
-
console.log(chalk.gray(' ✓ index.html already exists'));
|
|
462
|
+
console.log(chalk.gray(' ✓ index.html already exists and appears valid'));
|
|
463
|
+
const stats = fs.statSync(indexPath);
|
|
464
|
+
console.log(chalk.gray(` - Keeping existing index.html (${stats.size} bytes)`));
|
|
407
465
|
}
|
|
408
466
|
|
|
409
467
|
// Final check - log what files exist
|
|
410
468
|
console.log(chalk.blue('\n📁 Final deployment state:'));
|
|
469
|
+
|
|
470
|
+
// Double-check index.html one more time
|
|
471
|
+
const finalIndexExists = fs.existsSync(indexPath);
|
|
472
|
+
console.log(chalk[finalIndexExists ? 'green' : 'red'](` - index.html: ${finalIndexExists ? 'EXISTS' : 'MISSING'}`));
|
|
473
|
+
|
|
474
|
+
if (finalIndexExists) {
|
|
475
|
+
const stats = fs.statSync(indexPath);
|
|
476
|
+
console.log(chalk.gray(` - index.html size: ${stats.size} bytes`));
|
|
477
|
+
console.log(chalk.gray(` - index.html modified: ${stats.mtime.toISOString()}`));
|
|
478
|
+
}
|
|
479
|
+
|
|
411
480
|
const finalFiles = fs.readdirSync(outputDir)
|
|
412
481
|
.filter(file => file.endsWith('.html'))
|
|
413
482
|
.slice(0, 5); // Show first 5 HTML files
|
|
483
|
+
console.log(chalk.gray(`\n HTML files in ${outputDir}:`));
|
|
414
484
|
finalFiles.forEach(file => {
|
|
415
|
-
|
|
485
|
+
const size = fs.statSync(path.join(outputDir, file)).size;
|
|
486
|
+
console.log(chalk.gray(` - ${file} (${size} bytes)`));
|
|
416
487
|
});
|
|
417
488
|
if (fs.readdirSync(outputDir).filter(f => f.endsWith('.html')).length > 5) {
|
|
418
489
|
console.log(chalk.gray(` - ... and ${fs.readdirSync(outputDir).filter(f => f.endsWith('.html')).length - 5} more HTML files`));
|