Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,3 @@ jobs:
- run: bun install
- run: bun run typecheck
- run: bun test

release:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install

- name: Build all targets
run: VERSION=${GITHUB_REF_NAME} bun run build.ts

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
dist/minimax-*
dist/minimax.mjs
dist/manifest.json
generate_release_notes: true
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ Supports **Global** (`api.minimax.io`) and **CN** (`api.minimaxi.com`) with auto

## Install

Requires [Node.js](https://nodejs.org) 18+.

```bash
curl -fsSL https://raw.githubusercontent.com/MiniMax-AI-Dev/cli/main/install.sh | sh
npm install -g minimax-cli
```

---
Expand Down
4 changes: 3 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

## 安装

需要 [Node.js](https://nodejs.org) 18+。

```bash
curl -fsSL https://raw.githubusercontent.com/MiniMax-AI-Dev/cli/main/install.sh | sh
npm install -g minimax-cli
```

---
Expand Down
76 changes: 16 additions & 60 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,19 @@
import { $ } from 'bun';
import { createHash } from 'crypto';
import { readFileSync, writeFileSync } from 'fs';

const VERSION = process.env.VERSION ?? 'dev';

const targets = [
{ bunTarget: 'bun-linux-x64', platform: 'linux-x64', output: 'minimax-linux-x64' },
{ bunTarget: 'bun-linux-x64-musl', platform: 'linux-x64-musl', output: 'minimax-linux-x64-musl' },
{ bunTarget: 'bun-linux-arm64', platform: 'linux-arm64', output: 'minimax-linux-arm64' },
{ bunTarget: 'bun-linux-arm64-musl', platform: 'linux-arm64-musl', output: 'minimax-linux-arm64-musl' },
{ bunTarget: 'bun-darwin-x64', platform: 'darwin-x64', output: 'minimax-darwin-x64' },
{ bunTarget: 'bun-darwin-arm64', platform: 'darwin-arm64', output: 'minimax-darwin-arm64' },
{ bunTarget: 'bun-windows-x64', platform: 'windows-x64', output: 'minimax-windows-x64.exe' },
];

function sha256(path: string): string {
return createHash('sha256').update(readFileSync(path)).digest('hex');
}

console.log(`Building minimax-cli ${VERSION}...\n`);

const manifest: {
version: string;
platforms: Record<string, { file: string; checksum: string }>;
} = { version: VERSION, platforms: {} };

// Platform standalones
for (const { bunTarget, platform, output } of targets) {
const outPath = `dist/${output}`;
process.stdout.write(` ${output}...`);

await $`bun build src/main.ts \
--compile \
--minify \
--target ${bunTarget} \
--outfile ${outPath} \
--define "process.env.CLI_VERSION='${VERSION}'"`.quiet();

manifest.platforms[platform] = { file: output, checksum: sha256(outPath) };
console.log(' ✓');
}

// Node.js .mjs bundle (much smaller, requires node >= 18)
process.stdout.write(' minimax.mjs...');
const mjsPath = 'dist/minimax.mjs';

await $`bun build src/main.ts \
--outfile ${mjsPath} \
--target node \
--minify \
--define "process.env.CLI_VERSION='${VERSION}'"`.quiet();

// Prepend shebang so the file is directly executable
const mjsContent = readFileSync(mjsPath);
writeFileSync(mjsPath, Buffer.concat([Buffer.from('#!/usr/bin/env node\n'), mjsContent]));

manifest.platforms['node'] = { file: 'minimax.mjs', checksum: sha256(mjsPath) };
console.log(' ✓');

writeFileSync('dist/manifest.json', JSON.stringify(manifest, null, 2));
console.log(' manifest.json ✓');
console.log(`\nDone. ${targets.length + 1} builds in dist/`);
const OUT = 'dist/minimax.mjs';

await Bun.build({
entrypoints: ['src/main.ts'],
outdir: 'dist',
naming: 'minimax.mjs',
target: 'node',
minify: true,
define: { 'process.env.CLI_VERSION': JSON.stringify(VERSION) },
});

const content = readFileSync(OUT);
writeFileSync(OUT, Buffer.concat([Buffer.from('#!/usr/bin/env node\n'), content]));

const size = (content.length / 1024).toFixed(0);
console.log(`dist/minimax.mjs ${size}KB`);
149 changes: 0 additions & 149 deletions install.sh

This file was deleted.

19 changes: 7 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
{
"name": "minimax-cli",
"version": "0.3.1",
"private": true,
"description": "CLI for the MiniMax API Platform (Token Plan)",
"description": "CLI for the MiniMax AI Platform",
"type": "module",
"bin": {
"minimax": "./dist/minimax.mjs"
},
"files": [
"dist/minimax.mjs"
],
"engines": { "node": ">=18" },
"bin": { "minimax": "./dist/minimax.mjs" },
"files": ["dist/minimax.mjs"],
"scripts": {
"dev": "bun run src/main.ts",
"build": "bun run build.ts",
"build:dev": "bun build src/main.ts --compile --minify --outfile dist/minimax --define \"process.env.CLI_VERSION='$(node -p \"require('./package.json').version\")'\"",
"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",
"prepublishOnly": "bun run build",
"lint": "eslint src/ test/",
"typecheck": "tsc --noEmit",
"test": "bun test",
"test:watch": "bun test --watch",
"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",
"prepublishOnly": "bun run build:npm"
"test:watch": "bun test --watch"
},
"dependencies": {
"@clack/prompts": "^0.7.0"
Expand Down
54 changes: 7 additions & 47 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
import { defineCommand } from '../command';
import { CLIError } from '../errors/base';
import { ExitCode } from '../errors/codes';
import { resolveUpdateTarget, applySelfUpdate, type Channel } from '../update/self-update';

const CLI_VERSION = process.env.CLI_VERSION ?? '0.1.0';
const CLI_VERSION = process.env.CLI_VERSION ?? '0.0.0';

export default defineCommand({
name: 'update',
description: 'Update minimax to a newer version',
usage: 'minimax update [stable|latest|VERSION]',
options: [
{ flag: '[channel]', description: 'Target: stable (default), latest, or a version like 0.2.0' },
],
description: 'Update minimax to the latest version',
usage: 'minimax update',
examples: [
'minimax update',
'minimax update latest',
'minimax update 0.2.0',
],
async run(config, flags) {
// Detect current binary path
const currentBin = process.execPath;
if (currentBin.endsWith('bun') || currentBin.endsWith('node')) {
throw new CLIError(
'Self-update is only supported for standalone binary installs.\n' +
'For npm installs, run: npm update -g minimax-cli',
ExitCode.USAGE,
);
}

const rawChannel = (flags._positional as string[] | undefined)?.[0] ?? 'stable';
const validChannels = new Set(['stable', 'latest']);
const channel: Channel = validChannels.has(rawChannel) || /^\d/.test(rawChannel) || rawChannel.startsWith('v')
? rawChannel
: (() => { throw new CLIError(`Unknown channel: ${rawChannel}`, ExitCode.USAGE); })();

process.stderr.write(`Checking for updates (channel: ${channel})...\n`);
const target = await resolveUpdateTarget(channel);

if (target.version === `v${CLI_VERSION}`) {
process.stderr.write(`Already up to date (${CLI_VERSION}).\n`);
return;
}

process.stderr.write(`Update available: v${CLI_VERSION} → ${target.version}\n`);

if (config.dryRun) {
process.stderr.write(`Would replace: ${currentBin}\n`);
return;
}

await applySelfUpdate(target, currentBin);

process.stderr.write(`\nUpdated to ${target.version}.\n`);
process.stderr.write(`https://github.com/MiniMax-AI-Dev/minimax-cli/releases/tag/${target.version}\n`);
async run() {
process.stderr.write(`Current version: ${CLI_VERSION}\n\n`);
process.stderr.write('Run:\n');
process.stderr.write(' npm update -g minimax-cli\n\n');
},
});
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ async function main() {
await updateCheckPromise;
const newVersion = getPendingUpdateNotification();
if (newVersion && !config.quiet) {
process.stderr.write(`\n Update available: v${CLI_VERSION} → ${newVersion}\n`);
process.stderr.write(` Run 'minimax update' to upgrade.\n\n`);
process.stderr.write(`\n Update available: ${newVersion}\n`);
process.stderr.write(` npm update -g minimax-cli\n\n`);
}
}

Expand Down
Loading