-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_book.sh
More file actions
executable file
·96 lines (87 loc) · 1.95 KB
/
build_book.sh
File metadata and controls
executable file
·96 lines (87 loc) · 1.95 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
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored messages
print_message() {
echo -e "${BLUE}[Rust Async Book]${NC} $1"
}
# Function to print success messages
print_success() {
echo -e "${GREEN}[Success]${NC} $1"
}
# Function to print error messages
print_error() {
echo -e "${RED}[Error]${NC} $1"
}
# Check if mdbook is installed
if ! command -v mdbook &> /dev/null; then
print_error "mdBook is not installed. Installing..."
cargo install mdbook
if [ $? -eq 0 ]; then
print_success "mdBook installed successfully"
else
print_error "Failed to install mdBook"
exit 1
fi
fi
# Function to build the book
build_book() {
print_message "Building the book..."
cd book
mdbook build
if [ $? -eq 0 ]; then
print_success "Book built successfully"
else
print_error "Failed to build book"
exit 1
fi
cd ..
}
# Function to serve the book
serve_book() {
print_message "Starting development server..."
cd book
mdbook serve
if [ $? -eq 0 ]; then
print_success "Development server started"
else
print_error "Failed to start development server"
exit 1
fi
cd ..
}
# Function to clean build artifacts
clean() {
print_message "Cleaning build artifacts..."
cd book
rm -rf book
if [ $? -eq 0 ]; then
print_success "Build artifacts cleaned successfully"
else
print_error "Failed to clean build artifacts"
exit 1
fi
cd ..
}
# Parse command line arguments
case "$1" in
"build")
build_book
;;
"serve")
serve_book
;;
"clean")
clean
;;
*)
echo "Usage: $0 {build|serve|clean}"
echo " build - Build the book"
echo " serve - Start development server"
echo " clean - Clean build artifacts"
exit 1
;;
esac