Skip to content

Commit b6ad5ac

Browse files
committed
Add flags to control package build script
1 parent 424a783 commit b6ad5ac

2 files changed

Lines changed: 107 additions & 30 deletions

File tree

‎pkgs/core/scripts/build/package.sh‎

Lines changed: 106 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,39 @@
77

88
set -e
99

10+
build_cjs=true
11+
build_cdn=true
12+
format_code=true
13+
include_docs=true
14+
include_fp=true
15+
include_i18n=true
16+
17+
for arg in "$@"; do
18+
if [ "$arg" = "--no-cjs" ]; then
19+
build_cjs=false
20+
fi
21+
22+
if [ "$arg" = "--no-cdn" ]; then
23+
build_cdn=false
24+
fi
25+
26+
if [ "$arg" = "--no-format" ]; then
27+
format_code=false
28+
fi
29+
30+
if [ "$arg" = "--no-docs" ]; then
31+
include_docs=false
32+
fi
33+
34+
if [ "$arg" = "--no-fp" ]; then
35+
include_fp=false
36+
fi
37+
38+
if [ "$arg" = "--no-i18n" ]; then
39+
include_i18n=false
40+
fi
41+
done
42+
1043
echo "⚡️ Building package"
1144

1245
#region Prepare
@@ -48,19 +81,24 @@ echo "🟢 ESM code is ready!"
4881

4982
#region CommonJS
5083

51-
echo
52-
echo "🚧 Building CommonJS code..."
84+
if [ "$build_cjs" = true ]; then
85+
echo
86+
echo "🚧 Building CommonJS code..."
5387

54-
# Transpile CommonJS versions of files
55-
env BABEL_ENV=cjs pnpm babel src \
56-
--config-file ./babel.config.json \
57-
--source-root src \
58-
--out-dir "$dir" \
59-
--extensions .js,.ts \
60-
--out-file-extension .cjs \
61-
--quiet
88+
# Transpile CommonJS versions of files
89+
env BABEL_ENV=cjs pnpm babel src \
90+
--config-file ./babel.config.json \
91+
--source-root src \
92+
--out-dir "$dir" \
93+
--extensions .js,.ts \
94+
--out-file-extension .cjs \
95+
--quiet
6296

63-
echo "🟢 CommonJS code is ready!"
97+
echo "🟢 CommonJS code is ready!"
98+
else
99+
echo
100+
echo "⚪️ --no-cjs is set, CommonJS code is skipped"
101+
fi
64102

65103
#endregion
66104

@@ -82,20 +120,18 @@ echo
82120
echo "🚧 Formatting code..."
83121

84122
# Make it prettier
85-
if [ -z "$PACKAGE_SKIP_BEAUTIFY" ]; then
123+
if [ "$format_code" = true ]; then
86124
pnpm prettier --write --ignore-path "" "$dir" 1> /dev/null
87-
fi
88125

89-
echo "🟢 Formatting is complete!"
126+
echo "🟢 Formatting is complete!"
127+
else
128+
echo "⚪️ --no-format is set, formatting is skipped"
129+
fi
90130

91131
#endregion
92132

93133
#region Flattening
94134

95-
if [ -n "$TEST_FLATTEN" ]; then
96-
exit 0
97-
fi
98-
99135
echo
100136
echo "🚧 Flattening the modules..."
101137

@@ -108,13 +144,18 @@ echo "🟢 Flattening is complete!"
108144

109145
#region CommonJS types
110146

111-
echo
112-
echo "🚧 Building CommonJS type definitions..."
147+
if [ "$build_cjs" = true ]; then
148+
echo
149+
echo "🚧 Building CommonJS type definitions..."
113150

114-
# Generate .d.cts files
115-
node scripts/build/cts.ts
151+
# Generate .d.cts files
152+
node scripts/build/cts.ts
116153

117-
echo "🟢 CommonJS type definitions are ready!"
154+
echo "🟢 CommonJS type definitions are ready!"
155+
else
156+
echo
157+
echo "⚪️ --no-cjs is set, CommonJS type definitions are skipped"
158+
fi
118159

119160
#endregion
120161

@@ -153,16 +194,55 @@ echo "🟢 package.json is ready!"
153194
echo
154195

155196
# Build CDN versions
156-
if [ -z "$PACKAGE_SKIP_CDN" ]; then
197+
if [ "$build_cdn" = true ]; then
157198
echo "🚧 Building CDN versions..."
158199

159200
bun ./scripts/build/cdn.ts
160201

161202
echo "🟢 CDN versions are ready!"
162203
else
163-
echo "⚪️ PACKAGE_SKIP_CDN is set, CDN versions are skipped"
204+
echo "⚪️ --no-cdn is set, CDN versions are skipped"
205+
fi
206+
207+
#endregion
208+
209+
#region Cleanup
210+
211+
if [ "$include_docs" = false ]; then
212+
echo
213+
echo "🚧 Removing docs files..."
214+
215+
rm -rf "$dir/docs" \
216+
"$dir/CHANGELOG.md" \
217+
"$dir/SECURITY.md" \
218+
"$dir/LICENSE.md"
219+
220+
echo "🟢 Docs files are removed!"
221+
fi
222+
223+
if [ "$include_fp" = false ]; then
224+
echo
225+
echo "🚧 Removing FP files..."
226+
227+
rm -rf "$dir"/fp*
228+
229+
echo "🟢 FP files are removed!"
230+
fi
231+
232+
if [ "$include_i18n" = false ]; then
233+
echo
234+
echo "🚧 Removing I18n files..."
235+
236+
rm -rf "$dir"/locale* \
237+
"$dir"/format.* \
238+
"$dir"/formatDistance* \
239+
"$dir"/formatDuration* \
240+
"$dir"/formatRelative* \
241+
"$dir"/parse.*
242+
243+
echo "🟢 I18n files are removed!"
164244
fi
165245

166246
#endregion
167247

168-
echo -e "\n⭐️ Build complete!"
248+
echo -e "\n⭐️ Build complete!"

‎pkgs/core/scripts/test/types.sh‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ root_rel_path="$root/tmp/types"
1111
mkdir -p "$root_rel_path"
1212
export PACKAGE_OUTPUT_PATH=$(realpath "$root_rel_path")
1313

14-
export PACKAGE_SKIP_BEAUTIFY=true
15-
export PACKAGE_SKIP_CDN=true
16-
17-
./scripts/build/package.sh
14+
./scripts/build/package.sh --no-format --no-cdn
1815

1916
echo "$PACKAGE_OUTPUT_PATH"
2017
pnpm attw --pack "$PACKAGE_OUTPUT_PATH"

0 commit comments

Comments
 (0)