-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-examples.js
More file actions
89 lines (76 loc) · 2.5 KB
/
update-examples.js
File metadata and controls
89 lines (76 loc) · 2.5 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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Configuration for updates
const updates = [
{
// Replace API keys
pattern: /const API_KEY = 'rhy_[^']+';/g,
replacement: "const API_KEY = 'YOUR_API_KEY_HERE'; // کلید API خود را اینجا قرار دهید"
},
{
// Replace localhost URLs
pattern: /const BASE_URL = 'http:\/\/localhost:3000\/api\/v1';/g,
replacement: "const BASE_URL = 'https://rahyana.ir/api/v1';"
},
{
// Replace localhost URLs with comments
pattern: /const BASE_URL = 'https:\/\/rahyana\.ir\/api\/v1'; \/\/ برای تست محلی از http:\/\/localhost:3000\/api\/v1 استفاده کنید/g,
replacement: "const BASE_URL = 'https://rahyana.ir/api/v1';"
},
{
// Update models to GPT
pattern: /model: 'anthropic\/claude-sonnet-4\.5',/g,
replacement: "model: 'openai/gpt-4o', // مدل GPT-4o - مدلهای محبوب: openai/gpt-4o, openai/gpt-4o-mini, openai/gpt-5"
},
{
// Update error messages to Farsi
pattern: /console\.error\('Error:', error\);/g,
replacement: "console.error('خطا:', error);"
},
{
// Update success messages to Farsi
pattern: /console\.log\('Success!'\);/g,
replacement: "console.log('موفق!');"
},
{
// Update failed messages to Farsi
pattern: /console\.error\('Failed:', error\);/g,
replacement: "console.error('ناموفق:', error);"
}
];
function updateFile(filePath) {
try {
let content = fs.readFileSync(filePath, 'utf8');
let updated = false;
updates.forEach(update => {
const newContent = content.replace(update.pattern, update.replacement);
if (newContent !== content) {
content = newContent;
updated = true;
}
});
if (updated) {
fs.writeFileSync(filePath, content, 'utf8');
console.log(`✅ Updated: ${filePath}`);
}
} catch (error) {
console.error(`❌ Error updating ${filePath}:`, error.message);
}
}
function walkDir(dir) {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
walkDir(filePath);
} else if (file.endsWith('.js') || file.endsWith('.py') || file.endsWith('.sh')) {
updateFile(filePath);
}
});
}
// Update all files in the github-examples directory
const examplesDir = path.join(__dirname);
walkDir(examplesDir);
console.log('🎉 All examples updated for publication!');