create-disposabl-app 0.6.3 → 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 +84 -61
- 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 = [
|
|
@@ -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
|
|
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.
|
|
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,
|
|
445
|
-
|
|
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 =
|
|
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("--
|
|
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
|
|
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 =
|
|
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 =
|
|
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 (
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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: "
|
|
682
|
-
})
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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
|
|
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}`,
|