-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepend.js
More file actions
80 lines (72 loc) · 3.57 KB
/
Copy pathprepend.js
File metadata and controls
80 lines (72 loc) · 3.57 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
const fs = require('fs');
const htmlComment = `<!--
================================================================================
🌤️ SKYGLASS WEATHER SYSTEM - index.html
================================================================================
WHAT THIS FILE DOES:
This is the main structure (skeleton) of the website. It defines where all the
text, images, and layout boxes (cards) go.
HOW IT WORKS:
- Contains the search bar to find cities.
- Has empty placeholders (like id="temperature") that get filled by script.js.
- Links to style.css for colors/layout and script.js for interactive logic.
================================================================================
-->\n`;
const cssComment = `/*
================================================================================
🌤️ SKYGLASS WEATHER SYSTEM - style.css
================================================================================
WHAT THIS FILE DOES:
This is the "paint and layout" of the website. It takes the plain HTML skeleton
and makes it look beautiful, specifically giving it the responsive "glassmorphism" look.
HOW IT WORKS:
- Defines colors, fonts, and smooth animations (like hovering over buttons).
- Controls the "grid" layout so the cards fit nicely on both phones and big screens.
================================================================================
*/\n`;
const scriptComment = `/**
* ============================================================================
* 🌤️ SKYGLASS WEATHER SYSTEM - script.js
* ============================================================================
* WHAT THIS FILE DOES:
* This is the "brain" of the frontend user interface. It detects when a user
* types a city, fetches the data from our backend server, and updates the HTML.
*
* HOW IT WORKS FOR BEGINNERS:
* 1. The user types a city in the search bar.
* 2. script.js asks the backend server.js: "Hey, give me weather for London".
* 3. The server sends back a single JSON object with all the temperature, rain,
* and prediction data.
* 4. We find the exact HTML boxes (like document.getElementById('temperature'))
* and specifically change their internal text to the new data.
* ============================================================================
*/\n`;
const serverComment = `/**
* ============================================================================
* 🌤️ SKYGLASS WEATHER SYSTEM - server.js (The Backend)
* ============================================================================
* WHAT THIS FILE DOES:
* This is a Node.js Express server. It acts as a secure middleman between our
* website front-end and the raw data APIs (WeatherAPI & Open-Meteo).
*
* WHY WE NEED THIS FILE:
* - SECURITY: We NEVER put secret API keys in \`script.js\` because hackers can
* see them in the browser. The server hides them in a .env file.
* - PROCESSING: It takes messy data from 2 different APIs, passes it through
* our "Intelligence Engines" to create smart predictions, and sends ONE clean
* data package back to the website.
* ============================================================================
*/\n`;
function prepend(file, comment) {
if (fs.existsSync(file)) {
const content = fs.readFileSync(file, 'utf8');
if (!content.includes('🌤️ SKYGLASS WEATHER SYSTEM')) {
fs.writeFileSync(file, comment + content);
console.log('Commented: ' + file);
}
}
}
prepend('index.html', htmlComment);
prepend('style.css', cssComment);
prepend('script.js', scriptComment);
prepend('server.js', serverComment);