create-disposabl-app 1.3.0 → 1.3.2
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 +11 -5
- package/index.mjs +17 -8
- package/package.json +1 -1
- package/setup.mjs +69 -97
- package/template.tar.gz +0 -0
- package/terminal.mjs +9 -4
package/README.md
CHANGED
|
@@ -8,17 +8,23 @@ cd my-app
|
|
|
8
8
|
bun run dev
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
The generator installs `@disposabl/cli`
|
|
11
|
+
The generator installs `@disposabl/cli` and checks your Disposabl sign-in. It then guides you through GitHub and Convex in order. With both providers connected, setup creates the GitHub repository and Convex project in your accounts, sets the repository as `origin`, and saves the returned `appSlug` in `disposabl.json`. `bun run dev` starts a local Convex development deployment.
|
|
12
12
|
|
|
13
|
-
The default project enables web and authentication. Choose platforms and features at the prompts or pass comma-separated lists for unattended setup.
|
|
13
|
+
The default project enables web, CLI, and authentication. Choose platforms and features at the prompts or pass comma-separated lists for unattended setup.
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
bunx create-disposabl-app@latest my-app --platforms web,ios --features authentication,payments
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
The generator saves your selections in `disposabl.json`.
|
|
19
|
+
The generator saves your selections in `disposabl.json`. Deployment uses the platforms and features in that file. Use `--features ""` for an app without sign-in or billing.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Press Ctrl+C to pause. In a non-interactive shell, open the printed provider link and resume after authorizing. From the generated project's parent directory, run `bunx create-disposabl-app@latest my-app --resume`. Setup skips providers already connected to your Disposabl account. Use `--skip-setup` to generate local files only.
|
|
22
|
+
|
|
23
|
+
## App CLI
|
|
24
|
+
|
|
25
|
+
Run `bunx disposabl status` from a generated app. The CLI targets the local Convex deployment when configured, or the app’s hosted API otherwise. Override the target with `--origin <url>`.
|
|
26
|
+
|
|
27
|
+
Run `bunx disposabl login` if your app uses authentication. `bunx disposabl list` shows the commands exposed by its Convex functions with `platforms: true`. For automation, use `bunx disposabl call <operationId> '<json>'` or run a named command. Apps with payments enabled and an Autumn key configured expose `bunx disposabl billing status`.
|
|
22
28
|
|
|
23
29
|
## Project skills
|
|
24
30
|
|
|
@@ -35,6 +41,6 @@ The generator takes `apps/apps`, `packages/backend`, and the backend workspace m
|
|
|
35
41
|
|
|
36
42
|
## Release from Exact
|
|
37
43
|
|
|
38
|
-
Run `bun install --frozen-lockfile` and `bun run test` in this directory to pack and test the starter with
|
|
44
|
+
Run `bun install --frozen-lockfile` and `bun run test` in this directory to pack and test the starter with its bundled CLI. The **Exact app generator** workflow tests each push to `main` and publishes to npm’s default `latest` tag using the trusted publisher `disposabl-dev/disposabl-exact` and workflow `create-disposabl-app.yml`.
|
|
39
45
|
|
|
40
46
|
The generator uses `semantic-release` with the Conventional Commits preset. Breaking changes bump the major version, `feat:` bumps the minor version, and other changes bump the patch version. Each release tags the existing commit as `create-disposabl-app-vX.Y.Z`. Tag pushes do not start the branch CI workflows.
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { randomBytes } from "node:crypto";
|
|
3
3
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { join, resolve } from "node:path";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
6
|
import { extract } from "tar";
|
|
7
7
|
import lockfile from "proper-lockfile";
|
|
@@ -11,13 +11,14 @@ import { git, readJson, setup, writeJson } from "./setup.mjs";
|
|
|
11
11
|
import { createTerminal } from "./terminal.mjs";
|
|
12
12
|
|
|
13
13
|
const terminal = createTerminal();
|
|
14
|
+
const setupCancellation = new AbortController();
|
|
14
15
|
const nameError = "Provide an app name of up to 55 lowercase letters, numbers and hyphens.";
|
|
15
16
|
const validName = name => typeof name === "string" && name.length <= 55 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name);
|
|
16
17
|
|
|
17
18
|
const help = `Usage: create-disposabl-app [app-name] [options]
|
|
18
19
|
|
|
19
|
-
Create an Exact and Convex project. Web and authentication are
|
|
20
|
-
Setup
|
|
20
|
+
Create an Exact and Convex project. Web, CLI, and authentication are enabled by default.
|
|
21
|
+
Setup signs you in to Disposabl, connects GitHub and Convex, then creates the app.
|
|
21
22
|
|
|
22
23
|
--platforms Comma-separated list of ${platforms.join(", ")}.
|
|
23
24
|
--features Comma-separated list of ${features.join(", ")}.
|
|
@@ -119,21 +120,29 @@ async function main() {
|
|
|
119
120
|
const release = await lockfile.lock(configPath, {
|
|
120
121
|
lockfilePath: join(git(directory, "rev-parse", "--absolute-git-dir"), "disposabl-setup.lock"),
|
|
121
122
|
});
|
|
123
|
+
const interrupt = () => setupCancellation.abort();
|
|
124
|
+
process.on("SIGINT", interrupt);
|
|
125
|
+
process.on("SIGTERM", interrupt);
|
|
122
126
|
try {
|
|
123
127
|
const config = await readJson(configPath);
|
|
124
128
|
readProjectConfig(config);
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
const { signal } = setupCancellation;
|
|
130
|
+
await terminal.install(directory, config, signal);
|
|
131
|
+
if (!values["skip-setup"]) await setup(directory, app.name, config, terminal, signal);
|
|
127
132
|
} catch (error) {
|
|
128
|
-
|
|
133
|
+
const reason = setupCancellation.signal.aborted ? "Setup paused." : error.message;
|
|
134
|
+
throw new Error(`${reason}\nProject files are in ${directory}.\nRun this command from ${dirname(directory)} to resume.\n bunx create-disposabl-app@latest ${name} --resume`);
|
|
129
135
|
} finally {
|
|
136
|
+
process.off("SIGINT", interrupt);
|
|
137
|
+
process.off("SIGTERM", interrupt);
|
|
130
138
|
await release();
|
|
131
139
|
}
|
|
132
|
-
terminal.complete(directory);
|
|
140
|
+
terminal.complete(directory, !values["skip-setup"]);
|
|
133
141
|
}
|
|
134
142
|
|
|
135
143
|
try {
|
|
136
144
|
await main();
|
|
137
145
|
} catch (error) {
|
|
138
|
-
|
|
146
|
+
const status = terminal.fail(error);
|
|
147
|
+
process.exitCode = setupCancellation.signal.aborted ? 130 : status;
|
|
139
148
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-disposabl-app",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Create a Disposabl app with Exact and Convex",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/disposabl-dev/disposabl-exact/tree/main/packages/create-disposabl-app#readme",
|
package/setup.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { execFileSync
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
6
7
|
|
|
7
8
|
const defaultOrigin = "https://www.disposabl.dev";
|
|
8
|
-
const web = JSON.stringify(["web"]);
|
|
9
9
|
|
|
10
10
|
export const git = (directory, ...args) =>
|
|
11
11
|
execFileSync("git", args, { cwd: directory, encoding: "utf8" }).trim();
|
|
@@ -21,122 +21,94 @@ export async function writeJson(path, value) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async function runCli(directory, origin, args, interactive = false) {
|
|
25
|
-
const require = createRequire(join(directory, "package.json"));
|
|
26
|
-
const manifest = require.resolve("@disposabl/cli/package.json");
|
|
27
|
-
const cli = join(dirname(manifest), require(manifest).bin.disposabl);
|
|
28
|
-
const output = await new Promise((resolve, reject) => {
|
|
29
|
-
const child = spawn(process.execPath, [cli, ...args], {
|
|
30
|
-
cwd: directory,
|
|
31
|
-
env: { ...process.env, DISPOSABL_API_ORIGIN: origin },
|
|
32
|
-
stdio: interactive ? "inherit" : ["ignore", "pipe", "inherit"],
|
|
33
|
-
});
|
|
34
|
-
let stdout = "";
|
|
35
|
-
child.stdout?.setEncoding("utf8").on("data", chunk => { stdout += chunk; });
|
|
36
|
-
child.once("error", reject);
|
|
37
|
-
child.once("close", code => {
|
|
38
|
-
if (code === 0) resolve(stdout);
|
|
39
|
-
else reject(new Error('Disposabl setup failed at "' + args.slice(0, 2).join(" ") + '".'));
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
if (interactive) return;
|
|
43
|
-
try {
|
|
44
|
-
return JSON.parse(output);
|
|
45
|
-
} catch {
|
|
46
|
-
throw new Error("Disposabl setup returned an invalid response.");
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function updateEnv(directory, relativePath, variables, remove = []) {
|
|
51
|
-
git(directory, "check-ignore", relativePath);
|
|
52
|
-
const path = join(directory, relativePath);
|
|
53
|
-
let existing = "";
|
|
54
|
-
try {
|
|
55
|
-
existing = await readFile(path, "utf8");
|
|
56
|
-
} catch (error) {
|
|
57
|
-
if (error.code !== "ENOENT") throw error;
|
|
58
|
-
}
|
|
59
|
-
const keys = new Set([...Object.keys(variables), ...remove]);
|
|
60
|
-
const retained = existing.split("\n").filter(line =>
|
|
61
|
-
!keys.has(/^\s*(?:export\s+)?([A-Z0-9_]+)\s*=/.exec(line)?.[1]));
|
|
62
|
-
const updated = Object.entries(variables).map(([key, value]) => `${key}=${JSON.stringify(value)}`);
|
|
63
|
-
const temporary = join(git(directory, "rev-parse", "--absolute-git-dir"), `disposabl-env-${randomUUID()}`);
|
|
64
|
-
try {
|
|
65
|
-
await writeFile(temporary, [...retained, ...updated].join("\n").trimStart() + "\n", {
|
|
66
|
-
flag: "wx", mode: 0o600,
|
|
67
|
-
});
|
|
68
|
-
await rename(temporary, path);
|
|
69
|
-
} finally {
|
|
70
|
-
await rm(temporary, { force: true });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
24
|
function githubRepository(url) {
|
|
75
25
|
const match = /^(?:https:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([a-z0-9-]+\/[a-z0-9_.-]+?)(?:\.git)?\/?$/i.exec(url);
|
|
76
26
|
return match?.[1].toLowerCase();
|
|
77
27
|
}
|
|
78
28
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
29
|
+
function configureRemote(directory, app) {
|
|
30
|
+
if (typeof app.githubOwner !== "string" || typeof app.githubRepoName !== "string") {
|
|
31
|
+
throw new Error("Disposabl did not return the app's GitHub repository.");
|
|
32
|
+
}
|
|
33
|
+
const repository = app.githubOwner + "/" + app.githubRepoName;
|
|
34
|
+
if (!/^[a-z0-9-]+\/[a-z0-9_.-]+$/i.test(repository)) {
|
|
35
|
+
throw new Error("Disposabl returned an invalid GitHub repository.");
|
|
85
36
|
}
|
|
86
|
-
const expected = githubRepository(repositoryUrl);
|
|
87
|
-
if (!expected) throw new Error("Disposabl did not configure a GitHub repository.");
|
|
88
37
|
const remotes = git(directory, "remote").split("\n");
|
|
89
38
|
if (remotes.includes("origin")) {
|
|
90
|
-
|
|
91
|
-
if (githubRepository(current) !== expected) {
|
|
39
|
+
if (githubRepository(git(directory, "config", "--get", "remote.origin.url")) !== repository.toLowerCase()) {
|
|
92
40
|
throw new Error("The existing origin belongs to a different repository.");
|
|
93
41
|
}
|
|
94
42
|
} else {
|
|
95
|
-
git(directory, "remote", "add", "origin",
|
|
43
|
+
git(directory, "remote", "add", "origin", "https://github.com/" + repository + ".git");
|
|
96
44
|
}
|
|
45
|
+
return repository;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function connect(client, terminal, signal, provider, label, providerLink, openUrl) {
|
|
49
|
+
const path = "/api/connections/" + provider;
|
|
50
|
+
const status = () => client.request(path + "/status", { signal }, true);
|
|
51
|
+
if ((await status()).connected) return terminal.progress(label + " connected.");
|
|
52
|
+
|
|
53
|
+
const { url } = await client.request(path + "/connect", { method: "POST", signal }, true);
|
|
54
|
+
const link = providerLink(provider, url);
|
|
55
|
+
terminal.progress("Open this link to connect " + label + ".\n" + link);
|
|
56
|
+
if (!terminal.interactive) throw new Error("Setup paused. Open the link, finish connecting " + label + ", then resume.");
|
|
57
|
+
openUrl(link);
|
|
97
58
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
CONVEX_SITE_ORIGIN: convexSiteUrl,
|
|
106
|
-
});
|
|
59
|
+
terminal.progress("Waiting for " + label + ". Press Ctrl+C to pause.");
|
|
60
|
+
const expiresAt = Date.now() + 10 * 60_000;
|
|
61
|
+
while (Date.now() < expiresAt) {
|
|
62
|
+
await delay(2_000, undefined, { signal });
|
|
63
|
+
if ((await status()).connected) return terminal.progress(label + " connected.");
|
|
64
|
+
}
|
|
65
|
+
throw new Error(label + " connection timed out. Resume to check again.");
|
|
107
66
|
}
|
|
108
67
|
|
|
109
|
-
export async function setup(directory, name, config) {
|
|
110
|
-
const
|
|
111
|
-
|
|
68
|
+
export async function setup(directory, name, config, terminal, signal) {
|
|
69
|
+
const require = createRequire(join(directory, "package.json"));
|
|
70
|
+
const cli = dirname(require.resolve("@disposabl/cli/package.json"));
|
|
71
|
+
const { createClient, providerLink } = await import(join(cli, "client.mjs"));
|
|
72
|
+
const { sandboxSession } = await import(join(cli, "sandbox.mjs"));
|
|
73
|
+
const { openUrl } = await import(join(cli, "auth.mjs"));
|
|
74
|
+
const client = createClient(process.env.DISPOSABL_API_ORIGIN || sandboxSession()?.origin || defaultOrigin);
|
|
75
|
+
if (config.serviceOrigin && config.serviceOrigin !== client.origin) {
|
|
112
76
|
throw new Error("Set DISPOSABL_API_ORIGIN to the original Disposabl API origin before resuming.");
|
|
113
77
|
}
|
|
114
78
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
await
|
|
119
|
-
if (!
|
|
120
|
-
}
|
|
121
|
-
if (!(await run(["connections", "status", "--features", features, "--wait", "--setup-origin"])).ready) {
|
|
122
|
-
throw new Error("Connect GitHub and Convex to continue setup.");
|
|
79
|
+
terminal.progress("[1/4] Check Disposabl sign-in");
|
|
80
|
+
if (!await client.currentUser({ signal })) {
|
|
81
|
+
terminal.progress("Sign in in your browser, then return here to continue. Press Ctrl+C to pause.");
|
|
82
|
+
await client.signIn(terminal.interactive);
|
|
83
|
+
if (!await client.currentUser({ signal })) throw new Error("Disposabl login did not complete.");
|
|
123
84
|
}
|
|
85
|
+
terminal.progress("Signed in to Disposabl.");
|
|
124
86
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
87
|
+
terminal.progress("[2/4] Connect GitHub");
|
|
88
|
+
await connect(client, terminal, signal, "github", "GitHub", providerLink, openUrl);
|
|
89
|
+
terminal.progress("[3/4] Connect Convex");
|
|
90
|
+
await connect(client, terminal, signal, "convex", "Convex", providerLink, openUrl);
|
|
91
|
+
|
|
92
|
+
terminal.progress("[4/4] Provision your GitHub repository and Convex project");
|
|
93
|
+
const app = await client.request("/api/apps/create", {
|
|
94
|
+
method: "POST", signal, timeout: 120_000,
|
|
95
|
+
headers: { "Content-Type": "application/json" },
|
|
96
|
+
body: JSON.stringify({ appSlug: name, appName: name }),
|
|
97
|
+
}, true);
|
|
98
|
+
if (app.appSlug !== name) {
|
|
99
|
+
throw new Error("Disposabl did not return the expected app slug.");
|
|
100
|
+
}
|
|
101
|
+
if ((config.appSlug && config.appSlug !== app.appSlug) || (config.appId && config.appId !== app.appId)) {
|
|
102
|
+
throw new Error("This project is linked to a different Disposabl app.");
|
|
131
103
|
}
|
|
132
104
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
])
|
|
138
|
-
|
|
139
|
-
if (config.platforms.some(platform => ["android", "ios", "macos"].includes(platform))) {
|
|
140
|
-
execFileSync("bash", [".github/ci/android-key.sh", config.platforms.includes("android") ? "android" : "update"], { cwd: directory, stdio: "inherit" });
|
|
105
|
+
const repository = configureRemote(directory, app);
|
|
106
|
+
delete config.appId;
|
|
107
|
+
config.appSlug = app.appSlug;
|
|
108
|
+
config.serviceOrigin = client.origin;
|
|
109
|
+
if (typeof app.convexSiteUrl === "string" && /^https:\/\/[a-z0-9-]+\.convex\.site$/.test(app.convexSiteUrl)) {
|
|
110
|
+
config.apiOrigin = app.convexSiteUrl;
|
|
141
111
|
}
|
|
112
|
+
await writeJson(join(directory, "disposabl.json"), config);
|
|
113
|
+
terminal.progress("App linked to " + repository + ". App slug saved in disposabl.json.");
|
|
142
114
|
}
|
package/template.tar.gz
CHANGED
|
Binary file
|
package/terminal.mjs
CHANGED
|
@@ -47,7 +47,11 @@ export function createTerminal() {
|
|
|
47
47
|
required: false,
|
|
48
48
|
}));
|
|
49
49
|
},
|
|
50
|
-
|
|
50
|
+
progress(message) {
|
|
51
|
+
if (interactive) prompts.log.step(message);
|
|
52
|
+
else console.log(message);
|
|
53
|
+
},
|
|
54
|
+
async install(directory, config, signal) {
|
|
51
55
|
const progress = interactive ? prompts.spinner() : null;
|
|
52
56
|
if (interactive) {
|
|
53
57
|
const names = ids => ids.map(id => labels[id] ?? id).join(", ") || "None";
|
|
@@ -59,15 +63,16 @@ export function createTerminal() {
|
|
|
59
63
|
}
|
|
60
64
|
progress?.start("Installing project dependencies");
|
|
61
65
|
try {
|
|
62
|
-
await exec("bun", ["install", "--frozen-lockfile"], { cwd: directory });
|
|
66
|
+
await exec("bun", ["install", "--frozen-lockfile"], { cwd: directory, signal });
|
|
63
67
|
progress?.stop("Project dependencies installed");
|
|
64
68
|
} catch (error) {
|
|
65
69
|
progress?.stop("Dependency installation failed");
|
|
66
70
|
throw error;
|
|
67
71
|
}
|
|
68
72
|
},
|
|
69
|
-
complete(directory) {
|
|
70
|
-
const
|
|
73
|
+
complete(directory, linked) {
|
|
74
|
+
const deploy = linked ? "\n\nTo deploy, commit your files and run git push -u origin main." : "";
|
|
75
|
+
const message = `Created ${directory}\n\ncd ${basename(directory)}\nbun run dev${deploy}`;
|
|
71
76
|
if (interactive) prompts.outro(message);
|
|
72
77
|
else console.log(message);
|
|
73
78
|
},
|