Repository navigation
Expand file tree
/
Copy pathbuild.js
More file actions
176 lines (159 loc) · 5.7 KB
/
Copy pathbuild.js
File metadata and controls
176 lines (159 loc) · 5.7 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env node
/**
* Rehba Dev Website - Main Build Script
* =====================================
* يقوم بتشغيل:
* 1. apps/build.js - تحديث صفحات المشاريع في أماكنها
* 2. apps/screenshot.js - التقاط صور للشاشات (اختياري)
* 3. إنشاء مجلد projects/ يحتوي صفحات عرض (landing pages) فقط
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
console.log('🚀 Starting Main Build Process...\n');
// Verify required files exist
const APPS_BUILD_SCRIPT = path.join(__dirname, 'apps', 'build.js');
if (!fs.existsSync(APPS_BUILD_SCRIPT)) {
console.error('❌ apps/build.js not found!');
console.error('Expected path:', APPS_BUILD_SCRIPT);
process.exit(1);
}
// Step 1: Run apps/build.js to update projects in place
console.log('📦 Step 1: Updating project pages...');
try {
execSync('node apps/build.js', { stdio: 'inherit', cwd: __dirname });
console.log('✅ Project pages updated\n');
} catch (error) {
console.error('❌ Error updating project pages:', error.message);
console.error('Error details:', error);
process.exit(1);
}
// Step 2: Optional - Run screenshot.js (only if needed)
// Uncomment if you want to auto-generate screenshots
// console.log('📸 Step 2: Generating screenshots...');
// try {
// execSync('node apps/screenshot.js', { stdio: 'inherit' });
// console.log('✅ Screenshots generated\n');
// } catch (error) {
// console.warn('⚠️ Screenshot generation skipped or failed\n');
// }
// Step 3: Generate projects/ directory with landing pages
console.log('🏗️ Step 3: Generating projects landing pages...');
generateProjectsDirectory();
console.log('\n✨ Build Complete!');
/**
* إنشاء مجلد projects/ مع صفحات عرض بسيطة لكل مشروع
*/
function generateProjectsDirectory() {
const PROJECTS_DIR = path.join(__dirname, 'projects');
const APPS_DIR = path.join(__dirname, 'apps');
const PROJECTS_JSON = path.join(__dirname, 'site', 'assets', 'data', 'projects.json');
// Read projects.json
if (!fs.existsSync(PROJECTS_JSON)) {
console.warn('⚠️ projects.json not found, skipping projects generation');
console.warn('Expected path:', PROJECTS_JSON);
return;
}
let projects;
try {
projects = JSON.parse(fs.readFileSync(PROJECTS_JSON, 'utf8'));
console.log(`📄 Loaded ${projects.length} projects from projects.json`);
} catch (error) {
console.error('❌ Error reading projects.json:', error.message);
return;
}
// Create projects/ directory
if (!fs.existsSync(PROJECTS_DIR)) {
fs.mkdirSync(PROJECTS_DIR, { recursive: true });
console.log('📁 Created projects/ directory');
}
// Generate landing page for each project
let successCount = 0;
projects.forEach(project => {
try {
const projectDir = path.join(PROJECTS_DIR, project.id);
if (!fs.existsSync(projectDir)) {
fs.mkdirSync(projectDir, { recursive: true });
}
// Create simple landing page that redirects to apps/{project}/
const landingPage = `<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${project.title}</title>
<meta http-equiv="refresh" content="0; url=../../apps/${project.id}/">
<style>
body {
margin: 0;
padding: 0;
font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
color: white;
}
.container {
text-align: center;
padding: 2rem;
}
h1 {
font-size: 2rem;
margin-bottom: 1rem;
}
p {
font-size: 1.2rem;
opacity: 0.9;
}
.spinner {
border: 4px solid rgba(255,255,255,0.3);
border-top: 4px solid white;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 2rem auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
a {
color: white;
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>${project.title}</h1>
<p>جاري التحويل...</p>
<div class="spinner"></div>
<p style="font-size: 0.9rem;">
إذا لم يتم التحويل تلقائياً،
<a href="../../apps/${project.id}/">انقر هنا</a>
</p>
</div>
<script>
// Redirect after a short delay
setTimeout(() => {
window.location.href = '../../apps/${project.id}/';
}, 100);
</script>
</body>
</html>`;
fs.writeFileSync(path.join(projectDir, 'index.html'), landingPage);
console.log(` ✅ Generated landing page: projects/${project.id}/`);
successCount++;
} catch (error) {
console.error(` ❌ Failed to generate landing page for ${project.id}:`, error.message);
}
});
console.log(`\n📁 Successfully created ${successCount}/${projects.length} landing pages in projects/`);
if (successCount === 0) {
console.error('❌ No landing pages were created!');
process.exit(1);
}
}