Skip to content

Commit af84d7d

Browse files
committed
fix: correct npm package structure and publishing workflow
- Fix bin script paths (remove ./ prefix) - Remove binaries/ from main package files - Add publish-platform script for platform packages - Update GitHub Actions to auto-publish platform packages - Platform binaries now published separately as optionalDependencies"
1 parent 01ce280 commit af84d7d

File tree

4 files changed

+139
-7
lines changed

4 files changed

+139
-7
lines changed

.github/workflows/build-binaries.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ jobs:
6565
with:
6666
name: ${{ matrix.slug }}
6767
path: binaries/${{ matrix.slug }}
68+
69+
- name: Publish platform package to npm
70+
if: startsWith(github.ref, 'refs/tags/v')
71+
env:
72+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
73+
run: |
74+
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
75+
bun scripts/publish-platform.mjs --tag latest --access public

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
"description": "Multi-Agent Workflow Orchestration.",
55
"type": "module",
66
"bin": {
7-
"codemachine": "./bin/codemachine.js",
8-
"cm": "./bin/codemachine.js"
7+
"codemachine": "bin/codemachine.js",
8+
"cm": "bin/codemachine.js"
99
},
1010
"files": [
1111
"bin/",
12-
"dist/",
1312
"README.md",
1413
"LICENSE"
1514
],
@@ -40,7 +39,8 @@
4039
"_comment_release": "Release: Publishing and validation",
4140
"prepare": "husky install",
4241
"validate": "bun scripts/validate.mjs",
43-
"release": "bun scripts/publish.mjs --tag latest"
42+
"release": "bun scripts/publish.mjs --tag latest",
43+
"publish:platform": "bun scripts/publish-platform.mjs"
4444
},
4545
"dependencies": {
4646
"1.3.0": "^1.3.0",

scripts/build-binaries.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ try {
152152
// Create package.json for the platform-specific package
153153
const pkgName = `codemachine-${os}-${archName}`;
154154
const binEntries = {
155-
codemachine: `./codemachine${ext}`,
156-
'codemachine-workflow': `./codemachine-workflow${ext}`,
157-
cm: `./codemachine${ext}`,
155+
codemachine: `codemachine${ext}`,
156+
'codemachine-workflow': `codemachine-workflow${ext}`,
157+
cm: `codemachine${ext}`,
158158
};
159159

160160
const pkg = {

scripts/publish-platform.mjs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env bun
2+
import { execSync } from 'child_process';
3+
import { existsSync } from 'node:fs';
4+
import { join } from 'node:path';
5+
import { platform, arch } from 'node:os';
6+
7+
// Simple ANSI colors
8+
const cyan = '\x1b[36m';
9+
const green = '\x1b[32m';
10+
const yellow = '\x1b[33m';
11+
const red = '\x1b[31m';
12+
const dim = '\x1b[2m';
13+
const bold = '\x1b[1m';
14+
const reset = '\x1b[0m';
15+
16+
// Map platform/arch to package names
17+
const platformMap = {
18+
'linux-x64': 'codemachine-linux-x64',
19+
'darwin-arm64': 'codemachine-darwin-arm64',
20+
'darwin-x64': 'codemachine-darwin-x64',
21+
'win32-x64': 'codemachine-windows-x64',
22+
};
23+
24+
const currentPlatform = platform();
25+
const currentArch = arch();
26+
const platformKey = `${currentPlatform}-${currentArch}`;
27+
const packageName = platformMap[platformKey];
28+
29+
if (!packageName) {
30+
console.error(`${red}${reset} Unsupported platform: ${bold}${platformKey}${reset}`);
31+
console.error(`${dim}Supported:${reset} ${Object.keys(platformMap).join(', ')}`);
32+
process.exit(1);
33+
}
34+
35+
const packageDir = join('./binaries', packageName);
36+
37+
if (!existsSync(packageDir)) {
38+
console.error(`${red}${reset} Package directory not found: ${packageDir}`);
39+
console.error(`${yellow}${reset} Run ${bold}bun run build${reset} first to build binaries`);
40+
process.exit(1);
41+
}
42+
43+
// Parse arguments
44+
let dryRun = false;
45+
let tag = 'latest';
46+
let access = 'public';
47+
48+
const args = process.argv.slice(2);
49+
for (let i = 0; i < args.length; i++) {
50+
switch (args[i]) {
51+
case '--dry-run':
52+
dryRun = true;
53+
break;
54+
case '--tag':
55+
if (i + 1 >= args.length) {
56+
console.error(`${red}${reset} --tag requires a value`);
57+
process.exit(1);
58+
}
59+
i++;
60+
tag = args[i];
61+
break;
62+
case '--access':
63+
if (i + 1 >= args.length) {
64+
console.error(`${red}${reset} --access requires a value`);
65+
process.exit(1);
66+
}
67+
i++;
68+
access = args[i];
69+
break;
70+
default:
71+
console.error(`${red}${reset} Unknown option: ${args[i]}`);
72+
process.exit(1);
73+
}
74+
}
75+
76+
console.log(`\n${bold}${cyan}╭────────────────────────────────────────╮${reset}`);
77+
console.log(`${bold}${cyan}${reset} Publishing Platform Package ${bold}${cyan}${reset}`);
78+
console.log(`${bold}${cyan}╰────────────────────────────────────────╯${reset}\n`);
79+
80+
console.log(`${dim}Package:${reset} ${bold}${packageName}${reset}`);
81+
console.log(`${dim}Directory:${reset} ${packageDir}`);
82+
console.log(`${dim}Tag:${reset} ${tag}`);
83+
console.log(`${dim}Access:${reset} ${access}`);
84+
console.log(`${dim}Dry run:${reset} ${dryRun ? 'yes' : 'no'}\n`);
85+
86+
try {
87+
// Verify npm authentication
88+
console.log(`${cyan}${reset} Verifying npm authentication...`);
89+
try {
90+
execSync('npm whoami', { stdio: 'pipe' });
91+
console.log(`${green}${reset} ${dim}Authenticated${reset}\n`);
92+
} catch {
93+
console.error(`${red}${reset} Not logged in to npm. Run ${bold}npm login${reset} first.`);
94+
process.exit(1);
95+
}
96+
97+
// Build publish command
98+
const publishCmd = dryRun
99+
? `npm publish --dry-run --tag ${tag} --access ${access}`
100+
: `npm publish --tag ${tag} --access ${access}`;
101+
102+
console.log(`${cyan}${reset} Publishing ${packageName}...`);
103+
if (dryRun) {
104+
console.log(`${yellow}${reset} ${dim}Dry run mode - no actual publish${reset}`);
105+
}
106+
107+
execSync(publishCmd, {
108+
cwd: packageDir,
109+
stdio: 'inherit',
110+
});
111+
112+
if (!dryRun) {
113+
console.log(`\n${green}${reset} ${bold}Published successfully!${reset}`);
114+
console.log(`\n${dim}View at:${reset} https://www.npmjs.com/package/${packageName}\n`);
115+
} else {
116+
console.log(`\n${green}${reset} ${bold}Dry run complete${reset}\n`);
117+
}
118+
} catch (error) {
119+
console.error(`\n${red}${reset} ${bold}Publish failed${reset}`);
120+
if (error.message) {
121+
console.error(`${dim}${error.message}${reset}`);
122+
}
123+
process.exit(1);
124+
}

0 commit comments

Comments
 (0)