-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (110 loc) · 3.6 KB
/
Copy pathMakefile
File metadata and controls
124 lines (110 loc) · 3.6 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
# Makefile for comm-agent-IA project
# HTML source files to watch
HTML_FILES = pitch-commercial.html agent-interne.html agent-public.html
# Server configuration
PORT = 8000
# Default target
.PHONY: build
build:
@echo "Building navigation page..."
@node build-navigation.js
@echo "Navigation page built successfully!"
# Watch mode - rebuild on HTML file changes
.PHONY: watch
watch:
@echo "Starting watch mode..."
@node build-navigation.js --watch
# Development mode with auto-rebuild
.PHONY: dev
dev: watch
# Static file server using inline Node.js code
.PHONY: serve
serve:
@echo "Starting static HTTP server on port $(PORT)..."
@echo "Open http://localhost:$(PORT) in your browser"
@echo "Press Ctrl+C to stop the server"
@node -e " \
const http = require('http'); \
const fs = require('fs'); \
const path = require('path'); \
const url = require('url'); \
const mimes = { \
'.html': 'text/html', \
'.css': 'text/css', \
'.js': 'application/javascript', \
'.json': 'application/json', \
'.webp': 'image/webp', \
'.svg': 'image/svg+xml', \
'.csv': 'text/csv', \
'.md': 'text/markdown', \
'.txt': 'text/plain' \
}; \
http.createServer((req, res) => { \
let pathname = url.parse(req.url).pathname; \
if (pathname === '/') pathname = '/index.html'; \
const filePath = path.join(__dirname, pathname); \
fs.readFile(filePath, (err, data) => { \
if (err) { \
res.writeHead(404, { 'Content-Type': 'text/plain' }); \
res.end('404 - File Not Found'); \
console.log('404:', pathname); \
return; \
} \
const ext = path.extname(filePath); \
const contentType = mimes[ext] || 'application/octet-stream'; \
res.writeHead(200, { 'Content-Type': contentType }); \
res.end(data); \
console.log('200:', pathname); \
}); \
}).listen($(PORT), () => { \
console.log('Static HTTP server running at http://localhost:$(PORT)'); \
console.log('Press Ctrl+C to stop the server'); \
}); \
"
# Development server: serve + watch in parallel
.PHONY: start
start: build
@echo "Starting development environment..."
@echo "- HTTP server on http://localhost:$(PORT)"
@echo "- Auto-rebuild on file changes"
@echo "Press Ctrl+C to stop both server and watch"
@trap 'kill %1 %2 2>/dev/null; exit' INT; \
make serve & \
make watch & \
wait
# Legacy alias for dev-serve
.PHONY: dev-serve
dev-serve: start
# Build only if HTML files are newer than index.html
.PHONY: build-if-needed
build-if-needed: index.html
index.html: $(HTML_FILES) build-navigation.js
@echo "HTML files changed, rebuilding navigation..."
@node build-navigation.js
@echo "Navigation page updated!"
# Clean target
.PHONY: clean
clean:
@echo "Cleaning generated files..."
@rm -f index.html
@echo "Clean completed!"
# Install dependencies (if needed)
.PHONY: install
install:
@echo "No dependencies to install for this static project"
# Help target
.PHONY: help
help:
@echo "Available targets:"
@echo " build - Build the navigation page once"
@echo " watch - Watch HTML files and rebuild automatically"
@echo " dev - Alias for watch (development mode)"
@echo " serve - Start static HTTP server only"
@echo " start - Start HTTP server + watch (recommended for development)"
@echo " dev-serve - Alias for start"
@echo " build-if-needed - Build only if HTML files are newer than index.html"
@echo " clean - Remove generated index.html file"
@echo " install - Install dependencies (none needed)"
@echo " help - Show this help message"
# Default target when just running 'make'
.DEFAULT_GOAL := build