-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathbuild.mjs
More file actions
118 lines (103 loc) · 4 KB
/
build.mjs
File metadata and controls
118 lines (103 loc) · 4 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
import chalk from 'chalk';
import readline from 'readline';
import { buildFeaturedBlogs } from './build.blogs.featured.mjs';
import { buildBlogTags } from './build.blogs.tags.mjs';
import { prepForDocsChangelog } from './build.docs.changelog.mjs';
import { prepAndMoveFilesFromTempLocationToActual } from './build.lite.forprod.mjs';
import { prepForPreviewDeployment } from './build.preview.mjs';
import { automateTranslations } from './build.translation.automation.mjs';
/**
* Ask user for confirmation to continue
*/
const askToContinue = async (message) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return new Promise((resolve) => {
rl.question(message, (answer) => {
rl.close();
const normalizedAnswer = answer.toLowerCase().trim();
resolve(normalizedAnswer === 'y' || normalizedAnswer === 'yes');
});
});
};
// Prep for deployment starts everything
const prepForDeployment = async (appEnv, skipTranslation) => {
console.log(chalk.green('Starting Custom Deployment Prebuild...'));
// Check and move blogs back from temp location
await prepAndMoveFilesFromTempLocationToActual('full');
// Step 2: Do changelog in docs (future feature)
await prepForDocsChangelog();
// Step 2.5: Generate featured blogs JSON
console.log(chalk.cyan('\n📝 Step 2.5: Generating featured blogs JSON...'));
try {
await buildFeaturedBlogs();
console.log(chalk.green('✅ Featured blogs JSON generated successfully'));
} catch (error) {
console.warn(chalk.yellow('⚠️ Featured blogs generation failed'));
console.warn(chalk.gray(` Error: ${error.message}`));
}
// Step 2.6: Generate blog tags JSON
console.log(chalk.cyan('\n🏷️ Step 2.6: Generating blog tags JSON...'));
try {
await buildBlogTags();
console.log(chalk.green('✅ Blog tags JSON generated successfully'));
} catch (error) {
console.warn(chalk.yellow('⚠️ Blog tags generation failed'));
console.warn(chalk.gray(` Error: ${error.message}`));
}
// Step 3: Automated translation generation with MD5 checksum tracking
console.log(
chalk.cyan('\n🌍 Step 3: Running automated translation system...')
);
if (skipTranslation === 'skip_translation') {
console.log(
chalk.green('⏩ Skipping Translation as indicated in the params...')
);
} else {
try {
await automateTranslations();
console.log(chalk.green('✅ Automated translation system completed'));
} catch (error) {
// If API key is missing or invalid, halt the build process
if (
error.message.includes(
'WINDSURF_API_KEY environment variable is required'
) ||
error.message.includes('Invalid WINDSURF_API_KEY')
) {
console.error(
chalk.red('🛑 Translation process halted due to API key issue')
);
process.exit(1); // Exit immediately for API key issues
}
// For other translation errors, ask user if they want to continue
console.warn(chalk.yellow('⚠️ Automated translation failed'));
console.warn(chalk.gray(` Error: ${error.message}`));
console.log(chalk.cyan('\n📋 You have two options:'));
console.log(
chalk.white(' 1. Continue with existing translations (if any)')
);
console.log(
chalk.white(' 2. Halt the build to fix the translation issue')
);
const shouldContinue = await askToContinue(
chalk.blue('\nDo you want to continue with the build? (y/N): ')
);
if (!shouldContinue) {
console.log(chalk.red('🛑 Build process halted by user choice'));
console.log(
chalk.gray(' Fix the translation issue and run the build again')
);
process.exit(1);
} else {
console.log(chalk.green('✅ Continuing with existing translations...'));
}
}
}
// Step 4: Do preview deployment
await prepForPreviewDeployment(appEnv);
};
var args = process.argv.slice(2);
await prepForDeployment(args[0], args[1]);