Skip to content

Commit 638a077

Browse files
committed
add scripts\download.sh
1 parent 13cf550 commit 638a077

2 files changed

Lines changed: 122 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This project is to store [Dynamic Web TWAIN](https://www.dynamsoft.com/web-twain
44

55
### Local Development
66

7-
1. Download the docs template repo and the Web TWAIN docs repo with [download-dwt.sh](https://github.com/tony-xlh/misc/raw/refs/heads/main/build-docs/download-dwt.sh).
7+
1. Download the docs template repo and the Web TWAIN docs repo with [download.sh](https://github.com/dynamsoft-docs/web-twain-docs/raw/refs/heads/master/scripts/download.sh).
88
2. Install Ruby.
99
3. Go to the docs' folder and install dependencies.
1010

scripts/download.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Define variables
7+
DOCS_REPO_URL="https://github.com/dynamsoft-docs/web-twain-docs/archive/refs/heads/preview.zip"
8+
TEMPLATE_REPO_URL="https://github.com/dynamsoft-docs/Docs-Template-Repo/archive/refs/heads/preview.zip"
9+
TEMP_DIR="temp_docs"
10+
TEMPLATE_DIR="Docs-Template-Repo-preview"
11+
FINAL_DIR="web-twain-docs-preview"
12+
13+
echo "=== Starting build script ==="
14+
15+
# Clean up any existing temporary directories
16+
echo "Cleaning up old directories..."
17+
rm -rf "$TEMP_DIR" "$FINAL_DIR" "$TEMPLATE_DIR"
18+
19+
# Create temporary directory
20+
echo "Creating temporary directory: $TEMP_DIR"
21+
mkdir -p "$TEMP_DIR"
22+
cd "$TEMP_DIR"
23+
24+
# Download first repository (web-twain-docs)
25+
echo "Downloading web-twain-docs repository..."
26+
curl -L -o docs.zip "$DOCS_REPO_URL"
27+
28+
# Extract first repository
29+
echo "Extracting web-twain-docs..."
30+
unzip -q docs.zip
31+
32+
# Get the extracted directory name (dynamic detection)
33+
DOCS_EXTRACTED_DIR=$(find . -maxdepth 1 -type d -name "web-twain-docs-*" | head -1 | sed 's|^\./||')
34+
echo "Detected docs directory: $DOCS_EXTRACTED_DIR"
35+
36+
if [ -z "$DOCS_EXTRACTED_DIR" ]; then
37+
echo "Error: Unable to find extracted docs directory"
38+
exit 1
39+
fi
40+
41+
# Create final directory and copy docs content into it
42+
echo "Creating final directory and copying docs content..."
43+
mkdir -p "../$FINAL_DIR"
44+
cp -rf "$DOCS_EXTRACTED_DIR"/* "../$FINAL_DIR"/ 2>/dev/null || true
45+
46+
# Go back to parent directory
47+
cd ..
48+
49+
# Download second repository (Docs-Template-Repo)
50+
echo "Downloading Docs-Template-Repo repository..."
51+
curl -L -o template.zip "$TEMPLATE_REPO_URL"
52+
53+
# Extract second repository
54+
echo "Extracting Docs-Template-Repo..."
55+
unzip -q template.zip
56+
57+
# Get the template extracted directory name
58+
TEMPLATE_EXTRACTED_DIR=$(find . -maxdepth 1 -type d -name "Docs-Template-Repo-*" | head -1 | sed 's|^\./||')
59+
echo "Detected template directory: $TEMPLATE_EXTRACTED_DIR"
60+
61+
if [ -z "$TEMPLATE_EXTRACTED_DIR" ]; then
62+
echo "Error: Unable to find extracted template directory"
63+
exit 1
64+
fi
65+
66+
# Rename template directory to standard name
67+
if [ "$TEMPLATE_EXTRACTED_DIR" != "$TEMPLATE_DIR" ]; then
68+
echo "Renaming $TEMPLATE_EXTRACTED_DIR to $TEMPLATE_DIR"
69+
mv "$TEMPLATE_EXTRACTED_DIR" "$TEMPLATE_DIR"
70+
fi
71+
72+
# Ensure final directory exists
73+
if [ ! -d "$FINAL_DIR" ]; then
74+
echo "Error: Final directory $FINAL_DIR does not exist"
75+
exit 1
76+
fi
77+
78+
# Overwrite operation: Copy template repository contents to final directory (overwrite)
79+
echo "Performing overwrite operation..."
80+
cp -rf "$TEMPLATE_DIR"/* "$FINAL_DIR"/ 2>/dev/null || echo "Warning: Some files may not have been copied during the process, but execution can continue"
81+
82+
# Enter final directory
83+
cd "$FINAL_DIR"
84+
85+
# Display current directory
86+
echo "Current working directory: $(pwd)"
87+
echo "Final directory contents:"
88+
ls -la
89+
90+
# Replace strings in all files under _includes directory
91+
echo "Replacing assetsPath in _includes directory..."
92+
if [ -d "_includes" ]; then
93+
find _includes -type f -exec sed -i.bak "s|assetsPath = '/webres/wwwroot'|assetsPath = 'https://www.dynamsoft.com/webres/wwwroot'|g" {} \;
94+
find _includes -name "*.bak" -type f -delete
95+
echo "_includes directory processing completed"
96+
else
97+
echo "Warning: _includes directory does not exist"
98+
fi
99+
100+
# Replace strings in all files under _layouts directory
101+
echo "Replacing assetsPath in _layouts directory..."
102+
if [ -d "_layouts" ]; then
103+
find _layouts -type f -exec sed -i.bak "s|assetsPath = '/webres/wwwroot'|assetsPath = 'https://www.dynamsoft.com/webres/wwwroot'|g" {} \;
104+
find _layouts -name "*.bak" -type f -delete
105+
echo "_layouts directory processing completed"
106+
else
107+
echo "Warning: _layouts directory does not exist"
108+
fi
109+
110+
# Go back to parent directory
111+
cd ..
112+
113+
# Clean up temporary files
114+
echo "Cleaning up temporary files..."
115+
rm -f template.zip
116+
rm -rf "$TEMP_DIR" "$TEMPLATE_DIR"
117+
118+
echo "=== Build completed ==="
119+
echo "Final directory: $FINAL_DIR"
120+
echo "Final directory contents:"
121+
ls -la "$FINAL_DIR"

0 commit comments

Comments
 (0)