-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-versions.js
More file actions
156 lines (128 loc) · 4.27 KB
/
build-versions.js
File metadata and controls
156 lines (128 loc) · 4.27 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
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
/**
* Build script for versioned API documentation
*
* This script:
* 1. Creates directory structure for different API versions
* 2. Copies the appropriate files to each version directory
* 3. Updates paths and references in the files
* 4. Generates version-specific schema files if needed
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Available versions to build
const versions = [
{
version: '1.1.0',
path: 'v1.1.0',
schemaUrl: 'https://api.flashapp.me/graphql',
date: '2024-05-05'
},
{
version: '1.0.0',
path: '', // Root directory for the current stable version
schemaUrl: 'https://api.flashapp.me/graphql',
date: '2024-04-10'
},
{
version: 'beta',
path: 'beta',
schemaUrl: 'https://api.test.flashapp.me/graphql',
date: 'Current'
}
];
// Build directory (default is 'public')
const BUILD_DIR = path.join(__dirname, 'public');
// Source directory
const SRC_DIR = path.join(__dirname, 'src');
// Create version directories and copy files
async function buildVersionedDocs() {
try {
console.log('Starting versioned build process...');
// Create build directory if it doesn't exist
if (!fs.existsSync(BUILD_DIR)) {
fs.mkdirSync(BUILD_DIR, { recursive: true });
}
// Build each version
for (const version of versions) {
await buildVersion(version);
}
// Create version manifest file
createVersionManifest();
console.log('Versioned build complete!');
} catch (error) {
console.error('Error building versioned docs:', error);
process.exit(1);
}
}
/**
* Build a specific version of the documentation
*/
async function buildVersion(version) {
console.log(`Building version ${version.version}...`);
// Create version directory
const versionDir = path.join(BUILD_DIR, version.path);
if (version.path && !fs.existsSync(versionDir)) {
fs.mkdirSync(versionDir, { recursive: true });
}
// For root version (current stable), we'll use the main build process
if (!version.path) {
return;
}
// Copy files from public to version directory
console.log(`Copying files to ${versionDir}...`);
// Copy all files from public to version directory
execSync(`cp -r ${BUILD_DIR}/* ${versionDir}/`);
// Update paths in HTML files to reference version-specific files
updatePaths(versionDir, version);
console.log(`Version ${version.version} built successfully`);
}
/**
* Update paths in HTML files to reference version-specific files
*/
function updatePaths(versionDir, version) {
// Update index.html
const indexPath = path.join(versionDir, 'index.html');
if (fs.existsSync(indexPath)) {
let content = fs.readFileSync(indexPath, 'utf8');
// Add version information to the page
content = content.replace(
/<div class="logo">/,
`<div class="logo">
<div class="version-badge" style="background: rgba(0,0,0,0.2); border-radius: 4px; padding: 2px 8px; font-size: 0.8rem; margin-right: 10px;">${version.version}</div>`
);
// Write updated content
fs.writeFileSync(indexPath, content);
}
// Update spec.html
const specPath = path.join(versionDir, 'spec.html');
if (fs.existsSync(specPath)) {
let content = fs.readFileSync(specPath, 'utf8');
// Add version information to the page
content = content.replace(
/<a href="index\.html" class="back-link">/,
`<a href="index.html" class="back-link">
<span class="version-badge" style="background: rgba(0,0,0,0.2); border-radius: 4px; padding: 2px 8px; font-size: 0.8rem; margin-right: 10px;">${version.version}</span>`
);
// Write updated content
fs.writeFileSync(specPath, content);
}
}
/**
* Create a version manifest file that lists all available versions
*/
function createVersionManifest() {
const manifestPath = path.join(BUILD_DIR, 'versions.json');
const manifest = {
versions: versions.map(v => ({
version: v.version,
path: v.path || '/',
date: v.date
})),
latest: versions.find(v => v.version !== 'beta') || versions[0]
};
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
console.log('Version manifest created');
}
// Run the build process
buildVersionedDocs();