Skip to content

Commit 13ae218

Browse files
author
xychen
committed
Build NPM wrapper
1 parent 529c505 commit 13ae218

File tree

5 files changed

+3381
-7
lines changed

5 files changed

+3381
-7
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ on:
44

55
jobs:
66
build:
7-
permissions:
8-
contents: write
97
strategy:
108
matrix:
119
include:
12-
- name: darwin-aarch64
10+
- name: darwin-arm64
1311
platform: macos-latest
1412
target: aarch64-apple-darwin
15-
- name: darwin-x86_64
13+
- name: darwin-x64
1614
platform: macos-latest
1715
target: x86_64-apple-darwin
18-
- name: linux-x86_64
16+
- name: linux-x64
1917
platform: ubuntu-latest
2018
target: x86_64-unknown-linux-gnu
21-
- name: windows-x86_64
19+
- name: win32-x64
2220
platform: windows-latest
2321
target: x86_64-pc-windows-msvc
2422
suffix: .exe
@@ -53,5 +51,39 @@ jobs:
5351
- name: Archive distributable
5452
uses: actions/upload-artifact@v4
5553
with:
56-
name: commands-mcp_${{ github.run_id }}_${{ matrix.name }}
54+
name: commands-mcp_${{ matrix.name }}
5755
path: target/${{ matrix.target }}/release/commands-mcp${{ matrix.suffix }}
56+
57+
pack-npm:
58+
runs-on: ubuntu-latest
59+
needs: build
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v4
63+
64+
- name: Set up Node.js
65+
uses: actions/setup-node@v4
66+
with:
67+
node-version: '22'
68+
69+
- name: Download artifact
70+
uses: actions/download-artifact@v4
71+
with:
72+
pattern: commands-mcp_*
73+
74+
- name: Pack
75+
id: pack
76+
run: |
77+
for dir in commands-mcp_*; do
78+
platform=${dir#commands-mcp_}
79+
mkdir -p binaries/${platform}
80+
mv -v ${dir}/commands-mcp* binaries/${platform}/
81+
chmod +x binaries/${platform}/commands-mcp*
82+
done
83+
echo "tarball=$(npm pack)" >> "$GITHUB_OUTPUT"
84+
85+
- name: Archive tarball
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: npm-tarball
89+
path: ${{ steps.pack.outputs.tarball }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
node_modules
12
/target
23
/commands.yaml
34
/commands.schema.json
5+
*.tgz

npm-wrapper.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
3+
import { resolve } from 'path';
4+
import { accessSync, constants } from 'fs';
5+
import { spawnSync } from 'child_process';
6+
7+
const platforms = {
8+
'darwin-arm64': {
9+
suffix: '',
10+
},
11+
'darwin-x64': {
12+
suffix: '',
13+
},
14+
'linux-x64': {
15+
suffix: '',
16+
},
17+
'win32-x64': {
18+
suffix: '.exe',
19+
},
20+
};
21+
22+
const target = `${process.platform}-${process.arch}`;
23+
const config = platforms[target];
24+
if (!config) {
25+
throw new Error(`Unsupported platform: ${process.platform}-${process.arch}`);
26+
}
27+
28+
const packageDir = new URL('.', import.meta.url).pathname;
29+
30+
const executable = [
31+
resolve(packageDir, 'binaries', target, `commands-mcp${config.suffix}`),
32+
resolve(packageDir, 'target', 'release', `commands-mcp${config.suffix}`),
33+
].find((path) => {
34+
try {
35+
accessSync(path, constants.X_OK);
36+
return true;
37+
} catch {
38+
return false;
39+
}
40+
});
41+
if (!executable) {
42+
throw new Error(`Executable not found for platform: ${process.platform}-${process.arch}`);
43+
}
44+
45+
const args = process.argv.slice(2);
46+
47+
spawnSync(executable, args, {
48+
stdio: 'inherit',
49+
});

0 commit comments

Comments
 (0)