@virtualagency/server 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/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @virtualagency/server
|
|
2
|
+
|
|
3
|
+
Rust-powered Virtual Agency server packaged as an npm CLI.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @virtualagency/server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or run without installing globally:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx @virtualagency/server
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
virtual-agency-server --port 1337
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The `--port` flag sets `VIRTUAL_AGENCY_PORT` for the server process.
|
|
24
|
+
|
|
25
|
+
## Custom Binary
|
|
26
|
+
|
|
27
|
+
If you want to run your own binary build, set:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
VIRTUAL_AGENCY_SERVER_BINARY=/absolute/path/to/virtual-agency-server virtual-agency-server
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Packaging Notes
|
|
34
|
+
|
|
35
|
+
This package expects prebuilt binaries to exist in `dist/` with names:
|
|
36
|
+
|
|
37
|
+
- `virtual-agency-server-macos-arm64`
|
|
38
|
+
- `virtual-agency-server-macos-x64`
|
|
39
|
+
- `virtual-agency-server-linux-x64`
|
|
40
|
+
- `virtual-agency-server-linux-arm64`
|
|
41
|
+
- `virtual-agency-server-windows-x64.exe`
|
|
42
|
+
- `virtual-agency-server-windows-arm64.exe`
|
|
43
|
+
|
|
44
|
+
Only binaries that exist at publish time are included in the npm tarball.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { spawn } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const DIST_BINARY_NAMES = {
|
|
8
|
+
darwin: {
|
|
9
|
+
arm64: "virtual-agency-server-macos-arm64",
|
|
10
|
+
x64: "virtual-agency-server-macos-x64",
|
|
11
|
+
},
|
|
12
|
+
linux: {
|
|
13
|
+
x64: "virtual-agency-server-linux-x64",
|
|
14
|
+
arm64: "virtual-agency-server-linux-arm64",
|
|
15
|
+
},
|
|
16
|
+
win32: {
|
|
17
|
+
x64: "virtual-agency-server-windows-x64.exe",
|
|
18
|
+
arm64: "virtual-agency-server-windows-arm64.exe",
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function printHelp() {
|
|
23
|
+
console.log(`virtual-agency-server\n\nRuns the Virtual Agency Rust server binary.\n\nUsage:\n virtual-agency-server [--port <number>]\n virtual-agency-server --help\n\nOptions:\n --port <number> Sets VIRTUAL_AGENCY_PORT for the server process.\n -h, --help Show this help message.\n\nEnvironment:\n VIRTUAL_AGENCY_SERVER_BINARY Absolute path to a custom server binary.\n VIRTUAL_AGENCY_PORT Default port (used when --port is not passed).\n`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseArgs(argv) {
|
|
27
|
+
let port;
|
|
28
|
+
const passthrough = [];
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
31
|
+
const arg = argv[i];
|
|
32
|
+
|
|
33
|
+
if (arg === "-h" || arg === "--help") {
|
|
34
|
+
return { help: true, port, passthrough: [] };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (arg === "--port") {
|
|
38
|
+
const value = argv[i + 1];
|
|
39
|
+
if (!value || value.startsWith("-")) {
|
|
40
|
+
throw new Error("Missing value for --port");
|
|
41
|
+
}
|
|
42
|
+
port = value;
|
|
43
|
+
i += 1;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (arg.startsWith("--port=")) {
|
|
48
|
+
const value = arg.slice("--port=".length);
|
|
49
|
+
if (!value) {
|
|
50
|
+
throw new Error("Missing value for --port");
|
|
51
|
+
}
|
|
52
|
+
port = value;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
passthrough.push(arg);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { help: false, port, passthrough };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resolveBinaryPath() {
|
|
63
|
+
const custom = process.env.VIRTUAL_AGENCY_SERVER_BINARY;
|
|
64
|
+
if (custom) {
|
|
65
|
+
return path.resolve(custom);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const byArch = DIST_BINARY_NAMES[process.platform];
|
|
69
|
+
const fileName = byArch && byArch[process.arch];
|
|
70
|
+
if (!fileName) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return path.join(__dirname, "..", "dist", fileName);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function ensureExecutable(binaryPath) {
|
|
78
|
+
if (process.platform === "win32") return;
|
|
79
|
+
const stat = fs.statSync(binaryPath);
|
|
80
|
+
const executeMask = 0o111;
|
|
81
|
+
if ((stat.mode & executeMask) === executeMask) return;
|
|
82
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function start() {
|
|
86
|
+
let parsed;
|
|
87
|
+
try {
|
|
88
|
+
parsed = parseArgs(process.argv.slice(2));
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`[virtual-agency-server] ${error.message}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (parsed.help) {
|
|
95
|
+
printHelp();
|
|
96
|
+
process.exit(0);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const binaryPath = resolveBinaryPath();
|
|
100
|
+
if (!binaryPath) {
|
|
101
|
+
console.error(
|
|
102
|
+
`[virtual-agency-server] Unsupported platform/arch: ${process.platform}/${process.arch}. ` +
|
|
103
|
+
"Set VIRTUAL_AGENCY_SERVER_BINARY to run a custom binary.",
|
|
104
|
+
);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!fs.existsSync(binaryPath)) {
|
|
109
|
+
console.error(
|
|
110
|
+
`[virtual-agency-server] Missing binary at ${binaryPath}. ` +
|
|
111
|
+
"Build or add the matching file under apps/server/dist before publishing.",
|
|
112
|
+
);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
ensureExecutable(binaryPath);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(`[virtual-agency-server] Failed to prepare binary: ${error.message}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const env = {
|
|
124
|
+
...process.env,
|
|
125
|
+
VIRTUAL_AGENCY_PORT: parsed.port || process.env.VIRTUAL_AGENCY_PORT || "1337",
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const child = spawn(binaryPath, parsed.passthrough, {
|
|
129
|
+
stdio: "inherit",
|
|
130
|
+
env,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
child.on("error", (error) => {
|
|
134
|
+
console.error(`[virtual-agency-server] Failed to launch binary: ${error.message}`);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
child.on("exit", (code, signal) => {
|
|
139
|
+
if (signal) {
|
|
140
|
+
process.kill(process.pid, signal);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
process.exit(code ?? 1);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
start();
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@virtualagency/server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Virtual Agency Rust server packaged as an npm global CLI",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/amirdauti/virtualagency.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/amirdauti/virtualagency",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/amirdauti/virtualagency/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "commonjs",
|
|
15
|
+
"bin": {
|
|
16
|
+
"virtual-agency-server": "bin/virtual-agency-server.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/virtual-agency-server.js",
|
|
20
|
+
"dist/virtual-agency-server-macos-arm64",
|
|
21
|
+
"dist/virtual-agency-server-macos-x64",
|
|
22
|
+
"dist/virtual-agency-server-linux-x64",
|
|
23
|
+
"dist/virtual-agency-server-linux-arm64",
|
|
24
|
+
"dist/virtual-agency-server-windows-x64.exe",
|
|
25
|
+
"dist/virtual-agency-server-windows-arm64.exe",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "cargo build --release",
|
|
30
|
+
"build:linux": "bash ./scripts/build-linux.sh",
|
|
31
|
+
"prepack": "cargo build --release && node ./scripts/prepare-npm-dist.mjs",
|
|
32
|
+
"test:bin": "node ./bin/virtual-agency-server.js --help",
|
|
33
|
+
"release": "semantic-release"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
43
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
44
|
+
"@semantic-release/exec": "^7.1.0",
|
|
45
|
+
"@semantic-release/git": "^10.0.1",
|
|
46
|
+
"@semantic-release/github": "^11.0.6",
|
|
47
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
48
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
49
|
+
"semantic-release": "^24.2.9"
|
|
50
|
+
}
|
|
51
|
+
}
|