Skip to content

Commit f3c1ae0

Browse files
committed
Create generate.js
1 parent 13bab4f commit f3c1ae0

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

scripts/generate.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { execSync } = require('child_process');
4+
5+
// Console colors
6+
const colors = {
7+
reset: '\x1b[0m',
8+
green: '\x1b[32m',
9+
red: '\x1b[31m',
10+
blue: '\x1b[34m',
11+
yellow: '\x1b[33m'
12+
};
13+
14+
// Utility functions
15+
const utils = {
16+
logSuccess(message) {
17+
console.log(`${colors.green}${message}${colors.reset}`);
18+
},
19+
20+
logError(message, error) {
21+
console.error(`${colors.red}${message}${colors.reset}`);
22+
if (error) {
23+
console.error(`${colors.red}${error.stack}${colors.reset}`);
24+
}
25+
},
26+
27+
logInfo(message) {
28+
console.log(`${colors.blue}${message}${colors.reset}`);
29+
},
30+
31+
logWarning(message) {
32+
console.log(`${colors.yellow}${message}${colors.reset}`);
33+
}
34+
};
35+
36+
// Main generator class
37+
class SiteGenerator {
38+
constructor() {
39+
this.scriptDir = __dirname;
40+
this.rootDir = path.join(this.scriptDir, '..');
41+
}
42+
43+
async generate() {
44+
try {
45+
utils.logInfo('Starting site generation...');
46+
47+
// Step 1: Run the build script to generate language pages
48+
utils.logInfo('Generating language pages...');
49+
await this.runScript('build.js');
50+
51+
utils.logSuccess('Site generation completed successfully!');
52+
} catch (error) {
53+
utils.logError('Failed to generate site', error);
54+
process.exit(1);
55+
}
56+
}
57+
58+
async runScript(scriptName) {
59+
try {
60+
const scriptPath = path.join(this.scriptDir, scriptName);
61+
62+
// Check if script exists
63+
if (!fs.existsSync(scriptPath)) {
64+
throw new Error(`Script not found: ${scriptPath}`);
65+
}
66+
67+
// Run the script
68+
require(scriptPath);
69+
return true;
70+
} catch (error) {
71+
utils.logError(`Failed to run script: ${scriptName}`, error);
72+
throw error;
73+
}
74+
}
75+
}
76+
77+
// Run generator
78+
const generator = new SiteGenerator();
79+
generator.generate().catch(error => {
80+
utils.logError('Fatal error during site generation', error);
81+
process.exit(1);
82+
});

0 commit comments

Comments
 (0)