Skip to content

Commit 460d0ca

Browse files
authored
chore: add script to build all examples and improve parcel build process (#223)
- Add a script to build all example projects at once, simplifying the build process. - Ensure the "shared" package is built first, as it is required by all examples. - The script lists the size of the generated JavaScript files, making it easier to compare bundle sizes across different maxGraph versions. - Update the Parcel build to always clean the dist folder before building, as Parcel does not do this automatically. This prevents outdated files from previous builds from being included.
1 parent 47a08ae commit 460d0ca

File tree

4 files changed

+242
-1
lines changed

4 files changed

+242
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ Build the "shared" package:
2626
- this package is used in all projects, so it must be built first.
2727
- for more details, see its [dedicated README](projects/_shared/README.md).
2828

29+
**NOTE**: if you want to build all examples at once, you can run
30+
```bash
31+
./build-all-examples.bash
32+
```
33+
2934
### Available projects
3035

3136
- [TypeScript with Farm](./projects/farm-ts/README.md)

build-all-examples.bash

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# This script builds all examples in the packages directory.
5+
# From the root of the repository, run " ./build-all-examples.bash"
6+
7+
8+
# Check for command line arguments
9+
LIST_SIZE_ONLY=false
10+
if [[ $# -gt 0 && "$1" == "--list-size-only" ]]; then
11+
LIST_SIZE_ONLY=true
12+
fi
13+
14+
if [ "$LIST_SIZE_ONLY" = true ]; then
15+
echo "Skip building examples."
16+
else
17+
echo "Building all examples..."
18+
19+
npm run build -w projects/_shared
20+
npm run build --workspaces
21+
22+
23+
# for dir in packages/ts-example* packages/js-example*; do
24+
# if [ -d "$dir" ]; then
25+
# echo
26+
# echo "##################################################"
27+
# echo "Building $dir"
28+
# echo "##################################################"
29+
# (cd "$dir" && npm run build)
30+
# fi
31+
# done
32+
33+
echo "All examples built successfully."
34+
fi
35+
36+
37+
for dir in projects/*; do
38+
if [ -d "$dir" ]; then
39+
echo
40+
echo "##################################################"
41+
echo "Files in $dir/dist directory:"
42+
echo "##################################################"
43+
44+
if [ -d "$dir/dist" ]; then
45+
# Find all JS files and display sizes with 2 decimal places
46+
# Use 1000 to match Vite's size display
47+
find "$dir/dist" -name "*.js" -type f -exec ls -l {} \; | LC_NUMERIC=C awk '{
48+
# Convert bytes to KB with 2 decimal places
49+
size_kb = $5 / 1000
50+
printf "%.2f kB %s\n", size_kb, $9
51+
}'
52+
else
53+
echo "No dist directory found in $dir"
54+
fi
55+
fi
56+
done
57+

package-lock.json

Lines changed: 178 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/parcel-ts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"type": "module",
55
"scripts": {
66
"dev": "parcel index.html",
7-
"build": "tsc && parcel build --public-url ./ index.html"
7+
"build": "tsc && del dist && parcel build --public-url ./ index.html"
88
},
99
"devDependencies": {
10+
"del-cli": "~6.0.0",
1011
"parcel": "~2.15.0"
1112
}
1213
}

0 commit comments

Comments
 (0)