@mflrevan/ucp 0.1.0

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.
package/bin/ucp.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawn } = require("child_process");
5
+ const path = require("path");
6
+ const fs = require("fs");
7
+
8
+ const ext = process.platform === "win32" ? ".exe" : "";
9
+ const bin = path.join(__dirname, "..", "native", `ucp${ext}`);
10
+
11
+ if (!fs.existsSync(bin)) {
12
+ console.error(
13
+ "ucp binary not found. Run 'npm rebuild @mflrevan/ucp' or reinstall."
14
+ );
15
+ process.exit(1);
16
+ }
17
+
18
+ const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
19
+ child.on("error", (err) => {
20
+ console.error("Failed to start ucp:", err.message);
21
+ process.exit(1);
22
+ });
23
+ child.on("exit", (code) => process.exit(code ?? 1));
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@mflrevan/ucp",
3
+ "version": "0.1.0",
4
+ "description": "Unity Control Protocol — CLI for programmatic Unity Editor control",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/mflRevan/unity-control-protocol.git"
9
+ },
10
+ "bin": {
11
+ "ucp": "bin/ucp.js"
12
+ },
13
+ "scripts": {
14
+ "postinstall": "node scripts/install.js"
15
+ },
16
+ "publishConfig": {
17
+ "registry": "https://registry.npmjs.org",
18
+ "access": "public"
19
+ },
20
+ "os": [
21
+ "darwin",
22
+ "linux",
23
+ "win32"
24
+ ],
25
+ "cpu": [
26
+ "x64",
27
+ "arm64"
28
+ ]
29
+ }
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ const https = require('https');
4
+ const http = require('http');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ const pkg = require('../package.json');
9
+ const version = pkg.version;
10
+
11
+ const PLATFORM_MAP = {
12
+ 'darwin-x64': 'ucp-darwin-x64',
13
+ 'darwin-arm64': 'ucp-darwin-arm64',
14
+ 'linux-x64': 'ucp-linux-x64',
15
+ 'win32-x64': 'ucp-win32-x64.exe',
16
+ };
17
+
18
+ const key = `${process.platform}-${process.arch}`;
19
+ const artifact = PLATFORM_MAP[key];
20
+
21
+ if (!artifact) {
22
+ console.error(`Unsupported platform: ${key}`);
23
+ console.error(`Supported: ${Object.keys(PLATFORM_MAP).join(', ')}`);
24
+ process.exit(1);
25
+ }
26
+
27
+ const nativeDir = path.join(__dirname, '..', 'native');
28
+ fs.mkdirSync(nativeDir, { recursive: true });
29
+
30
+ const ext = process.platform === 'win32' ? '.exe' : '';
31
+ const dest = path.join(nativeDir, `ucp${ext}`);
32
+
33
+ // Skip download if binary already exists (local dev / rebuild)
34
+ if (fs.existsSync(dest)) {
35
+ console.log('ucp binary already present, skipping download.');
36
+ process.exit(0);
37
+ }
38
+
39
+ // Allow local binary override via env var (for local testing)
40
+ if (process.env.UCP_LOCAL_BINARY) {
41
+ const src = path.resolve(process.env.UCP_LOCAL_BINARY);
42
+ if (!fs.existsSync(src)) {
43
+ console.error(`UCP_LOCAL_BINARY set but file not found: ${src}`);
44
+ process.exit(1);
45
+ }
46
+ fs.copyFileSync(src, dest);
47
+ if (process.platform !== 'win32') fs.chmodSync(dest, 0o755);
48
+ console.log(`Copied local binary from ${src}`);
49
+ process.exit(0);
50
+ }
51
+
52
+ const url = `https://github.com/mflRevan/unity-control-protocol/releases/download/v${version}/${artifact}`;
53
+ console.log(`Downloading ucp v${version} for ${key}...`);
54
+ console.log(` ${url}`);
55
+
56
+ download(url, dest, (err) => {
57
+ if (err) {
58
+ console.error(`Failed to download ucp: ${err.message}`);
59
+ console.error('You can build from source instead: cd cli && cargo build --release');
60
+ process.exit(1);
61
+ }
62
+ if (process.platform !== 'win32') {
63
+ fs.chmodSync(dest, 0o755);
64
+ }
65
+ console.log('ucp installed successfully.');
66
+ });
67
+
68
+ function download(url, dest, cb, redirects) {
69
+ if (redirects === undefined) redirects = 0;
70
+ if (redirects > 5) return cb(new Error('Too many redirects'));
71
+
72
+ var get = url.startsWith('https') ? https.get : http.get;
73
+ get(url, function (res) {
74
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
75
+ return download(res.headers.location, dest, cb, redirects + 1);
76
+ }
77
+ if (res.statusCode !== 200) {
78
+ res.resume();
79
+ return cb(new Error(`HTTP ${res.statusCode} from ${url}`));
80
+ }
81
+ var file = fs.createWriteStream(dest);
82
+ res.pipe(file);
83
+ file.on('finish', function () {
84
+ file.close(cb);
85
+ });
86
+ file.on('error', function (err) {
87
+ fs.unlink(dest, function () {});
88
+ cb(err);
89
+ });
90
+ }).on('error', cb);
91
+ }