Repository navigation
Expand file tree
/
Copy pathprebuild.js
More file actions
74 lines (60 loc) · 2.09 KB
/
Copy pathprebuild.js
File metadata and controls
74 lines (60 loc) · 2.09 KB
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
#!/usr/bin/env node
/**
* Pre-build script for Docusaurus
* Handles dynamic configuration based on environment variables
*
* Usage:
* node prebuild.js - Setup for build/start
* node prebuild.js clean - Clean generated files
*/
const fs = require('node:fs');
const path = require('node:path');
// Check if running in clean mode
const isCleanMode = process.argv[2] === 'clean';
// Get the route base path from environment variable
const routeBasePath = process.env.DOCUSAURUS_ROUTE_BASE_PATH || '/';
const indexPagePath = path.join(__dirname, '../src/pages/index.tsx');
const pagesDir = path.join(__dirname, '../src/pages');
// Helper function to remove the index page
function removeIndexPage() {
if (fs.existsSync(indexPagePath)) {
fs.unlinkSync(indexPagePath);
console.log('Removed index.tsx');
return true;
}
return false;
}
if (isCleanMode) {
// Clean mode - remove all generated files
console.log('Cleaning generated files...');
removeIndexPage();
process.exit(0);
}
console.log('Running pre-build setup...');
console.log(`Route base path: ${routeBasePath}`);
// Setup index redirect page based on route configuration
if (routeBasePath === '/') {
// If docs are at root, remove the index redirect page
console.log('Docs are at root (/), removing index redirect page, if it exists...');
removeIndexPage();
} else {
// If docs are not at root, ensure the index redirect page exists
console.log(`Docs are at ${routeBasePath}, creating index redirect page...`);
// Create pages directory if it doesn't exist
if (!fs.existsSync(pagesDir)) {
fs.mkdirSync(pagesDir, { recursive: true });
}
// Create the redirect page
const redirectContent = `import React from 'react';
import { Redirect } from '@docusaurus/router';
export default function Home(): JSX.Element {
// Redirect to the docs location
return <Redirect to="${routeBasePath}" />;
}
`;
fs.writeFileSync(indexPagePath, redirectContent);
console.log(`Created index redirect to ${routeBasePath}`);
}
// Generate release notes data
console.log('Generating release notes data...');
require('./generateReleaseNotesData')();