Skip to content

Commit 6eb17ef

Browse files
authored
Merge pull request #21 from MiniMax-AI-Dev/feat/mjs-distribution
feat: add minimax.mjs, prefer Node.js in install.sh
2 parents 078847a + c844239 commit 6eb17ef

2 files changed

Lines changed: 81 additions & 50 deletions

File tree

build.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { readFileSync, writeFileSync } from 'fs';
55
const VERSION = process.env.VERSION ?? 'dev';
66

77
const targets = [
8-
{ bunTarget: 'bun-linux-x64', platform: 'linux-x64', output: 'minimax-linux-x64', archive: 'minimax-linux-x64.tar.gz' },
9-
{ bunTarget: 'bun-linux-x64-musl', platform: 'linux-x64-musl', output: 'minimax-linux-x64-musl', archive: 'minimax-linux-x64-musl.tar.gz' },
10-
{ bunTarget: 'bun-linux-arm64', platform: 'linux-arm64', output: 'minimax-linux-arm64', archive: 'minimax-linux-arm64.tar.gz' },
11-
{ bunTarget: 'bun-linux-arm64-musl', platform: 'linux-arm64-musl', output: 'minimax-linux-arm64-musl', archive: 'minimax-linux-arm64-musl.tar.gz' },
12-
{ bunTarget: 'bun-darwin-x64', platform: 'darwin-x64', output: 'minimax-darwin-x64', archive: 'minimax-darwin-x64.tar.gz' },
13-
{ bunTarget: 'bun-darwin-arm64', platform: 'darwin-arm64', output: 'minimax-darwin-arm64', archive: 'minimax-darwin-arm64.tar.gz' },
14-
{ bunTarget: 'bun-windows-x64', platform: 'windows-x64', output: 'minimax-windows-x64.exe', archive: 'minimax-windows-x64.zip' },
8+
{ bunTarget: 'bun-linux-x64', platform: 'linux-x64', output: 'minimax-linux-x64' },
9+
{ bunTarget: 'bun-linux-x64-musl', platform: 'linux-x64-musl', output: 'minimax-linux-x64-musl' },
10+
{ bunTarget: 'bun-linux-arm64', platform: 'linux-arm64', output: 'minimax-linux-arm64' },
11+
{ bunTarget: 'bun-linux-arm64-musl', platform: 'linux-arm64-musl', output: 'minimax-linux-arm64-musl' },
12+
{ bunTarget: 'bun-darwin-x64', platform: 'darwin-x64', output: 'minimax-darwin-x64' },
13+
{ bunTarget: 'bun-darwin-arm64', platform: 'darwin-arm64', output: 'minimax-darwin-arm64' },
14+
{ bunTarget: 'bun-windows-x64', platform: 'windows-x64', output: 'minimax-windows-x64.exe' },
1515
];
1616

1717
function sha256(path: string): string {
@@ -22,31 +22,42 @@ console.log(`Building minimax-cli ${VERSION}...\n`);
2222

2323
const manifest: {
2424
version: string;
25-
platforms: Record<string, { archive: string; checksum: string }>;
25+
platforms: Record<string, { file: string; checksum: string }>;
2626
} = { version: VERSION, platforms: {} };
2727

28-
for (const { bunTarget, platform, output, archive } of targets) {
28+
// Platform standalones
29+
for (const { bunTarget, platform, output } of targets) {
2930
const outPath = `dist/${output}`;
30-
const archivePath = `dist/${archive}`;
3131
process.stdout.write(` ${output}...`);
32+
3233
await $`bun build src/main.ts \
3334
--compile \
3435
--minify \
3536
--target ${bunTarget} \
3637
--outfile ${outPath} \
3738
--define "process.env.CLI_VERSION='${VERSION}'"`.quiet();
3839

39-
// Compress: tar.gz for unix, zip for windows
40-
if (archive.endsWith('.zip')) {
41-
await $`zip -j ${archivePath} ${outPath}`.quiet();
42-
} else {
43-
await $`tar -czf ${archivePath} -C dist ${output}`.quiet();
44-
}
45-
46-
manifest.platforms[platform] = { archive, checksum: sha256(archivePath) };
40+
manifest.platforms[platform] = { file: output, checksum: sha256(outPath) };
4741
console.log(' ✓');
4842
}
4943

44+
// Node.js .mjs bundle (much smaller, requires node >= 18)
45+
process.stdout.write(' minimax.mjs...');
46+
const mjsPath = 'dist/minimax.mjs';
47+
48+
await $`bun build src/main.ts \
49+
--outfile ${mjsPath} \
50+
--target node \
51+
--minify \
52+
--define "process.env.CLI_VERSION='${VERSION}'"`.quiet();
53+
54+
// Prepend shebang so the file is directly executable
55+
const mjsContent = readFileSync(mjsPath);
56+
writeFileSync(mjsPath, Buffer.concat([Buffer.from('#!/usr/bin/env node\n'), mjsContent]));
57+
58+
manifest.platforms['node'] = { file: 'minimax.mjs', checksum: sha256(mjsPath) };
59+
console.log(' ✓');
60+
5061
writeFileSync('dist/manifest.json', JSON.stringify(manifest, null, 2));
5162
console.log(' manifest.json ✓');
52-
console.log(`\nDone. ${targets.length} archives in dist/`);
63+
console.log(`\nDone. ${targets.length + 1} builds in dist/`);

install.sh

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ case "$CHANNEL" in
1313
;;
1414
esac
1515

16-
REPO="MiniMax-AI-Dev/minimax-cli"
16+
REPO="MiniMax-AI-Dev/cli"
1717
INSTALL_DIR="${MINIMAX_INSTALL_DIR:-$HOME/.local/bin}"
1818

1919
# Dependency check: curl or wget
@@ -27,34 +27,45 @@ else
2727
echo "curl or wget is required." >&2; exit 1
2828
fi
2929

30-
# Detect OS
31-
case "$(uname -s)" in
32-
Darwin) OS="darwin" ;;
33-
Linux) OS="linux" ;;
34-
*) echo "Unsupported OS: $(uname -s)" >&2; exit 1 ;;
35-
esac
36-
37-
# Detect architecture
38-
case "$(uname -m)" in
39-
x86_64|amd64) ARCH="x64" ;;
40-
arm64|aarch64) ARCH="arm64" ;;
41-
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
42-
esac
43-
44-
# Rosetta 2: x64 shell on ARM Mac → use native arm64 binary
45-
if [ "$OS" = "darwin" ] && [ "$ARCH" = "x64" ]; then
46-
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
47-
ARCH="arm64"
30+
# Prefer Node.js >= 18 (much smaller download, ~200KB vs ~57MB)
31+
USE_NODE=0
32+
if command -v node >/dev/null 2>&1; then
33+
NODE_MAJOR=$(node --version 2>/dev/null | sed 's/v//' | cut -d. -f1)
34+
if [ -n "$NODE_MAJOR" ] && [ "$NODE_MAJOR" -ge 18 ] 2>/dev/null; then
35+
USE_NODE=1
4836
fi
4937
fi
5038

51-
# musl detection on Linux
52-
PLATFORM="${OS}-${ARCH}"
53-
if [ "$OS" = "linux" ]; then
54-
if [ -f /lib/libc.musl-x86_64.so.1 ] || \
55-
[ -f /lib/libc.musl-aarch64.so.1 ] || \
56-
ldd /bin/ls 2>&1 | grep -q musl; then
57-
PLATFORM="${OS}-${ARCH}-musl"
39+
if [ "$USE_NODE" = "0" ]; then
40+
# Detect OS
41+
case "$(uname -s)" in
42+
Darwin) OS="darwin" ;;
43+
Linux) OS="linux" ;;
44+
*) echo "Unsupported OS: $(uname -s)" >&2; exit 1 ;;
45+
esac
46+
47+
# Detect architecture
48+
case "$(uname -m)" in
49+
x86_64|amd64) ARCH="x64" ;;
50+
arm64|aarch64) ARCH="arm64" ;;
51+
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
52+
esac
53+
54+
# Rosetta 2: x64 shell on ARM Mac → use native arm64 binary
55+
if [ "$OS" = "darwin" ] && [ "$ARCH" = "x64" ]; then
56+
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
57+
ARCH="arm64"
58+
fi
59+
fi
60+
61+
# musl detection on Linux
62+
PLATFORM="${OS}-${ARCH}"
63+
if [ "$OS" = "linux" ]; then
64+
if [ -f /lib/libc.musl-x86_64.so.1 ] || \
65+
[ -f /lib/libc.musl-aarch64.so.1 ] || \
66+
ldd /bin/ls 2>&1 | grep -q musl; then
67+
PLATFORM="${OS}-${ARCH}-musl"
68+
fi
5869
fi
5970
fi
6071

@@ -78,25 +89,34 @@ if [ -z "$VERSION" ]; then
7889
echo "Failed to resolve version." >&2; exit 1
7990
fi
8091

81-
echo "Installing minimax ${VERSION} for ${PLATFORM}..."
82-
83-
# Fetch manifest and extract SHA256 (pure sh, no jq required)
8492
BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}"
93+
94+
# Fetch manifest and extract checksum
8595
MANIFEST=$(download "${BASE_URL}/manifest.json") || {
8696
echo "Failed to fetch manifest.json" >&2; exit 1
8797
}
98+
99+
if [ "$USE_NODE" = "1" ]; then
100+
PLATFORM="node"
101+
DOWNLOAD_FILE="minimax.mjs"
102+
echo "Installing minimax ${VERSION} (Node.js)..."
103+
else
104+
DOWNLOAD_FILE="minimax-${PLATFORM}"
105+
echo "Installing minimax ${VERSION} for ${PLATFORM}..."
106+
fi
107+
88108
CHECKSUM=$(printf '%s' "$MANIFEST" | tr -d '\n' | \
89109
sed "s/.*\"${PLATFORM}\"[^}]*\"checksum\" *: *\"\([a-f0-9]*\)\".*/\1/")
90110

91111
if [ -z "$CHECKSUM" ] || [ "${#CHECKSUM}" -ne 64 ]; then
92112
echo "Platform '${PLATFORM}' not found in manifest." >&2; exit 1
93113
fi
94114

95-
# Download binary to temp file
115+
# Download to temp file
96116
TMP=$(mktemp)
97117
trap 'rm -f "$TMP"' EXIT
98118

99-
download_to "${BASE_URL}/minimax-${PLATFORM}" "$TMP" || {
119+
download_to "${BASE_URL}/${DOWNLOAD_FILE}" "$TMP" || {
100120
echo "Download failed." >&2; exit 1
101121
}
102122

0 commit comments

Comments
 (0)