Skip to content

Commit c15be93

Browse files
committed
refactor: extract log
1 parent fc66413 commit c15be93

File tree

3 files changed

+41
-58
lines changed

3 files changed

+41
-58
lines changed

script/android-firefox.sh

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,10 @@ cleanup() {
2121
# Set trap to cleanup on exit
2222
trap cleanup EXIT
2323

24-
# Color definitions
25-
RED='\033[0;31m'
26-
GREEN='\033[0;32m'
27-
YELLOW='\033[1;33m'
28-
BLUE='\033[0;34m'
29-
# No Color
30-
NC='\033[0m'
31-
32-
log_info() {
33-
echo -e "${BLUE}[ INFO]${NC} $1" >&4
34-
}
35-
36-
log_success() {
37-
echo -e "${GREEN}[ SUCC]${NC} $1" >&4
38-
}
39-
40-
log_warning() {
41-
echo -e "${YELLOW}[ WARN]${NC} $1" >&4
42-
}
43-
44-
log_error() {
45-
echo -e "${RED}[ERROR]${NC} $1" >&4
46-
}
24+
# Source logging functions
25+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
26+
LOG_FD=4
27+
source "${SCRIPT_DIR}/lib/log.sh"
4728

4829
# Check if command exists
4930
check_command() {
@@ -163,43 +144,39 @@ check_firefox_nightly() {
163144
build_and_run_extension() {
164145
local device_id="$1"
165146
local extension_dir="dist_dev_firefox"
166-
167147
# Clear existing extension directory
168148
if [ -d "$extension_dir" ]; then
169149
log_info "Clearing existing extension directory..."
170150
rm -rf "$extension_dir"
171151
fi
172-
173152
# Start npm run dev:firefox in background
174153
log_info "Starting npm run dev:firefox in background..."
175154
npm run dev:firefox > /dev/null 2>&1 &
176155
NPM_PID=$!
177-
178156
# Wait for manifest.json to be created
179157
local max_wait=60
180158
local wait_count=0
181159
log_info "Waiting for building finished..."
182-
183160
while [ ! -f "$extension_dir/manifest.json" ] && [ $wait_count -lt $max_wait ]; do
184161
sleep 1
185162
wait_count=$((wait_count + 1))
186163
if [ $((wait_count % 5)) -eq 0 ]; then
187164
log_info "Still waiting for building finished... ($wait_count/$max_wait)"
188165
fi
189166
done
190-
167+
191168
if [ ! -f "$extension_dir/manifest.json" ]; then
192169
log_error "Building not finished yet after ${max_wait}s"
193170
cleanup
194171
exit 1
195172
fi
196-
173+
197174
log_success "Extension built successfully, manifest.json found"
198175
log_info "Background build process PID: $NPM_PID"
199176

200177
log_info "Starting extension development server..."
201178
log_info "Command: web-ext run -t firefox-android --firefox-apk org.mozilla.fenix -s $extension_dir --adb-device $device_id --verbose"
202-
179+
203180
if web-ext run \
204181
-t firefox-android \
205182
--firefox-apk org.mozilla.fenix \

script/lib/log.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Color definitions
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[1;33m'
7+
BLUE='\033[0;34m'
8+
CYAN='\033[0;36m'
9+
# No Color
10+
NC='\033[0m'
11+
12+
log_info() {
13+
echo -e "${BLUE}[ INFO]${NC} $1" >&${LOG_FD:-1}
14+
}
15+
16+
log_success() {
17+
echo -e "${GREEN}[ SUCC]${NC} $1" >&${LOG_FD:-1}
18+
}
19+
20+
log_warning() {
21+
echo -e "${YELLOW}[ WARN]${NC} $1" >&${LOG_FD:-1}
22+
}
23+
24+
log_error() {
25+
echo -e "${RED}[ERROR]${NC} $1" >&${LOG_FD:-1}
26+
}
27+
28+
log_step() {
29+
echo -e "${CYAN}[ STEP]${NC} $1" >&${LOG_FD:-1}
30+
}
31+

script/setup-e2e.sh

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,9 @@ set -e
55

66
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
77

8-
# Color definitions
9-
RED='\033[0;31m'
10-
GREEN='\033[0;32m'
11-
YELLOW='\033[1;33m'
12-
BLUE='\033[0;34m'
13-
CYAN='\033[0;36m'
14-
# No Color
15-
NC='\033[0m'
16-
17-
log_info() {
18-
echo -e "${BLUE}[ INFO]${NC} $1"
19-
}
20-
21-
log_success() {
22-
echo -e "${GREEN}[ SUCC]${NC} $1"
23-
}
24-
25-
log_warning() {
26-
echo -e "${YELLOW}[ WARN]${NC} $1"
27-
}
28-
29-
log_error() {
30-
echo -e "${RED}[ERROR]${NC} $1"
31-
}
32-
33-
log_step() {
34-
echo -e "${CYAN}[ STEP]${NC} $1"
35-
}
8+
# Source logging functions
9+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
10+
source "${SCRIPT_DIR}/lib/log.sh"
3611

3712
# Detect OS
3813
detect_os() {

0 commit comments

Comments
 (0)