robodev 0.13.0 → 0.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "robodev",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "CLI for Robodev Starbase — create, auth, link, and deploy hosted apps",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  resolveStarterTree,
26
26
  type Starter,
27
27
  } from "./emit-starter.js";
28
+ import { parseCreateArgs } from "./parse-create-args.js";
28
29
 
29
30
  const execFileAsync = promisify(execFile);
30
31
 
@@ -38,7 +39,7 @@ Commands:
38
39
  logout Remove stored credentials
39
40
  whoami Show the signed-in user
40
41
  projects List your projects
41
- create [path] [--starter <id>] [--empty] Create a project, scaffold a starter, and deploy
42
+ create [path] [--starter <id>] [--empty] [--org <id>] Create a project, scaffold a starter, and deploy
42
43
  link [projectId] Write .robodev in the current folder
43
44
  deploy [--force] Deploy database.ts, api/*.ts, jobs, and frontend files (no Vite / npm run build)
44
45
  `);
@@ -279,48 +280,47 @@ function validIdsMessage(starters: Starter[]): string {
279
280
  return `Valid ids: ${starters.map((starter) => starter.id).join(", ")}`;
280
281
  }
281
282
 
282
- function parseCreateArgs(args: string[]): { path?: string; starterId?: string } {
283
- let path: string | undefined;
284
- let starterId: string | undefined;
285
- let empty = false;
286
- for (let i = 0; i < args.length; i++) {
287
- const arg = args[i];
288
- if (arg === "--empty") {
289
- empty = true;
290
- continue;
291
- }
292
- if (arg === "--starter") {
293
- const value = args[i + 1];
294
- if (!value || value.startsWith("-")) {
295
- throw new Error("Missing value for --starter");
296
- }
297
- starterId = value;
298
- i += 1;
299
- continue;
300
- }
301
- if (arg.startsWith("--starter=")) {
302
- const value = arg.slice("--starter=".length);
303
- if (!value) {
304
- throw new Error("Missing value for --starter");
305
- }
306
- starterId = value;
307
- continue;
308
- }
309
- if (arg.startsWith("-")) {
310
- throw new Error(`Unknown flag ${arg}`);
311
- }
312
- if (path !== undefined) {
313
- throw new Error(`Unexpected argument ${arg}`);
314
- }
315
- path = arg;
283
+ type Organization = {
284
+ id: string;
285
+ name: string;
286
+ plan: string;
287
+ createdAt: string;
288
+ role: "admin" | "developer";
289
+ };
290
+
291
+ function validOrgIdsMessage(orgs: Organization[]): string {
292
+ return `Valid ids: ${orgs.map((org) => org.id).join(", ")}`;
293
+ }
294
+
295
+ async function resolveOrganization(flagId: string | undefined): Promise<string | undefined> {
296
+ const { organizations } = await authed<{ organizations: Organization[] }>("/v1/organizations");
297
+ const adminOrgs = organizations.filter((org) => org.role === "admin");
298
+ if (flagId !== undefined) {
299
+ return flagId;
300
+ }
301
+ if (adminOrgs.length === 0) {
302
+ throw new Error("You need an admin role in an organization to create a project.");
303
+ }
304
+ if (adminOrgs.length === 1 || !stdin.isTTY) {
305
+ return undefined;
306
+ }
307
+ console.log("Organizations:");
308
+ adminOrgs.forEach((org, i) => {
309
+ console.log(` ${i + 1}. ${org.name} (${org.id})`);
310
+ });
311
+ const answer = (await prompt("Organization number or id: ")).trim();
312
+ if (!answer) {
313
+ throw new Error(`Unknown organization "". ${validOrgIdsMessage(adminOrgs)}`);
316
314
  }
317
- if (empty && starterId !== undefined) {
318
- throw new Error("Use either --empty or --starter, not both.");
315
+ const asIndex = Number(answer);
316
+ if (Number.isInteger(asIndex) && asIndex >= 1 && asIndex <= adminOrgs.length) {
317
+ return adminOrgs[asIndex - 1].id;
319
318
  }
320
- if (empty) {
321
- starterId = "empty";
319
+ const found = adminOrgs.find((org) => org.id === answer);
320
+ if (!found) {
321
+ throw new Error(`Unknown organization "${answer}". ${validOrgIdsMessage(adminOrgs)}`);
322
322
  }
323
- return { path, starterId };
323
+ return found.id;
324
324
  }
325
325
 
326
326
  async function resolveStarter(flagId: string | undefined): Promise<Starter> {
@@ -438,9 +438,10 @@ async function runCreate(args: string[]): Promise<void> {
438
438
  await assertCreatable(root);
439
439
 
440
440
  const name = projectNameFromPath(root);
441
+ const organizationId = await resolveOrganization(parsed.orgId);
441
442
  const project = await authed<Project>("/v1/projects", {
442
443
  method: "POST",
443
- body: JSON.stringify({ name }),
444
+ body: JSON.stringify(organizationId ? { name, organizationId } : { name }),
444
445
  });
445
446
 
446
447
  const { treeRoot } = await resolveStarterTree();
@@ -0,0 +1,26 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { parseCreateArgs } from "./parse-create-args.js";
4
+
5
+ test("parseCreateArgs accepts --org with starter flags", () => {
6
+ assert.deepEqual(parseCreateArgs(["app", "--starter", "space", "--org", "org_1"]), {
7
+ path: "app",
8
+ starterId: "space",
9
+ orgId: "org_1",
10
+ });
11
+ assert.deepEqual(parseCreateArgs(["--empty", "--org=org_2"]), {
12
+ path: undefined,
13
+ starterId: "empty",
14
+ orgId: "org_2",
15
+ });
16
+ });
17
+
18
+ test("parseCreateArgs rejects a missing --org value", () => {
19
+ assert.throws(() => parseCreateArgs(["--org"]), /Missing value for --org/);
20
+ assert.throws(() => parseCreateArgs(["--org="]), /Missing value for --org/);
21
+ assert.throws(() => parseCreateArgs(["--org", "--empty"]), /Missing value for --org/);
22
+ });
23
+
24
+ test("parseCreateArgs rejects unknown flags including --organization", () => {
25
+ assert.throws(() => parseCreateArgs(["--organization", "org_1"]), /Unknown flag --organization/);
26
+ });
@@ -0,0 +1,63 @@
1
+ export type CreateArgs = { path?: string; starterId?: string; orgId?: string };
2
+
3
+ export function parseCreateArgs(args: string[]): CreateArgs {
4
+ let path: string | undefined;
5
+ let starterId: string | undefined;
6
+ let orgId: string | undefined;
7
+ let empty = false;
8
+ for (let i = 0; i < args.length; i++) {
9
+ const arg = args[i];
10
+ if (arg === "--empty") {
11
+ empty = true;
12
+ continue;
13
+ }
14
+ if (arg === "--starter") {
15
+ const value = args[i + 1];
16
+ if (!value || value.startsWith("-")) {
17
+ throw new Error("Missing value for --starter");
18
+ }
19
+ starterId = value;
20
+ i += 1;
21
+ continue;
22
+ }
23
+ if (arg.startsWith("--starter=")) {
24
+ const value = arg.slice("--starter=".length);
25
+ if (!value) {
26
+ throw new Error("Missing value for --starter");
27
+ }
28
+ starterId = value;
29
+ continue;
30
+ }
31
+ if (arg === "--org") {
32
+ const value = args[i + 1];
33
+ if (!value || value.startsWith("-")) {
34
+ throw new Error("Missing value for --org");
35
+ }
36
+ orgId = value;
37
+ i += 1;
38
+ continue;
39
+ }
40
+ if (arg.startsWith("--org=")) {
41
+ const value = arg.slice("--org=".length);
42
+ if (!value) {
43
+ throw new Error("Missing value for --org");
44
+ }
45
+ orgId = value;
46
+ continue;
47
+ }
48
+ if (arg.startsWith("-")) {
49
+ throw new Error(`Unknown flag ${arg}`);
50
+ }
51
+ if (path !== undefined) {
52
+ throw new Error(`Unexpected argument ${arg}`);
53
+ }
54
+ path = arg;
55
+ }
56
+ if (empty && starterId !== undefined) {
57
+ throw new Error("Use either --empty or --starter, not both.");
58
+ }
59
+ if (empty) {
60
+ starterId = "empty";
61
+ }
62
+ return { path, starterId, orgId };
63
+ }
@@ -11,7 +11,7 @@
11
11
  "@robodev-ai/sdk": "^0.6.0"
12
12
  },
13
13
  "devDependencies": {
14
- "robodev": "^0.13.0",
14
+ "robodev": "^0.14.0",
15
15
  "rulesync": "^8.18.0",
16
16
  "typescript": "^5.9.2"
17
17
  }
@@ -10,7 +10,7 @@
10
10
  "@robodev-ai/sdk": "^0.6.0"
11
11
  },
12
12
  "devDependencies": {
13
- "robodev": "^0.13.0",
13
+ "robodev": "^0.14.0",
14
14
  "typescript": "^5.9.2"
15
15
  }
16
16
  }
@@ -10,7 +10,7 @@
10
10
  "@robodev-ai/sdk": "^0.6.0"
11
11
  },
12
12
  "devDependencies": {
13
- "robodev": "^0.13.0",
13
+ "robodev": "^0.14.0",
14
14
  "typescript": "^5.9.2"
15
15
  }
16
16
  }
@@ -11,7 +11,7 @@
11
11
  "@robodev-ai/sdk": "^0.6.0"
12
12
  },
13
13
  "devDependencies": {
14
- "robodev": "^0.13.0",
14
+ "robodev": "^0.14.0",
15
15
  "rulesync": "^8.18.0",
16
16
  "typescript": "^5.9.2"
17
17
  }