-
-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·103 lines (86 loc) · 2.78 KB
/
build.sh
File metadata and controls
executable file
·103 lines (86 loc) · 2.78 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
#!/usr/bin/env bash
set -e # Exit on error
# ============================================
# Version Bump Function
# ============================================
bump_version() {
# Get current version using npm
CURRENT_VERSION=$(npm pkg get version | tr -d '"')
echo ""
echo "Current version: $CURRENT_VERSION"
echo ""
echo "Version bump options:"
echo " [p]atch - Bug fixes (backward compatible)"
echo " [m]inor - New features (backward compatible)"
echo " [M]ajor - Breaking changes"
echo " [Enter] - No version change"
echo ""
read -p "Select version bump [p/m/M/Enter]: " BUMP_TYPE
case "$BUMP_TYPE" in
p|P|patch)
npm version patch --no-git-tag-version
;;
m|minor)
npm version minor --no-git-tag-version
;;
M|major)
npm version major --no-git-tag-version
;;
"")
echo "No version change."
return
;;
*)
echo "Invalid option. No version change."
return
;;
esac
NEW_VERSION=$(npm pkg get version | tr -d '"')
echo "✓ Version updated: $CURRENT_VERSION → $NEW_VERSION"
}
# ============================================
# Main Build Process
# ============================================
echo "=== Building draw2d.js ==="
# Run tests first
echo ""
echo "Running unit tests..."
npm test || { echo "❌ Tests failed! Build aborted."; exit 1; }
# Ask for version bump
bump_version
# Build the main library first
echo ""
echo "1/4 Building main library..."
npm install
npm run build
# Replace @VERSION@ placeholder in dist with actual version
VERSION=$(npm pkg get version | tr -d '"')
echo "Replacing @VERSION@ with $VERSION in dist/draw2d.js..."
sed -i '' "s/@VERSION@/$VERSION/g" ./dist/draw2d.js
# Copy built library to jsdoc public folder and examples
echo "2/4 Copying draw2d.js and examples to jsdoc..."
cp ./dist/draw2d.js ./jsdoc/public/
cp ./dist/draw2d.js ./examples/
# Sync examples to jsdoc/public/examples (for Vue.js app)
echo " Syncing examples to jsdoc/public/examples..."
rsync -av --delete --exclude='.DS_Store' ./examples/ ./jsdoc/public/examples/
# Generate the jsDoc
echo "3/4 Generating JSDoc..."
cd ./jsdoc/
npm install
./node_modules/jsdoc/jsdoc.js -c ./jsdoc.conf
# Generate the VUEjs app
echo "4/4 Building documentation site..."
npm run build
# Deploy to docs folder
cd ..
echo "=== Deploying to docs/ ==="
rm -rf ./docs/
cp -r ./jsdoc/dist/ ./docs
# Replace @VERSION@ in all JS files in docs
echo "Replacing @VERSION@ with $VERSION in docs/js/*.js..."
find ./docs/js -name "*.js" -exec sed -i '' "s/@VERSION@/$VERSION/g" {} \;
# Show final version
echo ""
echo "=== Build complete! ==="
echo "Version: $(npm pkg get version | tr -d '"')"