-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild
More file actions
executable file
·71 lines (58 loc) · 2.13 KB
/
Copy pathbuild
File metadata and controls
executable file
·71 lines (58 loc) · 2.13 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
#!/usr/bin/env bash
set -exuo pipefail
cd "$(dirname "$0")"
# Clean and create dist directory
rm -rf dist
mkdir dist
# Copy src to dist/src and build from dist/src into dist, so that
# the source map for index.js.map will refer to ./src/index.ts etc
cp -rp src README.md dist
# Copy LICENSE from root if it exists
for file in LICENSE; do
if [ -e "../../${file}" ]; then cp "../../${file}" dist; fi
done
# Copy CHANGELOG if it exists locally
for file in CHANGELOG.md; do
if [ -e "${file}" ]; then cp "${file}" dist; fi
done
# Copy scripts folder if it exists (needed for postinstall)
if [ -d "scripts" ]; then
cp -rp scripts dist
fi
# Create package.json for publishing from dist
node -e "
const pkg = require('./package.json');
// Fix paths for publishing from dist
pkg.bin.mxbai = pkg.bin.mxbai.replace('./dist/', './');
pkg.main = pkg.main.replace('dist/', '');
pkg.types = pkg.types.replace('dist/', '');
// Update files array to include actual files
pkg.files = ['bin/**/*', 'commands/**/*', 'utils/**/*', 'scripts/**/*', 'index.*', 'README.md', 'LICENSE', 'CHANGELOG.md'];
// Remove dev dependencies
delete pkg.devDependencies;
console.log(JSON.stringify(pkg, null, 2));
" > dist/package.json
# Build to .js/.mjs/.d.ts files using tsc-multi
./node_modules/.bin/tsc-multi
cp tsconfig.dist-src.json dist/src/tsconfig.json
# Ensure the CLI has proper shebang line
# The TypeScript compiler doesn't preserve shebangs, so we need to add it back
if [ -f "dist/bin/mxbai.js" ]; then
# Add shebang if not present
if ! head -n 1 dist/bin/mxbai.js | grep -q "^#!/usr/bin/env node"; then
echo '#!/usr/bin/env node' | cat - dist/bin/mxbai.js > temp && mv temp dist/bin/mxbai.js
fi
# Make the CLI executable
chmod +x dist/bin/mxbai.js
fi
# Run postprocess-files script if available
if [ -f "../../scripts/utils/postprocess-files.cjs" ]; then
DIST_PATH=./dist PKG_IMPORT_PATH=@mixedbread/cli/ node ../../scripts/utils/postprocess-files.cjs
fi
# Verify the build output
if [ -f "dist/bin/mxbai.js" ]; then
echo "Build successful: CLI binary created at dist/bin/mxbai.js"
else
echo "Build error: CLI binary not found"
exit 1
fi