-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcopy_workers.sh
More file actions
executable file
·55 lines (43 loc) · 1.89 KB
/
copy_workers.sh
File metadata and controls
executable file
·55 lines (43 loc) · 1.89 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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Configuration ---
# Source directory where the original files are located
SOURCE_DIR="node_modules/eecircuit-schematic/dist/"
# Destination directory where files should be copied
DEST_DIR="./dist/assets"
# File pattern to match within the source directory
FILE_PATTERN="*.worker.js"
# --- Pre-flight Checks ---
# 1. Check if the source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Source directory '$SOURCE_DIR' not found."
echo "Please ensure 'npm install' or 'yarn install' has been run and the package exists."
exit 1
fi
# 2. Ensure the destination directory exists (create if it doesn't)
# The '-p' flag ensures that parent directories are also created if needed,
# and it doesn't error if the directory already exists.
echo "Ensuring destination directory '$DEST_DIR' exists..."
mkdir -p "$DEST_DIR"
echo "Destination directory checked/created."
# --- Copy Operation ---
echo "Attempting to copy files matching '$FILE_PATTERN' from '$SOURCE_DIR' to '$DEST_DIR'..."
# Use the 'cp' command:
# -v : Verbose - print the name of each file before copying it. (Optional, but helpful)
# -f : Force - if an existing destination file cannot be opened, remove it and try again.
# This effectively ensures replacement without prompting (unless the destination
# is write-protected and cannot be removed).
# The source path uses the directory and the file pattern.
# The destination path is the target directory.
cp -vf "$SOURCE_DIR"/$FILE_PATTERN "$DEST_DIR"/
# Check the exit status of the cp command explicitly (optional, as set -e handles it)
if [ $? -eq 0 ]; then
echo "Files copied successfully."
else
# This message might not be reached if 'set -e' is active and cp fails,
# but it's good practice in scripts without 'set -e'.
echo "Error: File copy operation failed."
exit 1
fi
exit 0