create-disposabl-app 0.6.2 → 0.6.4
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 +7 -3
- package/dist/disposabl.js +18 -12
- package/dist/index.js +85 -64
- package/dist/templates/default/.github/scripts/disposabl.mjs +3 -2
- package/dist/templates/default/packages/cli/README.md +3 -3
- package/dist/templates/default/packages/cli/commands.ts +9 -17
- package/dist/templates/default/packages/cli/preview.ts +16 -2
- package/package.json +1 -1
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
|
|
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 --
|
|
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 --
|
|
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
|
-
|
|
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
|
|
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.
|
|
11
|
+
var version = "0.6.4";
|
|
12
12
|
|
|
13
13
|
// ../disposabl-kit/platforms.ts
|
|
14
14
|
var platforms = [
|
|
@@ -328,7 +328,6 @@ async function createApp(template, destination, name, config, overwrite = false)
|
|
|
328
328
|
"packages/disposabl-kit/client/routes/_auth-pages",
|
|
329
329
|
"packages/disposabl-kit/client/routes/consent.tsx",
|
|
330
330
|
"apps/web/src/router/_authenticated/dashboard.api-keys.tsx",
|
|
331
|
-
"apps/web/tests/auth-branches.test.tsx",
|
|
332
331
|
"apps/mobile/src/app/(auth)",
|
|
333
332
|
"apps/mobile/src/app/(authenticated)/account.tsx"
|
|
334
333
|
]) {
|
|
@@ -368,8 +367,7 @@ export const Route = createFileRoute("/_providers/_authenticated/dashboard")({
|
|
|
368
367
|
delete turbo.tasks["@disposabl/web#build"];
|
|
369
368
|
await writeFile(turboPath, JSON.stringify(turbo, null, 2) + `
|
|
370
369
|
`);
|
|
371
|
-
|
|
372
|
-
await rm(join(destination, "packages/disposabl-kit/server/lib", file));
|
|
370
|
+
await rm(join(destination, "packages/disposabl-kit/server/lib/docs.ts"));
|
|
373
371
|
}
|
|
374
372
|
for (const kind of ["cli", "sdk"]) {
|
|
375
373
|
const folder = join(destination, "packages", kind);
|
|
@@ -417,10 +415,28 @@ export const Route = createFileRoute("/_providers/_authenticated/dashboard")({
|
|
|
417
415
|
}
|
|
418
416
|
|
|
419
417
|
// setup.ts
|
|
420
|
-
import { spawn } from "node:child_process";
|
|
418
|
+
import { execFileSync, spawn, spawnSync as spawnSync2 } from "node:child_process";
|
|
421
419
|
import { readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
422
|
-
import { join as
|
|
420
|
+
import { join as join3 } from "node:path";
|
|
423
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
|
|
424
440
|
var runDisposabl = (args, interactive = false) => new Promise((resolve, reject) => {
|
|
425
441
|
const child = spawn(process.execPath, [fileURLToPath(new URL("./disposabl.js", import.meta.url)), ...args], {
|
|
426
442
|
stdio: interactive ? ["inherit", "inherit", "inherit"] : ["ignore", "pipe", "pipe"]
|
|
@@ -433,7 +449,7 @@ var runDisposabl = (args, interactive = false) => new Promise((resolve, reject)
|
|
|
433
449
|
child.once("error", reject);
|
|
434
450
|
child.once("close", (code) => {
|
|
435
451
|
if (code !== 0) {
|
|
436
|
-
reject(new Error(`disposabl ${args.slice(0, 3).join(" ")} failed.
|
|
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`));
|
|
437
453
|
return;
|
|
438
454
|
}
|
|
439
455
|
try {
|
|
@@ -443,9 +459,8 @@ var runDisposabl = (args, interactive = false) => new Promise((resolve, reject)
|
|
|
443
459
|
}
|
|
444
460
|
});
|
|
445
461
|
});
|
|
446
|
-
async function setupApp(directory, name,
|
|
447
|
-
|
|
448
|
-
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);
|
|
449
464
|
const status = await run(["login", "status"]);
|
|
450
465
|
if (!status.currentUser) {
|
|
451
466
|
await run(["login"], true);
|
|
@@ -453,7 +468,7 @@ async function setupApp(directory, name, reference, run = runDisposabl) {
|
|
|
453
468
|
if (!verified.currentUser)
|
|
454
469
|
throw new Error("Login completed without a verified user.");
|
|
455
470
|
}
|
|
456
|
-
const path =
|
|
471
|
+
const path = join3(directory, "disposabl.json");
|
|
457
472
|
const config = JSON.parse(await readFile2(path, "utf8"));
|
|
458
473
|
if (config.appId) {
|
|
459
474
|
await run(["apps", "get", "--appId", config.appId]);
|
|
@@ -483,10 +498,44 @@ async function setupApp(directory, name, reference, run = runDisposabl) {
|
|
|
483
498
|
]);
|
|
484
499
|
return config.appId;
|
|
485
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
|
+
}
|
|
486
535
|
|
|
487
536
|
// index.ts
|
|
488
537
|
var jsonOutput = process.argv.slice(2).includes("--json");
|
|
489
|
-
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("--
|
|
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", `
|
|
490
539
|
Platforms:
|
|
491
540
|
web (required), android, ios, api, mcp, cli, typescript-sdk
|
|
492
541
|
CLI and TypeScript SDK automatically include API.
|
|
@@ -504,7 +553,7 @@ Examples:
|
|
|
504
553
|
|
|
505
554
|
Without a TTY, the CLI never prompts. Supply an app name.
|
|
506
555
|
Platform and feature choices are saved in disposabl.json.
|
|
507
|
-
Backend authentication code is always included. Use --setup
|
|
556
|
+
Backend authentication code is always included. Use --setup to create an app UUID and development environment through https://www.disposabl.dev.
|
|
508
557
|
`).configureOutput({ writeErr: () => {} }).exitOverride();
|
|
509
558
|
|
|
510
559
|
class Cancelled extends Error {
|
|
@@ -549,26 +598,6 @@ Features
|
|
|
549
598
|
console.log(`
|
|
550
599
|
Web is always included. Authentication is enabled by default. Use --platforms and --features with the IDs above.`);
|
|
551
600
|
}
|
|
552
|
-
async function install(directory, interactive) {
|
|
553
|
-
await new Promise((done, reject) => {
|
|
554
|
-
const child = spawn2("bun", ["install"], {
|
|
555
|
-
cwd: directory,
|
|
556
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
557
|
-
env: { ...process.env, NODE_ENV: "development" }
|
|
558
|
-
});
|
|
559
|
-
let detail = "";
|
|
560
|
-
const onData = (chunk) => {
|
|
561
|
-
detail = (detail + chunk.toString()).slice(-4000);
|
|
562
|
-
if (!interactive)
|
|
563
|
-
process.stderr.write(chunk);
|
|
564
|
-
};
|
|
565
|
-
child.stdout.on("data", onData);
|
|
566
|
-
child.stderr.on("data", onData);
|
|
567
|
-
child.once("error", reject);
|
|
568
|
-
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.
|
|
569
|
-
` + detail.trim())));
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
601
|
async function main() {
|
|
573
602
|
program.parse();
|
|
574
603
|
const options = program.opts();
|
|
@@ -592,7 +621,17 @@ async function main() {
|
|
|
592
621
|
const invalidName = validateName(name);
|
|
593
622
|
if (invalidName)
|
|
594
623
|
throw new Error(invalidName);
|
|
595
|
-
let directory =
|
|
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
|
+
}
|
|
596
635
|
let overwrite = false;
|
|
597
636
|
if (pathExists(directory)) {
|
|
598
637
|
overwrite = interactive && answer(await p2.confirm({
|
|
@@ -605,7 +644,7 @@ async function main() {
|
|
|
605
644
|
do {
|
|
606
645
|
const ending = `-${suffix++}`;
|
|
607
646
|
name = requestedName.slice(0, 214 - ending.length) + ending;
|
|
608
|
-
directory =
|
|
647
|
+
directory = resolve2(name);
|
|
609
648
|
} while (pathExists(directory));
|
|
610
649
|
if (!options.json)
|
|
611
650
|
p2.log.info(`Using "${name}" instead.`);
|
|
@@ -632,16 +671,6 @@ async function main() {
|
|
|
632
671
|
message: "Set up this app with Disposabl?",
|
|
633
672
|
initialValue: false
|
|
634
673
|
})));
|
|
635
|
-
let reference = options.reference;
|
|
636
|
-
if (managedSetup && interactive && !reference)
|
|
637
|
-
reference = answer(await p2.text({
|
|
638
|
-
message: "Branch or worktree name",
|
|
639
|
-
defaultValue: "main",
|
|
640
|
-
placeholder: "main",
|
|
641
|
-
validate: (value) => !value?.trim() ? "Enter a branch, worktree name, or main." : undefined
|
|
642
|
-
}));
|
|
643
|
-
if (managedSetup && (!reference || reference !== reference.trim() || reference.length > 200 || [...reference].some((char) => char.charCodeAt(0) <= 32 || char.charCodeAt(0) === 127)))
|
|
644
|
-
throw new Error("Setup requires --reference with a branch, worktree name, or main.");
|
|
645
674
|
const config = {
|
|
646
675
|
version,
|
|
647
676
|
platforms: chosenPlatforms,
|
|
@@ -650,9 +679,9 @@ async function main() {
|
|
|
650
679
|
const setup = options.json ? undefined : projectSetup(name, config);
|
|
651
680
|
let installationStarted = false;
|
|
652
681
|
try {
|
|
653
|
-
if (
|
|
682
|
+
if (spawnSync3("git", ["--version"], { stdio: "ignore" }).status !== 0)
|
|
654
683
|
throw new Error("Install Git first to create the app's initial commit.");
|
|
655
|
-
const hasBun =
|
|
684
|
+
const hasBun = spawnSync3("bun", ["--version"], { stdio: "ignore" }).status === 0;
|
|
656
685
|
if (!options.skipInstall && !hasBun)
|
|
657
686
|
throw new Error("Install Bun first, or pass --skip-install to create the files only.");
|
|
658
687
|
const template = fileURLToPath2(new URL("./templates/default", import.meta.url));
|
|
@@ -663,7 +692,7 @@ async function main() {
|
|
|
663
692
|
await install(directory, Boolean(setup?.live));
|
|
664
693
|
}
|
|
665
694
|
if (hasBun)
|
|
666
|
-
|
|
695
|
+
execFileSync2("bun", ["fmt"], { cwd: directory, stdio: "pipe" });
|
|
667
696
|
setup?.finish({
|
|
668
697
|
installation: options.skipInstall ? "Skipped" : "Complete"
|
|
669
698
|
});
|
|
@@ -673,21 +702,13 @@ async function main() {
|
|
|
673
702
|
});
|
|
674
703
|
throw error;
|
|
675
704
|
}
|
|
676
|
-
|
|
677
|
-
git("init", "--initial-branch=main");
|
|
678
|
-
if (managedSetup)
|
|
679
|
-
config.appId = await setupApp(directory, name, reference);
|
|
680
|
-
git("add", "--all");
|
|
681
|
-
const hasIdentity = spawnSync("git", ["var", "GIT_AUTHOR_IDENT"], {
|
|
705
|
+
execFileSync2("git", ["init", "--initial-branch=main"], {
|
|
682
706
|
cwd: directory,
|
|
683
|
-
stdio: "
|
|
684
|
-
})
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
"-c",
|
|
689
|
-
"user.email=create-disposabl-app@users.noreply.github.com"
|
|
690
|
-
], "-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);
|
|
691
712
|
const folders = selectedFolders(config);
|
|
692
713
|
if (options.json) {
|
|
693
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
|
|
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}`,
|
|
@@ -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 --
|
|
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.
|
|
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 {
|
|
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
|
-
|
|
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 --
|
|
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}`,
|