Skip to content

Commit 27e1606

Browse files
RyanLee-Devclaude
andcommitted
refactor: npm-only distribution
Install: npm install -g minimax-cli (requires Node.js 18+) - package.json: remove private, add bin/files/engines/prepublishOnly - build.ts: only builds minimax.mjs, no platform binaries - install.sh: deleted (replaced by npm install) - release.yml: tests only, no binary release artifacts - update command: print "npm update -g minimax-cli" instead of self-update - main.ts: update notification shows npm command - README/README_CN: npm install -g minimax-cli Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 97c34f9 commit 27e1606

8 files changed

Lines changed: 38 additions & 294 deletions

File tree

.github/workflows/release.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,3 @@ jobs:
1212
- run: bun install
1313
- run: bun run typecheck
1414
- run: bun test
15-
16-
release:
17-
needs: test
18-
runs-on: ubuntu-latest
19-
permissions:
20-
contents: write
21-
steps:
22-
- uses: actions/checkout@v4
23-
- uses: oven-sh/setup-bun@v2
24-
- run: bun install
25-
26-
- name: Build all targets
27-
run: VERSION=${GITHUB_REF_NAME} bun run build.ts
28-
29-
- name: Create GitHub Release
30-
uses: softprops/action-gh-release@v2
31-
with:
32-
files: |
33-
dist/minimax-*
34-
dist/minimax.mjs
35-
dist/manifest.json
36-
generate_release_notes: true

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ Supports **Global** (`api.minimax.io`) and **CN** (`api.minimaxi.com`) with auto
1010

1111
## Install
1212

13+
Requires [Node.js](https://nodejs.org) 18+.
14+
1315
```bash
14-
curl -fsSL https://raw.githubusercontent.com/MiniMax-AI-Dev/cli/main/install.sh | sh
16+
npm install -g minimax-cli
1517
```
1618

1719
---

README_CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
## 安装
1212

13+
需要 [Node.js](https://nodejs.org) 18+。
14+
1315
```bash
14-
curl -fsSL https://raw.githubusercontent.com/MiniMax-AI-Dev/cli/main/install.sh | sh
16+
npm install -g minimax-cli
1517
```
1618

1719
---

build.ts

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,19 @@
1-
import { $ } from 'bun';
2-
import { createHash } from 'crypto';
31
import { readFileSync, writeFileSync } from 'fs';
42

53
const VERSION = process.env.VERSION ?? 'dev';
6-
7-
const targets = [
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' },
15-
];
16-
17-
function sha256(path: string): string {
18-
return createHash('sha256').update(readFileSync(path)).digest('hex');
19-
}
20-
21-
console.log(`Building minimax-cli ${VERSION}...\n`);
22-
23-
const manifest: {
24-
version: string;
25-
platforms: Record<string, { file: string; checksum: string }>;
26-
} = { version: VERSION, platforms: {} };
27-
28-
// Platform standalones
29-
for (const { bunTarget, platform, output } of targets) {
30-
const outPath = `dist/${output}`;
31-
process.stdout.write(` ${output}...`);
32-
33-
await $`bun build src/main.ts \
34-
--compile \
35-
--minify \
36-
--target ${bunTarget} \
37-
--outfile ${outPath} \
38-
--define "process.env.CLI_VERSION='${VERSION}'"`.quiet();
39-
40-
manifest.platforms[platform] = { file: output, checksum: sha256(outPath) };
41-
console.log(' ✓');
42-
}
43-
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-
61-
writeFileSync('dist/manifest.json', JSON.stringify(manifest, null, 2));
62-
console.log(' manifest.json ✓');
63-
console.log(`\nDone. ${targets.length + 1} builds in dist/`);
4+
const OUT = 'dist/minimax.mjs';
5+
6+
await Bun.build({
7+
entrypoints: ['src/main.ts'],
8+
outdir: 'dist',
9+
naming: 'minimax.mjs',
10+
target: 'node',
11+
minify: true,
12+
define: { 'process.env.CLI_VERSION': JSON.stringify(VERSION) },
13+
});
14+
15+
const content = readFileSync(OUT);
16+
writeFileSync(OUT, Buffer.concat([Buffer.from('#!/usr/bin/env node\n'), content]));
17+
18+
const size = (content.length / 1024).toFixed(0);
19+
console.log(`dist/minimax.mjs ${size}KB`);

install.sh

Lines changed: 0 additions & 149 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
{
22
"name": "minimax-cli",
33
"version": "0.3.1",
4-
"private": true,
5-
"description": "CLI for the MiniMax API Platform (Token Plan)",
4+
"description": "CLI for the MiniMax AI Platform",
65
"type": "module",
7-
"bin": {
8-
"minimax": "./dist/minimax.mjs"
9-
},
10-
"files": [
11-
"dist/minimax.mjs"
12-
],
6+
"engines": { "node": ">=18" },
7+
"bin": { "minimax": "./dist/minimax.mjs" },
8+
"files": ["dist/minimax.mjs"],
139
"scripts": {
1410
"dev": "bun run src/main.ts",
1511
"build": "bun run build.ts",
16-
"build:dev": "bun build src/main.ts --compile --minify --outfile dist/minimax --define \"process.env.CLI_VERSION='$(node -p \"require('./package.json').version\")'\"",
12+
"build:dev": "bun build src/main.ts --outfile dist/minimax.mjs --target node --minify --define \"process.env.CLI_VERSION='0.3.1'\" && printf '#!/usr/bin/env node\\n' | cat - dist/minimax.mjs > dist/tmp && mv dist/tmp dist/minimax.mjs && chmod +x dist/minimax.mjs",
13+
"prepublishOnly": "bun run build",
1714
"lint": "eslint src/ test/",
1815
"typecheck": "tsc --noEmit",
1916
"test": "bun test",
20-
"test:watch": "bun test --watch",
21-
"build:npm": "bun build src/main.ts --outfile dist/minimax.mjs --target node --define \"process.env.CLI_VERSION='$npm_package_version'\" && printf '#!/usr/bin/env node\\n' | cat - dist/minimax.mjs > dist/tmp && mv dist/tmp dist/minimax.mjs && chmod +x dist/minimax.mjs",
22-
"prepublishOnly": "bun run build:npm"
17+
"test:watch": "bun test --watch"
2318
},
2419
"dependencies": {
2520
"@clack/prompts": "^0.7.0"

src/commands/update.ts

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,17 @@
11
import { defineCommand } from '../command';
2-
import { CLIError } from '../errors/base';
3-
import { ExitCode } from '../errors/codes';
4-
import { resolveUpdateTarget, applySelfUpdate, type Channel } from '../update/self-update';
52

6-
const CLI_VERSION = process.env.CLI_VERSION ?? '0.1.0';
3+
const CLI_VERSION = process.env.CLI_VERSION ?? '0.0.0';
74

85
export default defineCommand({
96
name: 'update',
10-
description: 'Update minimax to a newer version',
11-
usage: 'minimax update [stable|latest|VERSION]',
12-
options: [
13-
{ flag: '[channel]', description: 'Target: stable (default), latest, or a version like 0.2.0' },
14-
],
7+
description: 'Update minimax to the latest version',
8+
usage: 'minimax update',
159
examples: [
1610
'minimax update',
17-
'minimax update latest',
18-
'minimax update 0.2.0',
1911
],
20-
async run(config, flags) {
21-
// Detect current binary path
22-
const currentBin = process.execPath;
23-
if (currentBin.endsWith('bun') || currentBin.endsWith('node')) {
24-
throw new CLIError(
25-
'Self-update is only supported for standalone binary installs.\n' +
26-
'For npm installs, run: npm update -g minimax-cli',
27-
ExitCode.USAGE,
28-
);
29-
}
30-
31-
const rawChannel = (flags._positional as string[] | undefined)?.[0] ?? 'stable';
32-
const validChannels = new Set(['stable', 'latest']);
33-
const channel: Channel = validChannels.has(rawChannel) || /^\d/.test(rawChannel) || rawChannel.startsWith('v')
34-
? rawChannel
35-
: (() => { throw new CLIError(`Unknown channel: ${rawChannel}`, ExitCode.USAGE); })();
36-
37-
process.stderr.write(`Checking for updates (channel: ${channel})...\n`);
38-
const target = await resolveUpdateTarget(channel);
39-
40-
if (target.version === `v${CLI_VERSION}`) {
41-
process.stderr.write(`Already up to date (${CLI_VERSION}).\n`);
42-
return;
43-
}
44-
45-
process.stderr.write(`Update available: v${CLI_VERSION}${target.version}\n`);
46-
47-
if (config.dryRun) {
48-
process.stderr.write(`Would replace: ${currentBin}\n`);
49-
return;
50-
}
51-
52-
await applySelfUpdate(target, currentBin);
53-
54-
process.stderr.write(`\nUpdated to ${target.version}.\n`);
55-
process.stderr.write(`https://github.com/MiniMax-AI-Dev/minimax-cli/releases/tag/${target.version}\n`);
12+
async run() {
13+
process.stderr.write(`Current version: ${CLI_VERSION}\n\n`);
14+
process.stderr.write('Run:\n');
15+
process.stderr.write(' npm update -g minimax-cli\n\n');
5616
},
5717
});

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ async function main() {
7070
await updateCheckPromise;
7171
const newVersion = getPendingUpdateNotification();
7272
if (newVersion && !config.quiet) {
73-
process.stderr.write(`\n Update available: v${CLI_VERSION}${newVersion}\n`);
74-
process.stderr.write(` Run 'minimax update' to upgrade.\n\n`);
73+
process.stderr.write(`\n Update available: ${newVersion}\n`);
74+
process.stderr.write(` npm update -g minimax-cli\n\n`);
7575
}
7676
}
7777

0 commit comments

Comments
 (0)