@mandors/cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,183 @@
1
+ /**
2
+ * @fileoverview Cross-platform build script for Mandor binaries
3
+ * @description Compiles Go binaries for all supported platforms and creates distribution archives
4
+ * @version 0.0.1
5
+ */
6
+
7
+ const { execSync } = require('child_process');
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const os = require('os');
11
+
12
+ /**
13
+ * @typedef {Object} PlatformConfig
14
+ * @property {string} os - Operating system (darwin, linux, win32)
15
+ * @property {string} arch - Architecture (x64, arm64)
16
+ */
17
+
18
+ /** @type {PlatformConfig[]} All supported platform configurations */
19
+ const PLATFORMS = [
20
+ { os: 'darwin', arch: 'x64' },
21
+ { os: 'darwin', arch: 'arm64' },
22
+ { os: 'linux', arch: 'x64' },
23
+ { os: 'linux', arch: 'arm64' },
24
+ { os: 'win32', arch: 'x64' },
25
+ { os: 'win32', arch: 'arm64' }
26
+ ];
27
+
28
+ /**
29
+ * Builds the Mandor binary for a specific platform
30
+ * @param {PlatformConfig} platform - Platform configuration
31
+ * @param {string} sourceDir - Source directory containing Go code
32
+ * @returns {string|null} Path to the compiled binary, or null if unsupported
33
+ * @example
34
+ * const binaryPath = buildForPlatform({ os: 'darwin', arch: 'arm64' }, './cmd/mandor');
35
+ */
36
+ function buildForPlatform(platform, sourceDir) {
37
+ const { os, arch } = platform;
38
+ const outputDir = path.join(__dirname, '..', 'binaries', `${os}-${arch}`);
39
+ const outputPath = path.join(outputDir, os === 'win32' ? 'mandor.exe' : 'mandor');
40
+
41
+ fs.mkdirSync(outputDir, { recursive: true });
42
+
43
+ console.log(`Building for ${os}-${arch}...`);
44
+
45
+ try {
46
+ execSync(`GOOS=${os} GOARCH=${arch} go build -o "${outputPath}" ${sourceDir}`, {
47
+ stdio: 'pipe',
48
+ shell: process.platform === 'win32'
49
+ });
50
+ return outputPath;
51
+ } catch (error) {
52
+ // Check stderr for unsupported pair message
53
+ const stderr = error.stderr ? error.stderr.toString() : '';
54
+ if (stderr.includes('unsupported GOOS/GOARCH pair')) {
55
+ console.log(` ⊘ Not supported on this system`);
56
+ return null;
57
+ }
58
+ console.error(` ✗ Build failed:`, error.message);
59
+ throw error;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Creates a distribution archive for a platform
65
+ * @param {PlatformConfig} platform - Platform configuration
66
+ * @returns {string|null} Path to the archive file, or null if binary doesn't exist
67
+ * @example
68
+ * const archivePath = createArchive({ os: 'linux', arch: 'x64' });
69
+ */
70
+ function createArchive(platform) {
71
+ const { os, arch } = platform;
72
+ const sourceDir = path.join(__dirname, '..', 'binaries', `${os}-${arch}`);
73
+
74
+ // Check if binary exists
75
+ const binaryExists = fs.existsSync(path.join(sourceDir, os === 'win32' ? 'mandor.exe' : 'mandor'));
76
+ if (!binaryExists) {
77
+ return null;
78
+ }
79
+
80
+ const archivePath = path.join(__dirname, '..', 'binaries', `${os}-${arch}.tar.gz`);
81
+
82
+ console.log(`Creating archive for ${os}-${arch}...`);
83
+
84
+ execSync(`tar -czf "${archivePath}" -C "${sourceDir}" .`, {
85
+ stdio: 'inherit',
86
+ shell: true
87
+ });
88
+
89
+ return archivePath;
90
+ }
91
+
92
+ /**
93
+ * Main build function - attempts to build all platforms
94
+ * @returns {Object[]} Build results for each successfully built platform
95
+ * @example
96
+ * const results = mainBuild();
97
+ * console.log(`Built ${results.length} platforms`);
98
+ */
99
+ function mainBuild() {
100
+ const sourceDir = path.join(__dirname, '..', '..', 'cmd', 'mandor');
101
+ const results = [];
102
+ const unsupported = [];
103
+
104
+ console.log(`Running on: ${os.platform()}/${os.arch()}`);
105
+ console.log('Building cross-platform binaries...\n');
106
+
107
+ // Build all platforms
108
+ for (const platform of PLATFORMS) {
109
+ const binaryPath = buildForPlatform(platform, sourceDir);
110
+ if (binaryPath) {
111
+ results.push({
112
+ platform: platform.os,
113
+ arch: platform.arch,
114
+ binaryPath,
115
+ status: 'built'
116
+ });
117
+ console.log(` ✓ Built successfully\n`);
118
+ } else {
119
+ unsupported.push({
120
+ platform: platform.os,
121
+ arch: platform.arch,
122
+ status: 'unsupported'
123
+ });
124
+ }
125
+ }
126
+
127
+ // Create archives for successfully built platforms
128
+ const archiveResults = [];
129
+ for (const platform of PLATFORMS) {
130
+ const archivePath = createArchive(platform);
131
+ if (archivePath) {
132
+ const stats = fs.statSync(archivePath);
133
+ archiveResults.push({
134
+ platform: platform.os,
135
+ arch: platform.arch,
136
+ archivePath,
137
+ archiveSize: stats.size
138
+ });
139
+
140
+ const existing = results.find(r => r.platform === platform.os && r.arch === platform.arch);
141
+ if (existing) {
142
+ existing.archivePath = archivePath;
143
+ existing.archiveSize = stats.size;
144
+ }
145
+ }
146
+ }
147
+
148
+ // Summary
149
+ console.log('─'.repeat(50));
150
+ console.log(`Build complete!`);
151
+ console.log(` Built: ${archiveResults.length} platforms`);
152
+ console.log(` Unsupported: ${unsupported.length} platforms`);
153
+
154
+ if (unsupported.length > 0) {
155
+ console.log('\nUnsupported combinations (need different build environment):');
156
+ unsupported.forEach(u => {
157
+ console.log(` - ${u.platform}/${u.arch}`);
158
+ });
159
+ }
160
+
161
+ return archiveResults;
162
+ }
163
+
164
+ // Run if executed directly
165
+ if (require.main === module) {
166
+ const results = mainBuild();
167
+ if (results.length > 0) {
168
+ console.log('\nBuilt platforms:');
169
+ console.table(results.map(r => ({
170
+ Platform: `${r.platform}/${r.arch}`,
171
+ 'Archive Size': `${(r.archiveSize / 1024).toFixed(1)} KB`
172
+ })));
173
+
174
+ console.log('Archives location: npm/binaries/');
175
+ }
176
+ }
177
+
178
+ module.exports = {
179
+ PLATFORMS,
180
+ buildForPlatform,
181
+ createArchive,
182
+ mainBuild
183
+ };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@mandors/cli",
3
+ "version": "0.0.1",
4
+ "description": "Event-based task manager CLI for AI agent workflows",
5
+ "main": "npm/lib/index.js",
6
+ "bin": {
7
+ "mandor": "./npm/bin/mandor"
8
+ },
9
+ "os": [
10
+ "darwin",
11
+ "linux",
12
+ "win32"
13
+ ],
14
+ "cpu": [
15
+ "x64",
16
+ "arm64"
17
+ ],
18
+ "engines": {
19
+ "node": ">=16.0.0"
20
+ },
21
+ "scripts": {
22
+ "postinstall": "node npm/lib/install.js",
23
+ "prepublishOnly": "npm run build",
24
+ "preversion": "npm run build",
25
+ "build": "node npm/scripts/build.js",
26
+ "build:darwin:x64": "GOOS=darwin GOARCH=x64 go build -o binaries/darwin-x64/mandor ./cmd/mandor",
27
+ "build:darwin:arm64": "GOOS=darwin GOARCH=arm64 go build -o binaries/darwin-arm64/mandor ./cmd/mandor",
28
+ "build:linux:x64": "GOOS=linux GOARCH=x64 go build -o binaries/linux-x64/mandor ./cmd/mandor",
29
+ "build:linux:arm64": "GOOS=linux GOARCH=arm64 go build -o binaries/linux-arm64/mandor ./cmd/mandor",
30
+ "build:win32:x64": "GOOS=win32 GOARCH=x64 go build -o binaries/win32-x64/mandor.exe ./cmd/mandor",
31
+ "build:win32:arm64": "GOOS=win32 GOARCH=arm64 go build -o binaries/win32-arm64/mandor.exe ./cmd/mandor",
32
+ "version:major": "npm version major && git push --follow-tags",
33
+ "version:minor": "npm version minor && git push --follow-tags",
34
+ "version:patch": "npm version patch && git push --follow-tags",
35
+ "version:beta": "npm version prerelease --preid=beta && git push --follow-tags",
36
+ "publish:beta": "npm publish --tag beta --access public",
37
+ "publish:latest": "npm publish --access public"
38
+ },
39
+ "keywords": [
40
+ "mandor",
41
+ "task-manager",
42
+ "cli",
43
+ "ai-agent",
44
+ "workflow",
45
+ "event-sourcing"
46
+ ],
47
+ "author": "",
48
+ "license": "MIT",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/sanxzy/mandor.git",
52
+ "directory": "npm"
53
+ },
54
+ "bugs": {
55
+ "url": "https://github.com/sanxzy/mandor/issues"
56
+ },
57
+ "homepage": "https://github.com/sanxzy/mandor#readme"
58
+ }