-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_functions.sh
More file actions
executable file
·193 lines (152 loc) · 5.18 KB
/
Copy pathbuild_functions.sh
File metadata and controls
executable file
·193 lines (152 loc) · 5.18 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
# Build functions for VCV Rack Module Search
# This file contains modular functions for the build process
# Source configuration
source "$(dirname "${BASH_SOURCE[0]}")/config.sh"
# Function to set up the build environment
setup_environment() {
log_info "Setting up build environment..."
# Create necessary directories
if ! mkdir -p "$CACHE_DIR" "$SITE_DIR"; then
log_error "Failed to create directories"
return 1
fi
# Check Python dependencies
if ! command -v python3 &> /dev/null; then
log_error "Python 3 is required but not installed"
return 1
fi
# Check if required Python modules are available
if ! python3 -c "import json, requests, PIL" &> /dev/null; then
log_error "Required Python modules not available (json, requests, PIL)"
return 1
fi
log_info "Build environment setup completed"
return 0
}
# Function to clone or update VCV library repository
clone_or_update_library() {
log_info "Processing VCV Rack library repository..."
if [ -d "$TARGET_DIR" ]; then
log_info "Directory '$TARGET_DIR' already exists. Pulling latest changes..."
if ! (cd "$TARGET_DIR" && git pull); then
log_error "Failed to update repository"
return 1
fi
log_info "Repository updated successfully"
else
log_info "Cloning repository into '$TARGET_DIR'..."
if ! git clone "$REPO_URL" "$TARGET_DIR"; then
log_error "Failed to clone repository"
return 1
fi
log_info "Repository cloned successfully"
fi
return 0
}
# Function to run data processing
run_data_processing() {
log_info "Running data processing (parsing manifests and downloading images)..."
if ! python3 process_data.py; then
log_error "Data processing failed"
return 1
fi
log_info "Data processing completed successfully"
return 0
}
# Function to generate search file
generate_search_file() {
log_info "Generating search file..."
if ! python3 generate_search_file.py; then
log_error "Search file generation failed"
return 1
fi
log_info "Search file generated successfully"
return 0
}
# Function to deploy files to site directory
deploy_files() {
log_info "Deploying files to site directory..."
# Create site directory structure
if ! mkdir -p "$SITE_DIR/images"; then
log_error "Failed to create site directory structure"
return 1
fi
# Copy main files
if ! cp index.html "$SITE_DIR/"; then
log_error "Failed to copy index.html"
return 1
fi
log_info "Copied index.html to site/"
if ! cp search_file.json "$SITE_DIR/"; then
log_error "Failed to copy search_file.json"
return 1
fi
log_info "Copied search_file.json to site/"
if ! cp fuzzy.js "$SITE_DIR/"; then
log_error "Failed to copy fuzzy.js"
return 1
fi
log_info "Copied fuzzy.js to site/"
# Copy cache images to site
if [ -d "$CACHE_DIR" ]; then
if ! cp -r "$CACHE_DIR/." "$SITE_DIR/images/"; then
log_error "Failed to copy cached images"
return 1
fi
log_info "Copied cached images to site/images/"
else
log_warn "Cache directory not found, skipping image copy"
fi
return 0
}
# Function to clean up build artifacts
cleanup_build() {
log_info "Cleaning up build artifacts..."
# Remove temporary files if they exist
if [ -f "parsed_plugins.json" ]; then
rm -f "parsed_plugins.json"
log_info "Removed parsed_plugins.json"
fi
return 0
}
# Function to validate build output
validate_build() {
log_info "Validating build output..."
# Check if required files exist
if [ ! -f "$SITE_DIR/index.html" ]; then
log_error "Missing index.html in site directory"
return 1
fi
if [ ! -f "$SITE_DIR/search_file.json" ]; then
log_error "Missing search_file.json in site directory"
return 1
fi
if [ ! -d "$SITE_DIR/images" ]; then
log_error "Missing images directory in site directory"
return 1
fi
# Check if search file is valid JSON
if ! python3 -c "import json; json.load(open('$SITE_DIR/search_file.json'))" &> /dev/null; then
log_error "Invalid JSON in search_file.json"
return 1
fi
log_info "Build validation completed successfully"
return 0
}
# Function to display build summary
display_build_summary() {
log_info "Build Summary:"
log_info "=============="
if [ -f "$SITE_DIR/search_file.json" ]; then
local module_count=$(python3 -c "import json; data=json.load(open('$SITE_DIR/search_file.json')); print(len(data['data']))" 2>/dev/null || echo "Unknown")
log_info "Total modules processed: $module_count"
fi
if [ -d "$SITE_DIR/images" ]; then
local image_count=$(find "$SITE_DIR/images" -name "*.webp" 2>/dev/null | wc -l)
log_info "Total images cached: $image_count"
fi
local site_size=$(du -sh "$SITE_DIR" 2>/dev/null | cut -f1 || echo "Unknown")
log_info "Site directory size: $site_size"
log_info "Site files are ready in the '$SITE_DIR' directory"
}