File size: 1,668 Bytes
51bdde0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const projectRoot = path.resolve(__dirname, '..');
const docsDistPath = path.join(projectRoot, 'docs', '.vitepress', 'dist');
const mainDistPath = path.join(projectRoot, 'dist');
const targetDocsPath = path.join(mainDistPath, 'docs');

function copyDir(src, dest) {
    if (!fs.existsSync(dest)) {
        fs.mkdirSync(dest, { recursive: true });
    }

    const entries = fs.readdirSync(src, { withFileTypes: true });

    for (const entry of entries) {
        const srcPath = path.join(src, entry.name);
        const destPath = path.join(dest, entry.name);

        if (entry.isDirectory()) {
            copyDir(srcPath, destPath);
        } else {
            fs.copyFileSync(srcPath, destPath);
        }
    }
}

console.log('Including docs in dist...');

if (!fs.existsSync(docsDistPath)) {
    console.error('Error: Docs build not found. Please run "npm run docs:build" first.');
    process.exit(1);
}
if (!fs.existsSync(mainDistPath)) {
    console.error('Error: Main dist folder not found. Please run "npm run build" first.');
    process.exit(1);
}

try {
    console.log(`Copying from: ${docsDistPath}`);
    console.log(`Copying to: ${targetDocsPath}`);

    copyDir(docsDistPath, targetDocsPath);

    console.log('Docs successfully included in dist/docs!');

    const files = fs.readdirSync(targetDocsPath);
    console.log(`Copied ${files.length} items to dist/docs`);
} catch (error) {
    console.error('Error copying docs:', error.message);
    process.exit(1);
}