@united-robotics/cli 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/dist/index.d.ts +1 -0
- package/dist/index.js +68 -0
- package/package.json +37 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
6
|
+
import { homedir } from "os";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { spawnSync } from "child_process";
|
|
9
|
+
var configDir = join(homedir(), ".united-robotics");
|
|
10
|
+
var configPath = join(configDir, "config.json");
|
|
11
|
+
var defaultApiUrl = process.env.UR_API_URL ?? "https://united-robotics.rollersoft.com.au";
|
|
12
|
+
function load() {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(readFileSync(configPath, "utf8"));
|
|
15
|
+
} catch {
|
|
16
|
+
return { apiUrl: defaultApiUrl };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function save(config) {
|
|
20
|
+
mkdirSync(configDir, { recursive: true });
|
|
21
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
22
|
+
}
|
|
23
|
+
async function api(path, init = {}) {
|
|
24
|
+
const cfg = load();
|
|
25
|
+
const res = await fetch(`${cfg.apiUrl}${path}`, { ...init, headers: { authorization: `Bearer ${cfg.token ?? ""}`, "content-type": "application/json", ...init.headers ?? {} } });
|
|
26
|
+
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
|
|
27
|
+
return res.json();
|
|
28
|
+
}
|
|
29
|
+
var program = new Command();
|
|
30
|
+
program.name("ur").description("United Robotics customer CLI").version("0.1.0");
|
|
31
|
+
program.command("login").requiredOption("--token <token>").option("--api <url>").action((opts) => {
|
|
32
|
+
const cfg = load();
|
|
33
|
+
save({ apiUrl: opts.api ?? cfg.apiUrl ?? defaultApiUrl, token: opts.token });
|
|
34
|
+
console.log("Logged in to United Robotics");
|
|
35
|
+
});
|
|
36
|
+
program.command("whoami").action(async () => console.log(JSON.stringify(await api("/api/me"), null, 2)));
|
|
37
|
+
program.command("team").argument("<cmd>").action(async (cmd) => {
|
|
38
|
+
if (cmd !== "ls") throw new Error("supported: ur team ls");
|
|
39
|
+
console.log(JSON.stringify(await api("/api/teams"), null, 2));
|
|
40
|
+
});
|
|
41
|
+
var project = program.command("project");
|
|
42
|
+
project.command("ls").option("--team <teamId>").action(async (opts) => console.log(JSON.stringify(await api(`/api/projects${opts.team ? `?team=${encodeURIComponent(opts.team)}` : ""}`), null, 2)));
|
|
43
|
+
project.command("show").argument("<projectId>").action(async (projectId) => console.log(JSON.stringify({ projectId, repos: await api(`/api/projects/${projectId}/repos`) }, null, 2)));
|
|
44
|
+
project.command("clone").argument("<projectId>").option("--dest <path>").action(async (projectId, opts) => {
|
|
45
|
+
const repos = await api(`/api/projects/${projectId}/repos`);
|
|
46
|
+
const primary = repos.find((r) => r.kind === "primary") ?? repos[0];
|
|
47
|
+
if (!primary) throw new Error("No repo found");
|
|
48
|
+
const args = ["clone", "--recurse-submodules", primary.url];
|
|
49
|
+
if (opts.dest) args.push(opts.dest);
|
|
50
|
+
const child = spawnSync("git", args, { stdio: "inherit" });
|
|
51
|
+
process.exit(child.status ?? 1);
|
|
52
|
+
});
|
|
53
|
+
program.command("repo").argument("<cmd>").argument("<projectId>").action(async (cmd, projectId) => {
|
|
54
|
+
if (cmd !== "ls") throw new Error("supported: ur repo ls <projectId>");
|
|
55
|
+
console.log(JSON.stringify(await api(`/api/projects/${projectId}/repos`), null, 2));
|
|
56
|
+
});
|
|
57
|
+
var github = program.command("github");
|
|
58
|
+
github.command("token").option("--project <projectId>", "project id", "skinspirit-main").option("--json", "emit full JSON").action(async (opts) => {
|
|
59
|
+
const result = await api(`/api/projects/${opts.project}/github-token`, { method: "POST" });
|
|
60
|
+
if (opts.json) console.log(JSON.stringify(result, null, 2));
|
|
61
|
+
else console.log(result.token);
|
|
62
|
+
});
|
|
63
|
+
program.command("codex").argument("<cmd>").option("--project <projectId>", "project id", "skinspirit-main").action((cmd, opts) => {
|
|
64
|
+
if (cmd !== "onboard") throw new Error("supported: ur codex onboard");
|
|
65
|
+
const cfg = load();
|
|
66
|
+
console.log(`Establish new agent workspace by globally installing \`@united-robotics/cli\` module (ensuring there is a working node, nvm and git) and authenticate using token "ur login --token ${cfg.token ?? "<TOKEN>"}". Then run \`ur project ls\`, \`ur project clone ${opts.project}\`, and when GitHub write access is needed use \`ur github token --project ${opts.project}\` for a short-lived GitHub App token. Use that project as codex project base from now on, and familiarize yourself.`);
|
|
67
|
+
});
|
|
68
|
+
program.parseAsync();
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@united-robotics/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"ur": "dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup src/index.ts --format esm --dts --clean && chmod +x dist/index.js",
|
|
13
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"commander": "^12.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"tsup": "^8.3.5",
|
|
20
|
+
"typescript": "^5.6.3",
|
|
21
|
+
"@types/node": "^22.10.0"
|
|
22
|
+
},
|
|
23
|
+
"description": "United Robotics customer CLI",
|
|
24
|
+
"license": "UNLICENSED",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/exisz/united-robotics.git",
|
|
31
|
+
"directory": "packages/cli"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/exisz/united-robotics/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/exisz/united-robotics#readme"
|
|
37
|
+
}
|