@open-workspace/create 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -5
- package/create.ts +86 -0
- package/import/args.ts +57 -0
- package/import/cli.ts +432 -0
- package/import/concurrency.ts +52 -0
- package/import/csv.ts +56 -0
- package/import/directory/command.ts +320 -0
- package/import/directory/google.ts +510 -0
- package/import/directory/plan.ts +367 -0
- package/import/gmail.ts +195 -0
- package/import/headers.ts +105 -0
- package/import/imap-command.ts +182 -0
- package/import/imap-source.ts +397 -0
- package/import/invariant.ts +22 -0
- package/import/mbox-source.ts +174 -0
- package/import/mbox.ts +198 -0
- package/import/oauth.ts +423 -0
- package/import/protocol.ts +59 -0
- package/import/uploader.ts +235 -0
- package/import/workspace.ts +218 -0
- package/index.ts +13 -121
- package/module-templates.ts +409 -0
- package/module.ts +105 -0
- package/package.json +18 -6
- package/setup/alchemy-helper.ts +258 -0
- package/setup/alchemy-protocol.ts +63 -0
- package/setup/alchemy.ts +163 -0
- package/setup/args.ts +128 -0
- package/setup/cloudflare-api.ts +156 -0
- package/setup/domains.ts +102 -0
- package/setup/flow.ts +987 -0
- package/setup/ui.ts +146 -0
- package/templates.ts +193 -140
- package/keys.ts +0 -31
package/setup/flow.ts
ADDED
|
@@ -0,0 +1,987 @@
|
|
|
1
|
+
// `bun create @open-workspace`: writes and installs the project, signs in to
|
|
2
|
+
// Cloudflare with the project's Alchemy, picks the account, the mail domains
|
|
3
|
+
// and the hostname from what that login can see, and deploys.
|
|
4
|
+
import {
|
|
5
|
+
existsSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from "node:fs";
|
|
11
|
+
import { join, resolve } from "node:path";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
alchemyRunTs,
|
|
15
|
+
envFile,
|
|
16
|
+
gitignore,
|
|
17
|
+
packageJson,
|
|
18
|
+
readme,
|
|
19
|
+
tsconfigJson,
|
|
20
|
+
} from "../templates.ts";
|
|
21
|
+
import type { ProjectAnswers } from "../templates.ts";
|
|
22
|
+
import type { CredentialsReply, CloudflareAuth } from "./alchemy-protocol.ts";
|
|
23
|
+
import type { ProjectAlchemy } from "./alchemy.ts";
|
|
24
|
+
import type { AiChoice, CreateOptions } from "./args.ts";
|
|
25
|
+
import { CloudflareApiError } from "./cloudflare-api.ts";
|
|
26
|
+
import type { CloudflareApi } from "./cloudflare-api.ts";
|
|
27
|
+
import {
|
|
28
|
+
describeMx,
|
|
29
|
+
findAccount,
|
|
30
|
+
foreignMx,
|
|
31
|
+
hostnameProblem,
|
|
32
|
+
primaryFirst,
|
|
33
|
+
suggestedHostname,
|
|
34
|
+
zonesNamed,
|
|
35
|
+
} from "./domains.ts";
|
|
36
|
+
import type { Account, MxRecord, Zone } from "./domains.ts";
|
|
37
|
+
import { Cancelled } from "./ui.ts";
|
|
38
|
+
import type { Ui } from "./ui.ts";
|
|
39
|
+
|
|
40
|
+
export type CreateDeps = {
|
|
41
|
+
ui: Ui;
|
|
42
|
+
/** Where the project's directory is made. */
|
|
43
|
+
cwd: string;
|
|
44
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
45
|
+
/** Whether a person answers prompts. Without one, nothing is asked. */
|
|
46
|
+
interactive: boolean;
|
|
47
|
+
install(directory: string): Promise<{ ok: boolean; output: string }>;
|
|
48
|
+
alchemy(directory: string, profile: string | undefined): ProjectAlchemy;
|
|
49
|
+
cloudflare(auth: CloudflareAuth): CloudflareApi;
|
|
50
|
+
/**
|
|
51
|
+
* Starts a git repository in the new project with everything as its first
|
|
52
|
+
* commit: "committed", "initialized" (no commit, e.g. git has no identity
|
|
53
|
+
* set), or "skipped" (no git, or the directory is already in a repository).
|
|
54
|
+
*/
|
|
55
|
+
git(directory: string): Promise<"committed" | "initialized" | "skipped">;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const NAME = /^[a-z0-9][a-z0-9-]{0,62}$/u;
|
|
59
|
+
|
|
60
|
+
const DEFAULT_PROFILE = "default";
|
|
61
|
+
|
|
62
|
+
/** Ends the run with a message, and what to do about it. */
|
|
63
|
+
class Stop extends Error {
|
|
64
|
+
constructor(
|
|
65
|
+
message: string,
|
|
66
|
+
readonly next?: string
|
|
67
|
+
) {
|
|
68
|
+
super(message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type SignedIn = Extract<CredentialsReply, { status: "ok" }>;
|
|
73
|
+
|
|
74
|
+
type Connection = {
|
|
75
|
+
alchemy: ProjectAlchemy;
|
|
76
|
+
credentials: SignedIn;
|
|
77
|
+
accounts: Account[];
|
|
78
|
+
/** Whether the profile was signed in by this run (so its account is this run's to set). */
|
|
79
|
+
signedInNow: boolean;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** Runs create; resolves to the exit code. */
|
|
83
|
+
export async function runCreate(options: CreateOptions, deps: CreateDeps) {
|
|
84
|
+
const { ui } = deps;
|
|
85
|
+
|
|
86
|
+
let project:
|
|
87
|
+
| { directory: string; created: boolean; written: boolean }
|
|
88
|
+
| undefined;
|
|
89
|
+
|
|
90
|
+
ui.intro("OpenWorkspace");
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const name = await projectName(options, deps);
|
|
94
|
+
const directory = resolve(deps.cwd, name);
|
|
95
|
+
|
|
96
|
+
if (existsSync(directory) && readdirSync(directory).length > 0) {
|
|
97
|
+
throw new Stop(`${directory} is not empty.`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
project = { directory, created: !existsSync(directory), written: false };
|
|
101
|
+
|
|
102
|
+
await install(name, directory, deps);
|
|
103
|
+
|
|
104
|
+
const connection = await connect(directory, options, deps);
|
|
105
|
+
|
|
106
|
+
const { account, alchemy, credentials } = await bindAccount(
|
|
107
|
+
connection,
|
|
108
|
+
name,
|
|
109
|
+
directory,
|
|
110
|
+
options,
|
|
111
|
+
deps
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const zones = await ui.progress(
|
|
115
|
+
`Listing the zones in ${account.name}`,
|
|
116
|
+
async () =>
|
|
117
|
+
(await deps.cloudflare(credentials.auth).zones(account.id)).sort(
|
|
118
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
119
|
+
),
|
|
120
|
+
(found) =>
|
|
121
|
+
`${found.length} ${found.length === 1 ? "zone" : "zones"} in ${account.name}`
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (zones.length === 0) {
|
|
125
|
+
throw new Stop(
|
|
126
|
+
`${account.name} has no zones. Mail domains and the app's hostname must be zones in it.`,
|
|
127
|
+
`Add your domain at https://dash.cloudflare.com/${account.id}/add-site, then run bun create @open-workspace again.`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const api = deps.cloudflare(credentials.auth);
|
|
132
|
+
|
|
133
|
+
const mail = await chooseMailDomains(
|
|
134
|
+
zones,
|
|
135
|
+
api,
|
|
136
|
+
options.mailDomains,
|
|
137
|
+
[],
|
|
138
|
+
deps
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const hostname = await chooseHostname(
|
|
142
|
+
mail.domains[0] ?? "",
|
|
143
|
+
zones,
|
|
144
|
+
options,
|
|
145
|
+
deps
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const ai = await chooseAi(options, deps);
|
|
149
|
+
|
|
150
|
+
const pinnedProfile =
|
|
151
|
+
credentials.source === "profile" &&
|
|
152
|
+
credentials.profile !== DEFAULT_PROFILE
|
|
153
|
+
? credentials.profile
|
|
154
|
+
: undefined;
|
|
155
|
+
|
|
156
|
+
const answers: ProjectAnswers = {
|
|
157
|
+
name,
|
|
158
|
+
hostname,
|
|
159
|
+
mailDomains: mail.domains,
|
|
160
|
+
ai: ai.choice,
|
|
161
|
+
cloudflare: {
|
|
162
|
+
account,
|
|
163
|
+
profile:
|
|
164
|
+
credentials.source === "profile" ? credentials.profile : undefined,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
writeProject(directory, answers, ai.key, pinnedProfile);
|
|
169
|
+
project.written = true;
|
|
170
|
+
ui.success(`Wrote ${name}/alchemy.run.ts and ${name}/.env`);
|
|
171
|
+
|
|
172
|
+
if (options.git) {
|
|
173
|
+
const repository = await deps.git(directory);
|
|
174
|
+
|
|
175
|
+
if (repository === "committed") {
|
|
176
|
+
ui.success(
|
|
177
|
+
"Started a git repository with the project as its first commit"
|
|
178
|
+
);
|
|
179
|
+
} else if (repository === "initialized") {
|
|
180
|
+
ui.info(
|
|
181
|
+
"Started a git repository; commit the project when git knows who you are"
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return await deploy(
|
|
187
|
+
{ name, hostname, account, primary: mail.domains[0] ?? "", alchemy },
|
|
188
|
+
{
|
|
189
|
+
mxBlocked: mail.mxBlocked,
|
|
190
|
+
missingKey: ai.key && !ai.key.value ? ai.key.name : undefined,
|
|
191
|
+
},
|
|
192
|
+
options,
|
|
193
|
+
deps
|
|
194
|
+
);
|
|
195
|
+
} catch (failure) {
|
|
196
|
+
if (project && !project.written) discard(project);
|
|
197
|
+
|
|
198
|
+
if (failure instanceof Cancelled) {
|
|
199
|
+
ui.cancel(project?.written ? "Stopped." : "Nothing was created.");
|
|
200
|
+
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (failure instanceof Stop) {
|
|
205
|
+
ui.error(failure.message);
|
|
206
|
+
|
|
207
|
+
if (failure.next) ui.info(failure.next);
|
|
208
|
+
|
|
209
|
+
ui.cancel(project?.written ? "Stopped." : "Nothing was created.");
|
|
210
|
+
|
|
211
|
+
return 1;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
throw failure;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Removes what this run put in the project's directory, before the project was complete. */
|
|
219
|
+
function discard(project: { directory: string; created: boolean }) {
|
|
220
|
+
if (project.created) {
|
|
221
|
+
rmSync(project.directory, { recursive: true, force: true });
|
|
222
|
+
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
for (const entry of readdirSync(project.directory)) {
|
|
227
|
+
rmSync(join(project.directory, entry), { recursive: true, force: true });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function projectName(options: CreateOptions, deps: CreateDeps) {
|
|
232
|
+
if (options.name !== undefined) {
|
|
233
|
+
if (!NAME.test(options.name)) {
|
|
234
|
+
throw new Stop(
|
|
235
|
+
`"${options.name}" can't be the project name: use lowercase letters, digits, and dashes.`
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (!deps.interactive) return options.name;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!deps.interactive) {
|
|
243
|
+
throw new Stop(
|
|
244
|
+
"The project name is missing.",
|
|
245
|
+
"Pass it first: bun create @open-workspace acme-workspace --yes"
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return deps.ui.text({
|
|
250
|
+
message: "Project name",
|
|
251
|
+
placeholder: "acme-workspace",
|
|
252
|
+
initialValue: options.name ?? "",
|
|
253
|
+
validate: (value) =>
|
|
254
|
+
NAME.test(value)
|
|
255
|
+
? undefined
|
|
256
|
+
: "Use lowercase letters, digits, and dashes",
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Writes package.json and installs it: signing in uses the project's own Alchemy. */
|
|
261
|
+
async function install(name: string, directory: string, deps: CreateDeps) {
|
|
262
|
+
const answers = { name, hostname: "", mailDomains: [], ai: "none" as const };
|
|
263
|
+
|
|
264
|
+
mkdirSync(directory, { recursive: true });
|
|
265
|
+
writeFileSync(join(directory, "package.json"), packageJson(answers));
|
|
266
|
+
writeFileSync(join(directory, "tsconfig.json"), tsconfigJson);
|
|
267
|
+
writeFileSync(join(directory, ".gitignore"), gitignore);
|
|
268
|
+
|
|
269
|
+
const result = await deps.ui.progress(
|
|
270
|
+
"Installing dependencies with bun",
|
|
271
|
+
() => deps.install(directory),
|
|
272
|
+
(installed) =>
|
|
273
|
+
installed.ok ? "Dependencies installed" : "bun install failed"
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
if (!result.ok) {
|
|
277
|
+
throw new Stop(
|
|
278
|
+
`bun install failed:\n${result.output.trim()}`,
|
|
279
|
+
"Fix the problem above, then run bun create @open-workspace again."
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function describeLogin(credentials: SignedIn) {
|
|
285
|
+
return credentials.source === "environment"
|
|
286
|
+
? "Signed in to Cloudflare with CLOUDFLARE_API_TOKEN"
|
|
287
|
+
: `Signed in to Cloudflare (Alchemy profile '${credentials.profile}')`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** The Cloudflare login a deploy will use, signing in first when there's none, and the accounts it reaches. */
|
|
291
|
+
async function connect(
|
|
292
|
+
directory: string,
|
|
293
|
+
options: CreateOptions,
|
|
294
|
+
deps: CreateDeps
|
|
295
|
+
): Promise<Connection> {
|
|
296
|
+
const { ui } = deps;
|
|
297
|
+
const alchemy = deps.alchemy(directory, options.profile);
|
|
298
|
+
|
|
299
|
+
const found = await ui.progress(
|
|
300
|
+
"Checking for a Cloudflare login",
|
|
301
|
+
() => alchemy.credentials(),
|
|
302
|
+
(reply) =>
|
|
303
|
+
reply.status === "ok" ? describeLogin(reply) : "No Cloudflare login yet"
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
if (found.status === "ok") {
|
|
307
|
+
try {
|
|
308
|
+
return {
|
|
309
|
+
alchemy,
|
|
310
|
+
credentials: found,
|
|
311
|
+
accounts: await listAccounts(found, deps),
|
|
312
|
+
signedInNow: false,
|
|
313
|
+
};
|
|
314
|
+
} catch (failure) {
|
|
315
|
+
const rejected =
|
|
316
|
+
failure instanceof CloudflareApiError &&
|
|
317
|
+
(failure.status === 401 || failure.status === 403);
|
|
318
|
+
|
|
319
|
+
if (!rejected || found.source === "environment" || !deps.interactive) {
|
|
320
|
+
throw failure;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
ui.warn(`Cloudflare rejected the saved login: ${failure.message}`);
|
|
324
|
+
}
|
|
325
|
+
} else if (found.status === "invalid") {
|
|
326
|
+
ui.warn(found.message);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (!deps.interactive) {
|
|
330
|
+
throw new Stop(
|
|
331
|
+
found.status === "ok"
|
|
332
|
+
? "Cloudflare rejected the saved login."
|
|
333
|
+
: `There's no usable Cloudflare login: ${found.message}`,
|
|
334
|
+
"Run bun create @open-workspace in a terminal to sign in, or set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID, then run this again."
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const credentials = await signIn(alchemy, options.profile, deps);
|
|
339
|
+
|
|
340
|
+
return {
|
|
341
|
+
alchemy,
|
|
342
|
+
credentials,
|
|
343
|
+
accounts: await listAccounts(credentials, deps),
|
|
344
|
+
signedInNow: true,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Alchemy's own sign-in (`alchemy profile edit`), on this terminal, then the login it saved. */
|
|
349
|
+
async function signIn(
|
|
350
|
+
alchemy: ProjectAlchemy,
|
|
351
|
+
profile: string | undefined,
|
|
352
|
+
deps: CreateDeps
|
|
353
|
+
) {
|
|
354
|
+
const { ui } = deps;
|
|
355
|
+
const listed = await alchemy.profiles();
|
|
356
|
+
|
|
357
|
+
const name =
|
|
358
|
+
profile ?? (listed.status === "ok" ? listed.active : DEFAULT_PROFILE);
|
|
359
|
+
|
|
360
|
+
const existing =
|
|
361
|
+
listed.status === "ok"
|
|
362
|
+
? listed.profiles.find((entry) => entry.name === name)
|
|
363
|
+
: undefined;
|
|
364
|
+
|
|
365
|
+
if (
|
|
366
|
+
!existing &&
|
|
367
|
+
name !== DEFAULT_PROFILE &&
|
|
368
|
+
!(await alchemy.createProfile(name))
|
|
369
|
+
) {
|
|
370
|
+
throw new Stop(`Couldn't create the Alchemy profile '${name}'.`);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
ui.step(
|
|
374
|
+
[
|
|
375
|
+
`Signing in to Cloudflare with Alchemy (profile '${name}').`,
|
|
376
|
+
"Choose OAuth and All Scopes: the deploy sets up Workers, D1, R2, DNS and Email Routing.",
|
|
377
|
+
].join("\n")
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
const finished = await alchemy.signIn(
|
|
381
|
+
existing?.cloudflare ? "reconfigure" : "add"
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
const credentials = await alchemy.credentials();
|
|
385
|
+
|
|
386
|
+
if (!finished || credentials.status !== "ok") {
|
|
387
|
+
throw new Stop(
|
|
388
|
+
`Signing in to Cloudflare didn't finish${credentials.status === "ok" ? "" : `: ${credentials.message}`}`,
|
|
389
|
+
`Run bun create @open-workspace again, or sign in yourself with \`bun alchemy profile edit --add Cloudflare\`.`
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
ui.success(describeLogin(credentials));
|
|
394
|
+
|
|
395
|
+
return credentials;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async function listAccounts(credentials: SignedIn, deps: CreateDeps) {
|
|
399
|
+
const accounts = await deps.ui.progress(
|
|
400
|
+
"Listing the Cloudflare accounts this login reaches",
|
|
401
|
+
() => deps.cloudflare(credentials.auth).accounts(),
|
|
402
|
+
(found) =>
|
|
403
|
+
`${found.length} Cloudflare ${found.length === 1 ? "account" : "accounts"}`
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
if (accounts.length === 0) {
|
|
407
|
+
throw new Stop(
|
|
408
|
+
"This login reaches no Cloudflare account.",
|
|
409
|
+
"Sign in again with `bun alchemy profile edit --reconfigure Cloudflare` and choose All Scopes."
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return accounts;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** Which account to deploy to: always asked when the login reaches several. */
|
|
417
|
+
async function chooseAccount(
|
|
418
|
+
connection: Connection,
|
|
419
|
+
options: CreateOptions,
|
|
420
|
+
deps: CreateDeps
|
|
421
|
+
) {
|
|
422
|
+
const { accounts, credentials } = connection;
|
|
423
|
+
|
|
424
|
+
const current = accounts.find(
|
|
425
|
+
(account) => account.id === credentials.accountId
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
if (credentials.source === "environment") {
|
|
429
|
+
const account = current ?? {
|
|
430
|
+
id: credentials.accountId,
|
|
431
|
+
name: credentials.accountId,
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const wanted = options.account && findAccount([account], options.account);
|
|
435
|
+
|
|
436
|
+
if (options.account && !wanted) {
|
|
437
|
+
throw new Stop(
|
|
438
|
+
`CLOUDFLARE_ACCOUNT_ID is set to ${credentials.accountId}, and the deploy uses it, not --account ${options.account}.`
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return account;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (options.account) {
|
|
446
|
+
const account = findAccount(accounts, options.account);
|
|
447
|
+
|
|
448
|
+
if (!account) {
|
|
449
|
+
throw new Stop(
|
|
450
|
+
`This login can't reach a Cloudflare account "${options.account}".`,
|
|
451
|
+
`It reaches: ${accounts.map((entry) => `${entry.name} (${entry.id})`).join(", ")}`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return account;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const [only] = accounts;
|
|
459
|
+
|
|
460
|
+
if (accounts.length === 1 && only) return only;
|
|
461
|
+
|
|
462
|
+
if (!deps.interactive) {
|
|
463
|
+
throw new Stop(
|
|
464
|
+
`This login reaches ${accounts.length} Cloudflare accounts; say which to deploy to with --account.`,
|
|
465
|
+
accounts
|
|
466
|
+
.map((entry) => `--account ${entry.id} ${entry.name}`)
|
|
467
|
+
.join("\n")
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const id = await deps.ui.select({
|
|
472
|
+
message: "Cloudflare account to deploy to",
|
|
473
|
+
options: accounts.map((account) => ({
|
|
474
|
+
value: account.id,
|
|
475
|
+
label: account.name,
|
|
476
|
+
hint:
|
|
477
|
+
account.id === credentials.accountId
|
|
478
|
+
? `${account.id}, the profile's account`
|
|
479
|
+
: account.id,
|
|
480
|
+
})),
|
|
481
|
+
initialValue: current?.id,
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
return accounts.find((account) => account.id === id) ?? accounts[0];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Makes sure the deploy goes to the chosen account. Alchemy deploys to the
|
|
489
|
+
* account stored in the profile, so the profile must hold it: a profile this
|
|
490
|
+
* run signed in is pointed at it; a profile other projects may already deploy
|
|
491
|
+
* with is left alone, and another profile on that account is used, or a new
|
|
492
|
+
* one, named after the project, is signed in.
|
|
493
|
+
*/
|
|
494
|
+
async function bindAccount(
|
|
495
|
+
connection: Connection,
|
|
496
|
+
name: string,
|
|
497
|
+
directory: string,
|
|
498
|
+
options: CreateOptions,
|
|
499
|
+
deps: CreateDeps
|
|
500
|
+
): Promise<{
|
|
501
|
+
account: Account;
|
|
502
|
+
alchemy: ProjectAlchemy;
|
|
503
|
+
credentials: SignedIn;
|
|
504
|
+
}> {
|
|
505
|
+
const { ui } = deps;
|
|
506
|
+
const account = await chooseAccount(connection, options, deps);
|
|
507
|
+
const { alchemy, credentials } = connection;
|
|
508
|
+
|
|
509
|
+
if (account?.id === undefined) throw new Stop("No account was chosen.");
|
|
510
|
+
|
|
511
|
+
if (account.id === credentials.accountId) {
|
|
512
|
+
return { account, alchemy, credentials };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (connection.signedInNow) {
|
|
516
|
+
return {
|
|
517
|
+
account,
|
|
518
|
+
alchemy,
|
|
519
|
+
credentials: await pointAt(alchemy, account, deps),
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const other = await profileOn(account, connection, directory, deps);
|
|
524
|
+
|
|
525
|
+
if (other) {
|
|
526
|
+
ui.info(
|
|
527
|
+
`Using Alchemy profile '${other.credentials.profile}', which deploys to ${account.name}.`
|
|
528
|
+
);
|
|
529
|
+
|
|
530
|
+
return { account, ...other };
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const current =
|
|
534
|
+
connection.accounts.find((entry) => entry.id === credentials.accountId)
|
|
535
|
+
?.name ?? credentials.accountId;
|
|
536
|
+
|
|
537
|
+
if (!deps.interactive) {
|
|
538
|
+
throw new Stop(
|
|
539
|
+
`Alchemy profile '${credentials.profile}' deploys to ${current}, not ${account.name}.`,
|
|
540
|
+
`Pass --profile with a profile signed in to ${account.name}, or sign one in: bun alchemy profile create ${name} && bun alchemy profile edit --profile ${name} --add Cloudflare`
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const fresh = await uniqueProfileName(name, connection.alchemy);
|
|
545
|
+
|
|
546
|
+
const proceed = await ui.confirm({
|
|
547
|
+
message: `Alchemy profile '${credentials.profile}' deploys to ${current}, and other projects may rely on that. Sign in to ${account.name} in a new profile, '${fresh}', for this project?`,
|
|
548
|
+
initialValue: true,
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
// Declined: choose the account again.
|
|
552
|
+
if (!proceed) return bindAccount(connection, name, directory, options, deps);
|
|
553
|
+
|
|
554
|
+
const alchemyForProject = deps.alchemy(directory, fresh);
|
|
555
|
+
const signedIn = await signIn(alchemyForProject, fresh, deps);
|
|
556
|
+
|
|
557
|
+
return {
|
|
558
|
+
account,
|
|
559
|
+
alchemy: alchemyForProject,
|
|
560
|
+
credentials:
|
|
561
|
+
signedIn.accountId === account.id
|
|
562
|
+
? signedIn
|
|
563
|
+
: await pointAt(alchemyForProject, account, deps),
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/** Points a profile this run signed in at the chosen account. */
|
|
568
|
+
async function pointAt(
|
|
569
|
+
alchemy: ProjectAlchemy,
|
|
570
|
+
account: Account,
|
|
571
|
+
deps: CreateDeps
|
|
572
|
+
) {
|
|
573
|
+
const set = await alchemy.setAccount(account.id);
|
|
574
|
+
const credentials = await alchemy.credentials();
|
|
575
|
+
|
|
576
|
+
if (set.status !== "ok" || credentials.status !== "ok") {
|
|
577
|
+
throw new Stop(
|
|
578
|
+
`Couldn't point the Alchemy profile at ${account.name}: ${set.status === "ok" ? "" : set.message}`
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
deps.ui.success(
|
|
583
|
+
`Alchemy profile '${set.profile}' now deploys to ${account.name}.`
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
return credentials;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** Another profile that already deploys to the account, if one does and its login still works. */
|
|
590
|
+
async function profileOn(
|
|
591
|
+
account: Account,
|
|
592
|
+
connection: Connection,
|
|
593
|
+
directory: string,
|
|
594
|
+
deps: CreateDeps
|
|
595
|
+
) {
|
|
596
|
+
const listed = await connection.alchemy.profiles();
|
|
597
|
+
|
|
598
|
+
if (listed.status !== "ok") return undefined;
|
|
599
|
+
|
|
600
|
+
const candidates = listed.profiles.filter(
|
|
601
|
+
(profile) =>
|
|
602
|
+
profile.name !== connection.credentials.profile &&
|
|
603
|
+
profile.cloudflare?.accountId === account.id
|
|
604
|
+
);
|
|
605
|
+
|
|
606
|
+
const checked = await Promise.all(
|
|
607
|
+
candidates.map(async (candidate) => {
|
|
608
|
+
const alchemy = deps.alchemy(directory, candidate.name);
|
|
609
|
+
|
|
610
|
+
return { alchemy, credentials: await alchemy.credentials() };
|
|
611
|
+
})
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
for (const { alchemy, credentials } of checked) {
|
|
615
|
+
if (credentials.status === "ok" && credentials.accountId === account.id) {
|
|
616
|
+
return { alchemy, credentials };
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return undefined;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
async function uniqueProfileName(name: string, alchemy: ProjectAlchemy) {
|
|
624
|
+
const listed = await alchemy.profiles();
|
|
625
|
+
|
|
626
|
+
const taken = new Set(
|
|
627
|
+
listed.status === "ok" ? listed.profiles.map((profile) => profile.name) : []
|
|
628
|
+
);
|
|
629
|
+
|
|
630
|
+
let candidate = name;
|
|
631
|
+
|
|
632
|
+
for (let index = 2; taken.has(candidate); index++) {
|
|
633
|
+
candidate = `${name}-${index}`;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return candidate;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/** Mail domains, primary first, chosen from the account's zones; warns about another provider's MX records. */
|
|
640
|
+
async function chooseMailDomains(
|
|
641
|
+
zones: Zone[],
|
|
642
|
+
api: CloudflareApi,
|
|
643
|
+
requested: string[] | undefined,
|
|
644
|
+
previous: string[],
|
|
645
|
+
deps: CreateDeps
|
|
646
|
+
): Promise<{ domains: string[]; mxBlocked: boolean }> {
|
|
647
|
+
const chosen = await pickMailZones(zones, requested, previous, deps);
|
|
648
|
+
const outcome = await settleMx(chosen, zones.length > 1, api, deps);
|
|
649
|
+
|
|
650
|
+
if (outcome === "back") {
|
|
651
|
+
return chooseMailDomains(
|
|
652
|
+
zones,
|
|
653
|
+
api,
|
|
654
|
+
undefined,
|
|
655
|
+
chosen.map((zone) => zone.name),
|
|
656
|
+
deps
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
return {
|
|
661
|
+
domains: chosen.map((zone) => zone.name),
|
|
662
|
+
mxBlocked: outcome === "blocked",
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/** Checks the zones for another provider's MX records until there are none, or the person moves on. */
|
|
667
|
+
async function settleMx(
|
|
668
|
+
chosen: Zone[],
|
|
669
|
+
canGoBack: boolean,
|
|
670
|
+
api: CloudflareApi,
|
|
671
|
+
deps: CreateDeps
|
|
672
|
+
): Promise<"clear" | "blocked" | "back"> {
|
|
673
|
+
const { ui } = deps;
|
|
674
|
+
const verdict = await checkMx(chosen, api, deps);
|
|
675
|
+
|
|
676
|
+
if (verdict.length === 0) return "clear";
|
|
677
|
+
|
|
678
|
+
ui.warn(
|
|
679
|
+
[
|
|
680
|
+
"Another mail provider's MX records are in:",
|
|
681
|
+
...verdict.flatMap((entry) => describeMx(entry.records)),
|
|
682
|
+
"",
|
|
683
|
+
"Email Routing adds Cloudflare's own MX records and can't start while these",
|
|
684
|
+
"are there, so the deploy would fail. Remove them under DNS → Records in the",
|
|
685
|
+
"Cloudflare dashboard (mail stops reaching the old provider), or leave the",
|
|
686
|
+
"domain out for now.",
|
|
687
|
+
].join("\n")
|
|
688
|
+
);
|
|
689
|
+
|
|
690
|
+
if (!deps.interactive) return "blocked";
|
|
691
|
+
|
|
692
|
+
const next = await ui.select({
|
|
693
|
+
message: "What next?",
|
|
694
|
+
options: [
|
|
695
|
+
{ value: "recheck", label: "I removed them: check again" },
|
|
696
|
+
...(canGoBack
|
|
697
|
+
? [{ value: "back", label: "Choose other mail domains" }]
|
|
698
|
+
: []),
|
|
699
|
+
{
|
|
700
|
+
value: "continue",
|
|
701
|
+
label: "Keep these domains",
|
|
702
|
+
hint: "deploy after removing the records",
|
|
703
|
+
},
|
|
704
|
+
],
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
if (next === "recheck") return settleMx(chosen, canGoBack, api, deps);
|
|
708
|
+
|
|
709
|
+
return next === "back" ? "back" : "blocked";
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
async function pickMailZones(
|
|
713
|
+
zones: Zone[],
|
|
714
|
+
requested: string[] | undefined,
|
|
715
|
+
previous: string[],
|
|
716
|
+
deps: CreateDeps
|
|
717
|
+
) {
|
|
718
|
+
const { ui } = deps;
|
|
719
|
+
|
|
720
|
+
if (requested) {
|
|
721
|
+
const { found, missing } = zonesNamed(requested, zones);
|
|
722
|
+
|
|
723
|
+
if (missing.length === 0) return found;
|
|
724
|
+
|
|
725
|
+
const problem = `${missing.join(", ")} ${missing.length === 1 ? "isn't a zone" : "aren't zones"} in this account. Zones: ${zones.map((zone) => zone.name).join(", ")}`;
|
|
726
|
+
|
|
727
|
+
if (!deps.interactive) throw new Stop(problem);
|
|
728
|
+
|
|
729
|
+
ui.warn(problem);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
const [only] = zones;
|
|
733
|
+
|
|
734
|
+
if (zones.length === 1 && only && !requested && previous.length === 0) {
|
|
735
|
+
ui.info(`Mail domain: ${only.name}, the account's only zone.`);
|
|
736
|
+
|
|
737
|
+
return [only];
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
if (!deps.interactive) {
|
|
741
|
+
throw new Stop(
|
|
742
|
+
"Say which zones are mail domains with --mail-domains, primary first.",
|
|
743
|
+
`Zones: ${zones.map((zone) => zone.name).join(", ")}`
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const ids = await ui.multiselect({
|
|
748
|
+
message: "Mail domains (space to select, enter to confirm)",
|
|
749
|
+
options: zones.map((zone) => ({
|
|
750
|
+
value: zone.id,
|
|
751
|
+
label: zone.name,
|
|
752
|
+
hint: zone.status === "active" ? undefined : zone.status,
|
|
753
|
+
})),
|
|
754
|
+
initialValues: zonesNamed(requested ?? previous, zones).found.map(
|
|
755
|
+
(zone) => zone.id
|
|
756
|
+
),
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
const chosen = zones.filter((zone) => ids.includes(zone.id));
|
|
760
|
+
const [first] = chosen;
|
|
761
|
+
|
|
762
|
+
if (chosen.length < 2 || !first) return chosen;
|
|
763
|
+
|
|
764
|
+
const primaryId = await ui.select({
|
|
765
|
+
message: "Primary mail domain (the first administrator's address is on it)",
|
|
766
|
+
options: chosen.map((zone) => ({ value: zone.id, label: zone.name })),
|
|
767
|
+
initialValue: first.id,
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
const primary = chosen.find((zone) => zone.id === primaryId) ?? first;
|
|
771
|
+
|
|
772
|
+
return primaryFirst(
|
|
773
|
+
chosen.map((zone) => zone.name),
|
|
774
|
+
primary.name
|
|
775
|
+
).flatMap((domain) => chosen.filter((zone) => zone.name === domain));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/** Zones whose MX records point at another provider. A zone whose records can't be read is reported, not blocked. */
|
|
779
|
+
async function checkMx(zones: Zone[], api: CloudflareApi, deps: CreateDeps) {
|
|
780
|
+
const results = await deps.ui.progress(
|
|
781
|
+
"Checking the mail domains' MX records",
|
|
782
|
+
() =>
|
|
783
|
+
Promise.all(
|
|
784
|
+
zones.map(async (zone) => {
|
|
785
|
+
try {
|
|
786
|
+
return { zone, records: foreignMx(await api.mxRecords(zone.id)) };
|
|
787
|
+
} catch (failure) {
|
|
788
|
+
return {
|
|
789
|
+
zone,
|
|
790
|
+
records: [] satisfies MxRecord[],
|
|
791
|
+
unreadable:
|
|
792
|
+
failure instanceof Error ? failure.message : String(failure),
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
})
|
|
796
|
+
),
|
|
797
|
+
(checked) =>
|
|
798
|
+
checked.some((entry) => entry.records.length > 0)
|
|
799
|
+
? "Found another mail provider's MX records"
|
|
800
|
+
: "No other mail provider's MX records"
|
|
801
|
+
);
|
|
802
|
+
|
|
803
|
+
for (const entry of results) {
|
|
804
|
+
if (entry.unreadable) {
|
|
805
|
+
deps.ui.warn(
|
|
806
|
+
`Couldn't read ${entry.zone.name}'s DNS records (${entry.unreadable}). Check that it has no other provider's MX records before deploying.`
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
return results.filter((entry) => entry.records.length > 0);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
async function chooseHostname(
|
|
815
|
+
primary: string,
|
|
816
|
+
zones: Zone[],
|
|
817
|
+
options: CreateOptions,
|
|
818
|
+
deps: CreateDeps
|
|
819
|
+
) {
|
|
820
|
+
const suggested = options.hostname ?? suggestedHostname(primary);
|
|
821
|
+
const problem = hostnameProblem(suggested, zones);
|
|
822
|
+
|
|
823
|
+
if (!deps.interactive) {
|
|
824
|
+
if (problem) throw new Stop(`--hostname: ${problem}`);
|
|
825
|
+
|
|
826
|
+
return suggested;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
if (options.hostname && !problem) return options.hostname;
|
|
830
|
+
|
|
831
|
+
if (options.hostname && problem) deps.ui.warn(`--hostname: ${problem}`);
|
|
832
|
+
|
|
833
|
+
const hostname = await deps.ui.text({
|
|
834
|
+
message: "Hostname the app is served on",
|
|
835
|
+
initialValue: suggested,
|
|
836
|
+
validate: (value) => hostnameProblem(value, zones),
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
return hostname.trim().toLowerCase();
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const AI_KEYS = {
|
|
843
|
+
openai: "OPENAI_API_KEY",
|
|
844
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
845
|
+
} as const;
|
|
846
|
+
|
|
847
|
+
async function chooseAi(options: CreateOptions, deps: CreateDeps) {
|
|
848
|
+
const { ui } = deps;
|
|
849
|
+
|
|
850
|
+
const choice: AiChoice =
|
|
851
|
+
options.ai ??
|
|
852
|
+
(deps.interactive
|
|
853
|
+
? await ui.select<AiChoice>({
|
|
854
|
+
message: "AI for spam filtering, folders, and translation",
|
|
855
|
+
options: [
|
|
856
|
+
{
|
|
857
|
+
value: "cloudflare",
|
|
858
|
+
label: "Cloudflare AI Gateway",
|
|
859
|
+
hint: "no key; uses your account's AI credits",
|
|
860
|
+
},
|
|
861
|
+
{ value: "openai", label: "OpenAI", hint: "needs an API key" },
|
|
862
|
+
{
|
|
863
|
+
value: "anthropic",
|
|
864
|
+
label: "Anthropic",
|
|
865
|
+
hint: "needs an API key",
|
|
866
|
+
},
|
|
867
|
+
{ value: "none", label: "None" },
|
|
868
|
+
],
|
|
869
|
+
})
|
|
870
|
+
: "cloudflare");
|
|
871
|
+
|
|
872
|
+
if (choice !== "openai" && choice !== "anthropic") {
|
|
873
|
+
return { choice, key: undefined };
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
const name = AI_KEYS[choice];
|
|
877
|
+
const fromEnv = deps.env[name];
|
|
878
|
+
|
|
879
|
+
if (fromEnv) {
|
|
880
|
+
ui.info(`Using ${name} from the environment.`);
|
|
881
|
+
|
|
882
|
+
return { choice, key: { name, value: fromEnv } };
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
const value = deps.interactive
|
|
886
|
+
? await ui.password({
|
|
887
|
+
message: `${name} (stored in .env; the deploy needs it, so leave it empty only to add it there later)`,
|
|
888
|
+
})
|
|
889
|
+
: "";
|
|
890
|
+
|
|
891
|
+
return { choice, key: { name, value } };
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function writeProject(
|
|
895
|
+
directory: string,
|
|
896
|
+
answers: ProjectAnswers,
|
|
897
|
+
aiKey: { name: string; value: string } | undefined,
|
|
898
|
+
alchemyProfile: string | undefined
|
|
899
|
+
) {
|
|
900
|
+
const files = {
|
|
901
|
+
"package.json": packageJson(answers),
|
|
902
|
+
"alchemy.run.ts": alchemyRunTs(answers),
|
|
903
|
+
"tsconfig.json": tsconfigJson,
|
|
904
|
+
".gitignore": gitignore,
|
|
905
|
+
"README.md": readme(answers),
|
|
906
|
+
".env": envFile({ aiKey, alchemyProfile }),
|
|
907
|
+
} satisfies Record<string, string>;
|
|
908
|
+
|
|
909
|
+
for (const [file, content] of Object.entries(files)) {
|
|
910
|
+
writeFileSync(join(directory, file), content);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
async function deploy(
|
|
915
|
+
target: {
|
|
916
|
+
name: string;
|
|
917
|
+
hostname: string;
|
|
918
|
+
account: Account;
|
|
919
|
+
primary: string;
|
|
920
|
+
alchemy: ProjectAlchemy;
|
|
921
|
+
},
|
|
922
|
+
blockers: { mxBlocked: boolean; missingKey: string | undefined },
|
|
923
|
+
options: CreateOptions,
|
|
924
|
+
deps: CreateDeps
|
|
925
|
+
) {
|
|
926
|
+
const { ui } = deps;
|
|
927
|
+
const retry = `cd ${target.name}\nbun run deploy`;
|
|
928
|
+
const url = `https://${target.hostname}`;
|
|
929
|
+
const firstAdmin = `create the first administrator with a passkey, on an address at ${target.primary}`;
|
|
930
|
+
|
|
931
|
+
const before = [
|
|
932
|
+
...(blockers.mxBlocked
|
|
933
|
+
? ["Remove the other mail provider's MX records from the mail domains."]
|
|
934
|
+
: []),
|
|
935
|
+
...(blockers.missingKey ? [`Add ${blockers.missingKey} to .env.`] : []),
|
|
936
|
+
];
|
|
937
|
+
|
|
938
|
+
const migrating = () =>
|
|
939
|
+
ui.note(
|
|
940
|
+
"bunx @open-workspace/create import --help # bring people and mail over from Google Workspace, IMAP or mbox",
|
|
941
|
+
"Migrating?"
|
|
942
|
+
);
|
|
943
|
+
|
|
944
|
+
if (!options.deploy || before.length > 0) {
|
|
945
|
+
ui.note(
|
|
946
|
+
[...before, ...(before.length > 0 ? [""] : []), retry].join("\n"),
|
|
947
|
+
before.length > 0 ? "Before deploying" : "Deploy when you're ready"
|
|
948
|
+
);
|
|
949
|
+
migrating();
|
|
950
|
+
ui.outro(`Then open ${url} and ${firstAdmin}.`);
|
|
951
|
+
|
|
952
|
+
return 0;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
const now =
|
|
956
|
+
!deps.interactive ||
|
|
957
|
+
(await ui.confirm({
|
|
958
|
+
message: `Deploy to ${target.account.name} now?`,
|
|
959
|
+
initialValue: true,
|
|
960
|
+
}));
|
|
961
|
+
|
|
962
|
+
if (!now) {
|
|
963
|
+
ui.note(retry, "Deploy when you're ready");
|
|
964
|
+
migrating();
|
|
965
|
+
ui.outro(`Then open ${url} and ${firstAdmin}.`);
|
|
966
|
+
|
|
967
|
+
return 0;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
ui.step(
|
|
971
|
+
"Deploying with Alchemy (bun run deploy). The first deploy takes a few minutes."
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
if (!(await target.alchemy.deploy())) {
|
|
975
|
+
ui.error("The deploy failed; Alchemy printed why above.");
|
|
976
|
+
ui.note(retry, "Fix it, then deploy again");
|
|
977
|
+
ui.outro(`Then open ${url} and ${firstAdmin}.`);
|
|
978
|
+
|
|
979
|
+
return 1;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
ui.success(`Deployed to ${target.account.name}.`);
|
|
983
|
+
migrating();
|
|
984
|
+
ui.outro(`Open ${url} and ${firstAdmin}.`);
|
|
985
|
+
|
|
986
|
+
return 0;
|
|
987
|
+
}
|