create-disposabl-app 0.6.3 → 0.6.5

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 CHANGED
@@ -15,14 +15,18 @@ its access checks remain installed.
15
15
  Releases publish automatically after changes reach `main`. Commit messages
16
16
  determine the next version; no manual version edit is needed.
17
17
 
18
- Choose managed setup to sign in through `disposabl login`, create an app, save its UUID in `disposabl.json`, and configure a named development preview. The service is `https://disposabl.dev`.
18
+ Choose managed setup to sign in through `disposabl login`, create an app, save its UUID in `disposabl.json`, and configure a named development preview. The service is `https://www.disposabl.dev`.
19
19
 
20
20
  ```sh
21
- bun create disposabl-app@latest my-app --setup --reference main
21
+ bun create disposabl-app@latest my-app --setup
22
22
  cd my-app
23
23
  bun run dev
24
24
  ```
25
25
 
26
+ New apps start on `main`, which is also their initial preview name. No branch prompt is needed.
27
+
26
28
  The website opens automatically and Metro starts with development-client support. Install a development build once with `bun run --cwd apps/mobile android` or `bun run --cwd apps/mobile ios`. Expo Go is not used.
27
29
 
28
- To get another development key in a worktree, run `disposabl previews token create --reference your-branch --configure .`. The reference is required; repeated requests reuse the preview and issue a new key.
30
+ To get another development key in a worktree, run `disposabl previews token create --configure .`. The branch is detected automatically, or the worktree name when detached. Repeated requests reuse the preview and issue a new key.
31
+
32
+ If managed setup fails, rerun `bun create disposabl-app@latest my-app --setup` from the parent directory. It resumes setup using the existing files and app UUID.
package/dist/disposabl.js CHANGED
@@ -278,7 +278,6 @@ var hasCredentials = async (url) => Boolean(process.env.DISPOSABL_API_KEY || (aw
278
278
 
279
279
  // ../cli/commands.ts
280
280
  import { readFile as readFile3 } from "node:fs/promises";
281
- import { execFileSync } from "node:child_process";
282
281
  import { join as join3 } from "node:path";
283
282
 
284
283
  // ../cli/preview.ts
@@ -290,9 +289,21 @@ import {
290
289
  writeFile as writeFile2,
291
290
  rm as rm2
292
291
  } from "node:fs/promises";
293
- import { join as join2, resolve } from "node:path";
292
+ import { basename, join as join2, resolve } from "node:path";
294
293
  import { randomUUID } from "node:crypto";
295
294
  import { spawnSync } from "node:child_process";
295
+ function detectReference(directory = process.cwd()) {
296
+ const git = (...args) => spawnSync("git", args, { cwd: directory, encoding: "utf8" }).stdout?.trim();
297
+ const branch = git("symbolic-ref", "--quiet", "--short", "HEAD");
298
+ if (branch)
299
+ return branch;
300
+ const root = git("rev-parse", "--show-toplevel");
301
+ const common = git("rev-parse", "--path-format=absolute", "--git-common-dir");
302
+ const local = git("rev-parse", "--absolute-git-dir");
303
+ if (root && common && local && common !== local)
304
+ return basename(root);
305
+ throw new Error("Cannot detect a branch or worktree. Run inside the app's Git checkout or supply --reference.");
306
+ }
296
307
  async function updateEnv(file, values, remove = []) {
297
308
  const stat = await lstat(file).catch((error) => {
298
309
  if (error.code !== "ENOENT")
@@ -358,7 +369,7 @@ async function configureDevelopment(directory, value) {
358
369
  }
359
370
  function formatPreview(preview) {
360
371
  if (!preview)
361
- return "Preview not found. Create it with disposabl previews token create --reference <branch-or-worktree>.";
372
+ return "Preview not found. Create it with disposabl previews token create --configure .";
362
373
  const lines = [
363
374
  `Preview: ${preview.reference}`,
364
375
  `App: ${preview.appId}`,
@@ -386,7 +397,7 @@ function formatPreview(preview) {
386
397
  }
387
398
 
388
399
  // ../cli/commands.ts
389
- var SERVICE_ORIGIN = "https://disposabl.dev";
400
+ var SERVICE_ORIGIN = "https://www.disposabl.dev";
390
401
  async function runCli(argv = process.argv, serviceOrigin = SERVICE_ORIGIN) {
391
402
  const program = new Command().name(Object.keys(package_default.bin)[0]).version(package_default.version);
392
403
  const origin = () => apiUrl(serviceOrigin);
@@ -472,7 +483,7 @@ async function runCli(argv = process.argv, serviceOrigin = SERVICE_ORIGIN) {
472
483
  }));
473
484
  for (const field of fields) {
474
485
  const flag = `--${field.name} <value>`;
475
- if (field.required && !(field.name === "appId" && (previewGet || tokenCreate)) && !(field.name === "reference" && previewGet))
486
+ if (field.required && !(field.name === "appId" && (previewGet || tokenCreate)) && !(field.name === "reference" && (previewGet || tokenCreate)))
476
487
  command.requiredOption(flag, field.schema.type === "string" ? field.name : `${field.name} as JSON`);
477
488
  else
478
489
  command.option(flag, field.name);
@@ -484,13 +495,8 @@ async function runCli(argv = process.argv, serviceOrigin = SERVICE_ORIGIN) {
484
495
  throw new Error("No appId in disposabl.json. Run setup or pass --appId.");
485
496
  options.appId = config.appId;
486
497
  }
487
- if (previewGet && !options.reference) {
488
- try {
489
- options.reference = execFileSync("git", ["symbolic-ref", "--short", "HEAD"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
490
- } catch {
491
- throw new Error("Cannot determine the Git branch. Supply --reference with the worktree or preview name.");
492
- }
493
- }
498
+ if ((previewGet || tokenCreate) && !options.reference)
499
+ options.reference = detectReference(options.configure);
494
500
  const input = Object.fromEntries(fields.filter((field) => options[field.name] !== undefined).map((field) => [
495
501
  field.name,
496
502
  field.schema.type === "string" ? options[field.name] : JSON.parse(options[field.name])
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // index.ts
4
- import { execFileSync, spawn as spawn2, spawnSync } from "node:child_process";
4
+ import { execFileSync as execFileSync2, spawnSync as spawnSync3 } from "node:child_process";
5
5
  import { lstatSync } from "node:fs";
6
- import { resolve } from "node:path";
6
+ import { join as join4, resolve as resolve2 } from "node:path";
7
7
  import { fileURLToPath as fileURLToPath2 } from "node:url";
8
8
  import { Command, CommanderError } from "commander";
9
9
  import * as p2 from "@clack/prompts";
10
10
  // package.json
11
- var version = "0.6.3";
11
+ var version = "0.6.5";
12
12
 
13
13
  // ../disposabl-kit/platforms.ts
14
14
  var platforms = [
@@ -415,10 +415,28 @@ export const Route = createFileRoute("/_providers/_authenticated/dashboard")({
415
415
  }
416
416
 
417
417
  // setup.ts
418
- import { spawn } from "node:child_process";
418
+ import { execFileSync, spawn, spawnSync as spawnSync2 } from "node:child_process";
419
419
  import { readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
420
- import { join as join2 } from "node:path";
420
+ import { join as join3 } from "node:path";
421
421
  import { fileURLToPath } from "node:url";
422
+
423
+ // ../cli/preview.ts
424
+ import { basename, join as join2, resolve } from "node:path";
425
+ import { spawnSync } from "node:child_process";
426
+ function detectReference(directory = process.cwd()) {
427
+ const git = (...args) => spawnSync("git", args, { cwd: directory, encoding: "utf8" }).stdout?.trim();
428
+ const branch = git("symbolic-ref", "--quiet", "--short", "HEAD");
429
+ if (branch)
430
+ return branch;
431
+ const root = git("rev-parse", "--show-toplevel");
432
+ const common = git("rev-parse", "--path-format=absolute", "--git-common-dir");
433
+ const local = git("rev-parse", "--absolute-git-dir");
434
+ if (root && common && local && common !== local)
435
+ return basename(root);
436
+ throw new Error("Cannot detect a branch or worktree. Run inside the app's Git checkout or supply --reference.");
437
+ }
438
+
439
+ // setup.ts
422
440
  var runDisposabl = (args, interactive = false) => new Promise((resolve, reject) => {
423
441
  const child = spawn(process.execPath, [fileURLToPath(new URL("./disposabl.js", import.meta.url)), ...args], {
424
442
  stdio: interactive ? ["inherit", "inherit", "inherit"] : ["ignore", "pipe", "pipe"]
@@ -431,7 +449,7 @@ var runDisposabl = (args, interactive = false) => new Promise((resolve, reject)
431
449
  child.once("error", reject);
432
450
  child.once("close", (code) => {
433
451
  if (code !== 0) {
434
- reject(new Error(`disposabl ${args.slice(0, 3).join(" ")} failed. The project remains available; retry setup from its directory.`));
452
+ reject(new Error(`disposabl ${args.slice(0, 3).join(" ")} failed. Your files are saved. Retry from the parent directory: bun create disposabl-app@latest <app-directory> --setup`));
435
453
  return;
436
454
  }
437
455
  try {
@@ -441,9 +459,8 @@ var runDisposabl = (args, interactive = false) => new Promise((resolve, reject)
441
459
  }
442
460
  });
443
461
  });
444
- async function setupApp(directory, name, reference, run = runDisposabl) {
445
- if (!reference || reference.trim() !== reference || reference.length > 200 || [...reference].some((char) => char.charCodeAt(0) <= 32 || char.charCodeAt(0) === 127))
446
- throw new Error("Supply --reference with a branch, worktree name, or main.");
462
+ async function setupApp(directory, name, run = runDisposabl) {
463
+ const reference = detectReference(directory);
447
464
  const status = await run(["login", "status"]);
448
465
  if (!status.currentUser) {
449
466
  await run(["login"], true);
@@ -451,7 +468,7 @@ async function setupApp(directory, name, reference, run = runDisposabl) {
451
468
  if (!verified.currentUser)
452
469
  throw new Error("Login completed without a verified user.");
453
470
  }
454
- const path = join2(directory, "disposabl.json");
471
+ const path = join3(directory, "disposabl.json");
455
472
  const config = JSON.parse(await readFile2(path, "utf8"));
456
473
  if (config.appId) {
457
474
  await run(["apps", "get", "--appId", config.appId]);
@@ -481,10 +498,44 @@ async function setupApp(directory, name, reference, run = runDisposabl) {
481
498
  ]);
482
499
  return config.appId;
483
500
  }
501
+ async function install(directory, interactive) {
502
+ await new Promise((done, reject) => {
503
+ const child = spawn("bun", ["install"], {
504
+ cwd: directory,
505
+ stdio: ["ignore", "pipe", "pipe"],
506
+ env: { ...process.env, NODE_ENV: "development" }
507
+ });
508
+ let detail = "";
509
+ const onData = (chunk) => {
510
+ detail = (detail + chunk.toString()).slice(-4000);
511
+ if (!interactive)
512
+ process.stderr.write(chunk);
513
+ };
514
+ child.stdout.on("data", onData);
515
+ child.stderr.on("data", onData);
516
+ child.once("error", reject);
517
+ child.once("close", (code) => code === 0 ? done() : reject(new Error("bun install failed. The project was created at " + directory + `. Run bun install there to retry.
518
+ ` + detail.trim())));
519
+ });
520
+ }
521
+ function commitApp(directory) {
522
+ const git = (...args) => execFileSync("git", args, { cwd: directory, stdio: "pipe" });
523
+ git("add", "--all");
524
+ const hasIdentity = spawnSync2("git", ["var", "GIT_AUTHOR_IDENT"], {
525
+ cwd: directory,
526
+ stdio: "ignore"
527
+ }).status === 0;
528
+ git(...hasIdentity ? [] : [
529
+ "-c",
530
+ "user.name=create-disposabl-app",
531
+ "-c",
532
+ "user.email=create-disposabl-app@users.noreply.github.com"
533
+ ], "-c", "commit.gpgsign=false", "commit", "-m", "Initial commit");
534
+ }
484
535
 
485
536
  // index.ts
486
537
  var jsonOutput = process.argv.slice(2).includes("--json");
487
- var program = new Command("create-disposabl-app").description("Create a Disposabl starter. Web is always included.").version(version, "-v, --version").argument("[appname]", "App name and new directory").option("--platforms <ids>", "Comma-separated platform IDs; Web is always included").option("--features <ids>", "Comma-separated feature IDs, or none (default: authentication)").option("-y, --yes", "Skip prompts; include Web and authentication by default").option("--setup", "Sign in to Disposabl and configure a development preview").option("--reference <name>", "Branch or worktree name for setup (including main)").option("--skip-install", "Create files without running bun install").option("--list-options", "List every platform and feature, including disabled choices").option("--json", "Skip prompts and emit a JSON result or error; install logs go to stderr").helpOption("-h, --help").addHelpText("after", `
538
+ var program = new Command("create-disposabl-app").description("Create a Disposabl starter. Web is always included.").version(version, "-v, --version").argument("[appname]", "App name and new directory").option("--platforms <ids>", "Comma-separated platform IDs; Web is always included").option("--features <ids>", "Comma-separated feature IDs, or none (default: authentication)").option("-y, --yes", "Skip prompts; include Web and authentication by default").option("--setup", "Sign in to Disposabl and configure a development preview").option("--skip-install", "Create files without running bun install").option("--list-options", "List every platform and feature, including disabled choices").option("--json", "Skip prompts and emit a JSON result or error; install logs go to stderr").helpOption("-h, --help").addHelpText("after", `
488
539
  Platforms:
489
540
  web (required), android, ios, api, mcp, cli, typescript-sdk
490
541
  CLI and TypeScript SDK automatically include API.
@@ -502,7 +553,7 @@ Examples:
502
553
 
503
554
  Without a TTY, the CLI never prompts. Supply an app name.
504
555
  Platform and feature choices are saved in disposabl.json.
505
- Backend authentication code is always included. Use --setup --reference main to create an app UUID and development environment through https://disposabl.dev.
556
+ Backend authentication code is always included. Use --setup to create an app UUID and development environment through https://www.disposabl.dev.
506
557
  `).configureOutput({ writeErr: () => {} }).exitOverride();
507
558
 
508
559
  class Cancelled extends Error {
@@ -547,26 +598,6 @@ Features
547
598
  console.log(`
548
599
  Web is always included. Authentication is enabled by default. Use --platforms and --features with the IDs above.`);
549
600
  }
550
- async function install(directory, interactive) {
551
- await new Promise((done, reject) => {
552
- const child = spawn2("bun", ["install"], {
553
- cwd: directory,
554
- stdio: ["ignore", "pipe", "pipe"],
555
- env: { ...process.env, NODE_ENV: "development" }
556
- });
557
- let detail = "";
558
- const onData = (chunk) => {
559
- detail = (detail + chunk.toString()).slice(-4000);
560
- if (!interactive)
561
- process.stderr.write(chunk);
562
- };
563
- child.stdout.on("data", onData);
564
- child.stderr.on("data", onData);
565
- child.once("error", reject);
566
- child.once("close", (code) => code === 0 ? done() : reject(new Error("bun install failed. The project was created at " + directory + `. Run bun install there to retry.
567
- ` + detail.trim())));
568
- });
569
- }
570
601
  async function main() {
571
602
  program.parse();
572
603
  const options = program.opts();
@@ -590,7 +621,17 @@ async function main() {
590
621
  const invalidName = validateName(name);
591
622
  if (invalidName)
592
623
  throw new Error(invalidName);
593
- let directory = resolve(name);
624
+ let directory = resolve2(name);
625
+ if (options.setup && pathExists(join4(directory, "disposabl.json"))) {
626
+ const appId = await setupApp(directory, name);
627
+ console.log(options.json ? JSON.stringify({ status: "configured", directory, appId }) : `
628
+ Setup complete.
629
+
630
+ cd ${name}
631
+ bun run dev
632
+ `);
633
+ return;
634
+ }
594
635
  let overwrite = false;
595
636
  if (pathExists(directory)) {
596
637
  overwrite = interactive && answer(await p2.confirm({
@@ -603,7 +644,7 @@ async function main() {
603
644
  do {
604
645
  const ending = `-${suffix++}`;
605
646
  name = requestedName.slice(0, 214 - ending.length) + ending;
606
- directory = resolve(name);
647
+ directory = resolve2(name);
607
648
  } while (pathExists(directory));
608
649
  if (!options.json)
609
650
  p2.log.info(`Using "${name}" instead.`);
@@ -630,16 +671,6 @@ async function main() {
630
671
  message: "Set up this app with Disposabl?",
631
672
  initialValue: false
632
673
  })));
633
- let reference = options.reference;
634
- if (managedSetup && interactive && !reference)
635
- reference = answer(await p2.text({
636
- message: "Branch or worktree name",
637
- defaultValue: "main",
638
- placeholder: "main",
639
- validate: (value) => !value?.trim() ? "Enter a branch, worktree name, or main." : undefined
640
- }));
641
- if (managedSetup && (!reference || reference !== reference.trim() || reference.length > 200 || [...reference].some((char) => char.charCodeAt(0) <= 32 || char.charCodeAt(0) === 127)))
642
- throw new Error("Setup requires --reference with a branch, worktree name, or main.");
643
674
  const config = {
644
675
  version,
645
676
  platforms: chosenPlatforms,
@@ -648,9 +679,9 @@ async function main() {
648
679
  const setup = options.json ? undefined : projectSetup(name, config);
649
680
  let installationStarted = false;
650
681
  try {
651
- if (spawnSync("git", ["--version"], { stdio: "ignore" }).status !== 0)
682
+ if (spawnSync3("git", ["--version"], { stdio: "ignore" }).status !== 0)
652
683
  throw new Error("Install Git first to create the app's initial commit.");
653
- const hasBun = spawnSync("bun", ["--version"], { stdio: "ignore" }).status === 0;
684
+ const hasBun = spawnSync3("bun", ["--version"], { stdio: "ignore" }).status === 0;
654
685
  if (!options.skipInstall && !hasBun)
655
686
  throw new Error("Install Bun first, or pass --skip-install to create the files only.");
656
687
  const template = fileURLToPath2(new URL("./templates/default", import.meta.url));
@@ -661,7 +692,7 @@ async function main() {
661
692
  await install(directory, Boolean(setup?.live));
662
693
  }
663
694
  if (hasBun)
664
- execFileSync("bun", ["fmt"], { cwd: directory, stdio: "pipe" });
695
+ execFileSync2("bun", ["fmt"], { cwd: directory, stdio: "pipe" });
665
696
  setup?.finish({
666
697
  installation: options.skipInstall ? "Skipped" : "Complete"
667
698
  });
@@ -671,21 +702,13 @@ async function main() {
671
702
  });
672
703
  throw error;
673
704
  }
674
- const git = (...args) => execFileSync("git", args, { cwd: directory, stdio: "pipe" });
675
- git("init", "--initial-branch=main");
676
- if (managedSetup)
677
- config.appId = await setupApp(directory, name, reference);
678
- git("add", "--all");
679
- const hasIdentity = spawnSync("git", ["var", "GIT_AUTHOR_IDENT"], {
705
+ execFileSync2("git", ["init", "--initial-branch=main"], {
680
706
  cwd: directory,
681
- stdio: "ignore"
682
- }).status === 0;
683
- git(...hasIdentity ? [] : [
684
- "-c",
685
- "user.name=create-disposabl-app",
686
- "-c",
687
- "user.email=create-disposabl-app@users.noreply.github.com"
688
- ], "-c", "commit.gpgsign=false", "commit", "-m", "Initial commit");
707
+ stdio: "pipe"
708
+ });
709
+ if (managedSetup)
710
+ config.appId = await setupApp(directory, name);
711
+ commitApp(directory);
689
712
  const folders = selectedFolders(config);
690
713
  if (options.json) {
691
714
  console.log(JSON.stringify({
@@ -1,11 +1,12 @@
1
1
  import { appendFile, readFile } from "node:fs/promises";
2
2
 
3
- const origin = "https://disposabl.dev";
3
+ const origin = "https://www.disposabl.dev";
4
4
  const config = JSON.parse(await readFile("disposabl.json", "utf8"));
5
5
  const [command, platform, status, detail] = process.argv.slice(2);
6
6
  if (config.appId) {
7
7
  const audience = new URL(process.env.ACTIONS_ID_TOKEN_REQUEST_URL);
8
- audience.searchParams.set("audience", origin);
8
+ // The audience is an identity identifier, independent of the HTTP hostname.
9
+ audience.searchParams.set("audience", "https://disposabl.dev");
9
10
  const identity = await fetch(audience, {
10
11
  headers: {
11
12
  Authorization: `Bearer ${process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN}`,
@@ -9,12 +9,14 @@
9
9
  */
10
10
 
11
11
  import type * as apps_actions_create from "../apps/actions/create.js";
12
+ import type * as apps_actions_setup from "../apps/actions/setup.js";
12
13
  import type * as apps_internal from "../apps/internal.js";
13
14
  import type * as auth from "../auth.js";
14
15
  import type * as github_actions_http from "../github/actions/http.js";
15
16
  import type * as github_actions_internal from "../github/actions/internal.js";
16
17
  import type * as github_actions_oidc from "../github/actions/oidc.js";
17
18
  import type * as github_actions_provision from "../github/actions/provision.js";
19
+ import type * as github_actions_secrets from "../github/actions/secrets.js";
18
20
  import type * as github_actions_tokens from "../github/actions/tokens.js";
19
21
  import type * as github_internal from "../github/internal.js";
20
22
  import type * as http from "../http.js";
@@ -36,12 +38,14 @@ import type {
36
38
 
37
39
  declare const fullApi: ApiFromModules<{
38
40
  "apps/actions/create": typeof apps_actions_create;
41
+ "apps/actions/setup": typeof apps_actions_setup;
39
42
  "apps/internal": typeof apps_internal;
40
43
  auth: typeof auth;
41
44
  "github/actions/http": typeof github_actions_http;
42
45
  "github/actions/internal": typeof github_actions_internal;
43
46
  "github/actions/oidc": typeof github_actions_oidc;
44
47
  "github/actions/provision": typeof github_actions_provision;
48
+ "github/actions/secrets": typeof github_actions_secrets;
45
49
  "github/actions/tokens": typeof github_actions_tokens;
46
50
  "github/internal": typeof github_internal;
47
51
  http: typeof http;
@@ -34,6 +34,7 @@ type Env = {
34
34
  readonly AUTH_PRIVATE_KEY: string;
35
35
  readonly CONVEX_TEAM_ID: string | undefined;
36
36
  readonly CONVEX_TEAM_TOKEN: string | undefined;
37
+ readonly EXPO_TOKEN: string | undefined;
37
38
  readonly GITHUB_CONNECTOR: string | undefined;
38
39
  readonly GITHUB_INSTALLATION_ID: string | undefined;
39
40
  readonly GITHUB_OWNER: string | undefined;
@@ -4,6 +4,7 @@ import {
4
4
  } from "@disposabl/disposabl-kit/server/lib/functions";
5
5
  import { internal } from "../../_generated/api";
6
6
  import { appArgs, appResult } from "../../validator";
7
+ import { env } from "../../_generated/server";
7
8
  import type { Infer } from "convex/values";
8
9
  type AppResult = Infer<typeof appResult>;
9
10
 
@@ -11,9 +12,21 @@ export const create = internalAction({
11
12
  platforms: true,
12
13
  args: { ...identityFields, ...appArgs },
13
14
  returns: appResult,
14
- handler: async (ctx, args): Promise<AppResult> =>
15
- ctx.runMutation(internal.apps.internal.insert, {
15
+ handler: async (ctx, args): Promise<AppResult> => {
16
+ const app = await ctx.runMutation(internal.apps.internal.insert, {
16
17
  ...args,
17
18
  appId: crypto.randomUUID(),
18
- }),
19
+ });
20
+ if (env.CONVEX_TEAM_TOKEN) {
21
+ await ctx.runAction(internal.apps.actions.setup.setup, {
22
+ userId: args.userId,
23
+ appId: app.appId,
24
+ });
25
+ return ctx.runQuery(internal.apps.internal.get, {
26
+ userId: args.userId,
27
+ appId: app.appId,
28
+ });
29
+ }
30
+ return app;
31
+ },
19
32
  });
@@ -0,0 +1,34 @@
1
+ import {
2
+ identityFields,
3
+ internalAction,
4
+ } from "@disposabl/disposabl-kit/server/lib/functions";
5
+ import { v } from "convex/values";
6
+ import { internal } from "../../_generated/api";
7
+ import { env } from "../../_generated/server";
8
+ import { ensureProject } from "../../previews/token/actions/management";
9
+
10
+ export const setup = internalAction({
11
+ args: { ...identityFields, appId: v.string() },
12
+ returns: v.number(),
13
+ handler: async (ctx, args): Promise<number> => {
14
+ const saved = await ctx.runQuery(internal.apps.internal.project, args);
15
+ const token = env.CONVEX_TEAM_TOKEN;
16
+ const teamId = env.CONVEX_TEAM_ID;
17
+ if (!token || !teamId || !/^\d+$/.test(teamId))
18
+ throw new Error(
19
+ "Managed setup requires CONVEX_TEAM_ID and CONVEX_TEAM_TOKEN on the service backend.",
20
+ );
21
+ const projectId = saved ?? (await ensureProject(token, teamId, args.appId));
22
+ if (saved === null)
23
+ await ctx.runMutation(internal.apps.internal.saveProject, {
24
+ ...args,
25
+ projectId,
26
+ });
27
+ await ctx.runAction(internal.github.actions.provision.run, args);
28
+ await ctx.runAction(internal.github.actions.secrets.configure, {
29
+ ...args,
30
+ projectId,
31
+ });
32
+ return projectId;
33
+ },
34
+ });
@@ -195,3 +195,23 @@ export const githubSetup = internalQuery({
195
195
  };
196
196
  },
197
197
  });
198
+
199
+ export const project = internalQuery({
200
+ args: { ...identityFields, appId: v.string() },
201
+ returns: v.union(v.number(), v.null()),
202
+ handler: async (ctx, { userId, appId }) =>
203
+ (await ownedApp(ctx, userId, appId)).convexProjectId ?? null,
204
+ });
205
+ export const saveProject = internalMutation({
206
+ args: {
207
+ ...identityFields,
208
+ appId: v.string(),
209
+ projectId: v.number(),
210
+ },
211
+ returns: v.null(),
212
+ handler: async (ctx, args) => {
213
+ const app = await ownedApp(ctx, args.userId, args.appId);
214
+ await ctx.db.patch("apps", app._id, { convexProjectId: args.projectId });
215
+ return null;
216
+ },
217
+ });
@@ -18,6 +18,7 @@ const app = defineApp({
18
18
  VERCEL_TEAM_ID: v.optional(v.string()),
19
19
  GITHUB_CONNECTOR: v.optional(v.string()),
20
20
  GITHUB_OWNER: v.optional(v.string()),
21
+ EXPO_TOKEN: v.optional(v.string()),
21
22
  GITHUB_INSTALLATION_ID: v.optional(v.string()),
22
23
  },
23
24
  });
@@ -0,0 +1,101 @@
1
+ "use node";
2
+
3
+ import sodium from "libsodium-wrappers";
4
+ import {
5
+ identityFields,
6
+ internalAction,
7
+ } from "@disposabl/disposabl-kit/server/lib/functions";
8
+ import { v } from "convex/values";
9
+ import { internal } from "../../_generated/api";
10
+ import { env } from "../../_generated/server";
11
+ import {
12
+ management,
13
+ ensureProduction,
14
+ } from "../../previews/token/actions/management";
15
+ import { githubRequest, githubToken } from "./tokens";
16
+
17
+ export const configure = internalAction({
18
+ args: { ...identityFields, appId: v.string(), projectId: v.number() },
19
+ returns: v.null(),
20
+ handler: async (ctx, args) => {
21
+ await ctx.runQuery(internal.apps.internal.get, {
22
+ userId: args.userId,
23
+ appId: args.appId,
24
+ });
25
+ const app = await ctx.runQuery(internal.apps.internal.githubApp, {
26
+ appId: args.appId,
27
+ });
28
+ if (!app) return null;
29
+ const repository = `${app.githubOwner}/${app.githubRepo}`;
30
+ const token = await githubToken(
31
+ app.installationId,
32
+ ["secrets:write"],
33
+ repository,
34
+ );
35
+ const path = `/repos/${repository}/actions/secrets`;
36
+ const existing = await githubRequest<{ secrets: { name: string }[] }>(
37
+ token,
38
+ `${path}?per_page=100`,
39
+ );
40
+ const names = new Set(existing.secrets.map((secret) => secret.name));
41
+ const publicKey = await githubRequest<{ key_id: string; key: string }>(
42
+ token,
43
+ `${path}/public-key`,
44
+ );
45
+ await sodium.ready;
46
+ const save = async (name: string, value: string) => {
47
+ const encrypted = sodium.crypto_box_seal(
48
+ value,
49
+ sodium.from_base64(publicKey.key, sodium.base64_variants.ORIGINAL),
50
+ );
51
+ await githubRequest(
52
+ token,
53
+ `${path}/${name}`,
54
+ {
55
+ key_id: publicKey.key_id,
56
+ encrypted_value: sodium.to_base64(
57
+ encrypted,
58
+ sodium.base64_variants.ORIGINAL,
59
+ ),
60
+ },
61
+ "PUT",
62
+ );
63
+ };
64
+ const managementToken = env.CONVEX_TEAM_TOKEN;
65
+ if (!managementToken)
66
+ throw new Error("Convex team access is not configured.");
67
+ if (!names.has("CONVEX_DEPLOY_KEY")) {
68
+ const deployment = await ensureProduction(
69
+ managementToken,
70
+ args.projectId,
71
+ );
72
+ const { deployKey } = await management<{ deployKey: string }>(
73
+ managementToken,
74
+ `/deployments/${deployment}/create_deploy_key`,
75
+ { name: "github-actions-production" },
76
+ );
77
+ if (!deployKey.startsWith(`prod:${deployment}|`))
78
+ throw new Error("Expected a production deploy key.");
79
+ await save("CONVEX_DEPLOY_KEY", deployKey);
80
+ }
81
+ if (!names.has("CONVEX_DEPLOY_KEY_PREVIEW")) {
82
+ const { previewDeployKey } = await management<{
83
+ previewDeployKey: string;
84
+ }>(
85
+ managementToken,
86
+ `/projects/${args.projectId}/create_preview_deploy_key`,
87
+ { name: "github-actions-preview" },
88
+ );
89
+ if (!previewDeployKey.startsWith("preview:"))
90
+ throw new Error("Expected a preview deploy key.");
91
+ await save("CONVEX_DEPLOY_KEY_PREVIEW", previewDeployKey);
92
+ }
93
+ if (
94
+ app.githubOwner === env.GITHUB_OWNER?.toLowerCase() &&
95
+ env.EXPO_TOKEN &&
96
+ !names.has("EXPO_TOKEN")
97
+ )
98
+ await save("EXPO_TOKEN", env.EXPO_TOKEN);
99
+ return null;
100
+ },
101
+ });
@@ -47,9 +47,10 @@ export async function githubRequest<T>(
47
47
  token: string,
48
48
  path: string,
49
49
  body?: unknown,
50
+ method = body === undefined ? "GET" : "POST",
50
51
  ): Promise<T> {
51
52
  const response = await fetch(`https://api.github.com${path}`, {
52
- method: body === undefined ? "GET" : "POST",
53
+ method,
53
54
  redirect: "error",
54
55
  signal: AbortSignal.timeout(30_000),
55
56
  headers: {
@@ -62,5 +63,9 @@ export async function githubRequest<T>(
62
63
  });
63
64
  if (!response.ok)
64
65
  throw new Error(`GitHub request failed (${response.status}).`);
65
- return response.json() as Promise<T>;
66
+ return (
67
+ response.status === 204 || response.headers.get("content-length") === "0"
68
+ ? undefined
69
+ : await response.json()
70
+ ) as T;
66
71
  }
@@ -156,19 +156,6 @@ export const create = internalMutation({
156
156
  return app.convexProjectId ?? null;
157
157
  },
158
158
  });
159
- export const saveProject = internalMutation({
160
- args: {
161
- ...identityFields,
162
- appId: v.string(),
163
- projectId: v.number(),
164
- },
165
- returns: v.null(),
166
- handler: async (ctx, args) => {
167
- const app = await ownedApp(ctx, args.userId, args.appId);
168
- await ctx.db.patch("apps", app._id, { convexProjectId: args.projectId });
169
- return null;
170
- },
171
- });
172
159
  export const finish = internalMutation({
173
160
  args: { ...identityFields, ...previewIdentity, deployment },
174
161
  returns: v.null(),
@@ -2,12 +2,12 @@ import {
2
2
  identityFields,
3
3
  internalAction,
4
4
  } from "@disposabl/disposabl-kit/server/lib/functions";
5
- import { ConvexError, v } from "convex/values";
5
+ import { v } from "convex/values";
6
6
  import { internal } from "../../../_generated/api";
7
7
  import { env } from "../../../_generated/server";
8
8
  import { previewIdentity, deployment } from "../../../validator";
9
9
  import { validateReference } from "../../internal";
10
- import { ensureDevelopment, ensureProject } from "./management";
10
+ import { ensureDevelopment } from "./management";
11
11
 
12
12
  export const create = internalAction({
13
13
  platforms: true,
@@ -34,29 +34,13 @@ export const create = internalAction({
34
34
  userId: args.userId,
35
35
  appId: args.appId,
36
36
  });
37
- const token = env.CONVEX_TEAM_TOKEN;
38
- const teamId = env.CONVEX_TEAM_ID;
39
- if (!token || !teamId || !/^\d+$/.test(teamId))
40
- throw new ConvexError(
41
- "Managed setup requires CONVEX_TEAM_ID and CONVEX_TEAM_TOKEN on the service backend.",
42
- );
43
- const saved = await ctx.runMutation(
44
- internal.previews.internal.create,
45
- args,
46
- );
47
- await ctx.runAction(internal.github.actions.provision.run, {
37
+ await ctx.runMutation(internal.previews.internal.create, args);
38
+ const projectId = await ctx.runAction(internal.apps.actions.setup.setup, {
48
39
  userId: args.userId,
49
40
  appId: args.appId,
50
41
  });
51
- const projectId = saved ?? (await ensureProject(token, teamId, args.appId));
52
- if (saved === null)
53
- await ctx.runMutation(internal.previews.internal.saveProject, {
54
- userId: args.userId,
55
- appId: args.appId,
56
- projectId,
57
- });
58
42
  const { deployKey, ...deployment } = await ensureDevelopment(
59
- token,
43
+ env.CONVEX_TEAM_TOKEN!,
60
44
  projectId,
61
45
  args.reference,
62
46
  );
@@ -131,3 +131,36 @@ export async function ensureDevelopment(
131
131
  deployKey,
132
132
  };
133
133
  }
134
+
135
+ export async function ensureProduction(token: string, projectId: number) {
136
+ const path = `/projects/${projectId}`;
137
+ const lookup = () =>
138
+ management<Deployment>(token, `${path}/deployment?defaultProd=true`);
139
+ let deployment: Deployment;
140
+ try {
141
+ deployment = await lookup();
142
+ } catch (error) {
143
+ if (!(error instanceof ManagementError) || error.status !== 404)
144
+ throw error;
145
+ try {
146
+ deployment = await management<Deployment>(
147
+ token,
148
+ `${path}/create_deployment`,
149
+ { type: "prod" },
150
+ );
151
+ } catch (error) {
152
+ try {
153
+ deployment = await lookup();
154
+ } catch {
155
+ throw error;
156
+ }
157
+ }
158
+ }
159
+ if (
160
+ deployment.kind !== "cloud" ||
161
+ deployment.deploymentType !== "prod" ||
162
+ deployment.projectId !== projectId
163
+ )
164
+ throw new Error("Expected this app's production deployment.");
165
+ return deployment.name;
166
+ }
@@ -1,6 +1,6 @@
1
1
  # Disposabl CLI
2
2
 
3
- The CLI connects to `https://disposabl.dev`.
3
+ The CLI connects to `https://www.disposabl.dev`.
4
4
 
5
5
  ```sh
6
6
  disposabl login status
@@ -8,13 +8,13 @@ disposabl login
8
8
  disposabl apps create --name my-app --platforms '["web","android","api","mcp","cli","typescript-sdk"]'
9
9
  disposabl apps list --paginationOpts '{"numItems":20,"cursor":null}'
10
10
  disposabl apps get --appId <uuid>
11
- disposabl previews token create --reference main --configure .
11
+ disposabl previews token create --configure .
12
12
  disposabl previews get
13
13
  disposabl apps delete --appId <uuid>
14
14
  disposabl logout
15
15
  ```
16
16
 
17
- Save the returned app UUID as `appId` in `disposabl.json`. Preview commands read it automatically. `previews get` also reads the current Git branch; use `--reference` for a detached checkout or a custom worktree name. Token creation requires an explicit reference, reuses that preview, and issues a fresh development key. `--configure .` writes ignored local environment files without printing the key.
17
+ Save the returned app UUID as `appId` in `disposabl.json`. Preview commands read it automatically. Both preview commands detect the current Git branch, or the worktree name when detached. Use `--reference` only to select a different preview. Token creation reuses that preview and issues a fresh development key. `--configure .` writes ignored local environment files without printing the key.
18
18
 
19
19
  `login status` returns `currentUser`. `login --no-browser` prints the OAuth URL. The CLI owns PKCE, the loopback callback, refresh, and logout. The generator only invokes these commands.
20
20
 
@@ -9,11 +9,14 @@ import {
9
9
  logout,
10
10
  } from "./auth";
11
11
  import { readFile } from "node:fs/promises";
12
- import { execFileSync } from "node:child_process";
13
12
  import { join } from "node:path";
14
- import { configureDevelopment, formatPreview } from "./preview";
13
+ import {
14
+ configureDevelopment,
15
+ detectReference,
16
+ formatPreview,
17
+ } from "./preview";
15
18
 
16
- export const SERVICE_ORIGIN = "https://disposabl.dev";
19
+ export const SERVICE_ORIGIN = "https://www.disposabl.dev";
17
20
  export async function runCli(
18
21
  argv = process.argv,
19
22
  serviceOrigin = SERVICE_ORIGIN,
@@ -145,7 +148,7 @@ export async function runCli(
145
148
  if (
146
149
  field.required &&
147
150
  !(field.name === "appId" && (previewGet || tokenCreate)) &&
148
- !(field.name === "reference" && previewGet)
151
+ !(field.name === "reference" && (previewGet || tokenCreate))
149
152
  )
150
153
  command.requiredOption(
151
154
  flag,
@@ -169,19 +172,8 @@ export async function runCli(
169
172
  );
170
173
  options.appId = config.appId;
171
174
  }
172
- if (previewGet && !options.reference) {
173
- try {
174
- options.reference = execFileSync(
175
- "git",
176
- ["symbolic-ref", "--short", "HEAD"],
177
- { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] },
178
- ).trim();
179
- } catch {
180
- throw new Error(
181
- "Cannot determine the Git branch. Supply --reference with the worktree or preview name.",
182
- );
183
- }
184
- }
175
+ if ((previewGet || tokenCreate) && !options.reference)
176
+ options.reference = detectReference(options.configure);
185
177
  const input = Object.fromEntries(
186
178
  fields
187
179
  .filter((field) => options[field.name] !== undefined)
@@ -6,10 +6,24 @@ import {
6
6
  writeFile,
7
7
  rm,
8
8
  } from "node:fs/promises";
9
- import { join, resolve } from "node:path";
9
+ import { basename, join, resolve } from "node:path";
10
10
  import { randomUUID } from "node:crypto";
11
11
  import { spawnSync } from "node:child_process";
12
12
 
13
+ export function detectReference(directory = process.cwd()) {
14
+ const git = (...args: string[]) =>
15
+ spawnSync("git", args, { cwd: directory, encoding: "utf8" }).stdout?.trim();
16
+ const branch = git("symbolic-ref", "--quiet", "--short", "HEAD");
17
+ if (branch) return branch;
18
+ const root = git("rev-parse", "--show-toplevel");
19
+ const common = git("rev-parse", "--path-format=absolute", "--git-common-dir");
20
+ const local = git("rev-parse", "--absolute-git-dir");
21
+ if (root && common && local && common !== local) return basename(root);
22
+ throw new Error(
23
+ "Cannot detect a branch or worktree. Run inside the app's Git checkout or supply --reference.",
24
+ );
25
+ }
26
+
13
27
  type Development = {
14
28
  appId: string;
15
29
  name: string;
@@ -129,7 +143,7 @@ type Preview = {
129
143
  };
130
144
  export function formatPreview(preview: Preview | null) {
131
145
  if (!preview)
132
- return "Preview not found. Create it with disposabl previews token create --reference <branch-or-worktree>.";
146
+ return "Preview not found. Create it with disposabl previews token create --configure .";
133
147
  const lines = [
134
148
  `Preview: ${preview.reference}`,
135
149
  `App: ${preview.appId}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-disposabl-app",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Create a Disposabl app",
5
5
  "type": "module",
6
6
  "license": "MIT",