-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacking-script
More file actions
65 lines (49 loc) · 1.95 KB
/
Copy pathpacking-script
File metadata and controls
65 lines (49 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
#!/bin/bash
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# This is a bash script that builds, runs tests, packs the package,
# and copies it to the test project as a dependency if all previous steps are successful.
DEST_DIR="/Users/becaye/PROJECTS/npm-tester/node_modules"
NEW_DIR="${DEST_DIR}/gbfs-system"
set -e # Exit immediately if a command exits with a non-zero status.
# Function to display messages in green
echo_success() {
echo -e "${GREEN}$1${NC}"
echo
}
# Function to display messages in yellow
echo_warning() {
echo -e "${YELLOW}$1${NC}"
echo
}
# Function to display messages in red
echo_error() {
echo -e "${RED}$1${NC}"
echo
}
echo_warning "Building package..."
npm run build && echo_success "Build successful."
echo_warning "Running tests..."
npm test && echo_success "Tests passed."
echo_warning "Cleaning up old package files in current project..."
rm -f *.tgz && echo_success "old package files cleaned"
echo_warning "Creating package..."
PACKAGE_FILE=$(npm pack | tail -n1) && echo_success "Package $PACKAGE_FILE created."
echo_warning "Cleaning up old package files in destination project..."
rm -rf "${DEST_DIR}/@becaaye" && echo_success "old package files cleaned in destination directory"
if [ -f "$PACKAGE_FILE" ]; then
echo_warning "Creating package directory inside node_modules..."
mkdir -p "${NEW_DIR}" && echo_success "Package destination directory created."
echo_warning "Copying package..."
cp "$PACKAGE_FILE" "$NEW_DIR" && echo_success "Package copied successfully."
echo_warning "Unzipping copied package..."
tar -xzf "${NEW_DIR}/${PACKAGE_FILE}" -C "$NEW_DIR" --strip-components=1 && echo_success "Package unzipped successfully."
else
echo_error "Error: Package file does not exist."
exit 1
fi
echo_warning "Cleaning package files..."
rm -f *.tgz && find "${NEW_DIR}" -name "*.tgz" -exec rm {} \; && echo_success "OPERATION COMPLETED !"