betterstart-cli 0.0.74 → 0.0.75
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/dist/cli.js +54 -37
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -20138,6 +20138,10 @@ function spinner2(options) {
|
|
|
20138
20138
|
};
|
|
20139
20139
|
return {
|
|
20140
20140
|
start: (message = "") => {
|
|
20141
|
+
if (started) {
|
|
20142
|
+
inner.message(fitSpinnerMessage(message));
|
|
20143
|
+
return;
|
|
20144
|
+
}
|
|
20141
20145
|
setStarted(true);
|
|
20142
20146
|
inner.start(fitSpinnerMessage(message));
|
|
20143
20147
|
},
|
|
@@ -23101,7 +23105,7 @@ async function ensureRailwayProject(runner, options) {
|
|
|
23101
23105
|
projectSpinner.start("Checking Railway project names");
|
|
23102
23106
|
}
|
|
23103
23107
|
const projects = await listRailwayProjects(runner, options.cwd, options.env);
|
|
23104
|
-
projectSpinner.
|
|
23108
|
+
projectSpinner.message(`Creating Railway project ${pc2.cyan(options.projectName)}`);
|
|
23105
23109
|
const created = await createRailwayProject(
|
|
23106
23110
|
runner,
|
|
23107
23111
|
options.cwd,
|
|
@@ -23243,41 +23247,48 @@ async function waitForPostgresVariables(session, cwd, service) {
|
|
|
23243
23247
|
return {};
|
|
23244
23248
|
}
|
|
23245
23249
|
async function ensureRailwayPostgres(session, cwd) {
|
|
23246
|
-
const
|
|
23247
|
-
|
|
23248
|
-
|
|
23249
|
-
const
|
|
23250
|
-
|
|
23251
|
-
|
|
23250
|
+
const provisionSpinner = spinner2();
|
|
23251
|
+
provisionSpinner.start("Creating your Railway Postgres database");
|
|
23252
|
+
try {
|
|
23253
|
+
const services = await listRailwayServices(session, cwd);
|
|
23254
|
+
const candidates = services.filter((service2) => /^postgres(?:[-_ ].*)?$/i.test(service2.name));
|
|
23255
|
+
for (const candidate of candidates) {
|
|
23256
|
+
const variables2 = await readRailwayServiceVariables(session, cwd, candidate.name);
|
|
23257
|
+
if (variables2.DATABASE_PUBLIC_URL) {
|
|
23258
|
+
return { service: candidate, databaseUrl: variables2.DATABASE_PUBLIC_URL };
|
|
23259
|
+
}
|
|
23252
23260
|
}
|
|
23253
|
-
|
|
23254
|
-
|
|
23255
|
-
|
|
23256
|
-
|
|
23257
|
-
|
|
23258
|
-
|
|
23259
|
-
|
|
23260
|
-
|
|
23261
|
-
|
|
23262
|
-
|
|
23263
|
-
|
|
23264
|
-
|
|
23265
|
-
|
|
23266
|
-
|
|
23267
|
-
|
|
23268
|
-
|
|
23269
|
-
railwayOutputTail(`${result.stdout}
|
|
23261
|
+
if (candidates.length > 0) {
|
|
23262
|
+
throw new Error(
|
|
23263
|
+
`Railway Postgres service ${candidates.map((candidate) => candidate.name).join(", ")} exists, but DATABASE_PUBLIC_URL is not available. Rerun init after the database is ready.`
|
|
23264
|
+
);
|
|
23265
|
+
}
|
|
23266
|
+
const result = await runRailway(session.runner, ["add", "--database", "postgres", "--json"], {
|
|
23267
|
+
cwd,
|
|
23268
|
+
mode: "capture",
|
|
23269
|
+
env: session.env
|
|
23270
|
+
});
|
|
23271
|
+
const payload = result.success ? parseRailwayJson(result.stdout) : void 0;
|
|
23272
|
+
const serviceName = payload && isNonEmptyString(payload.serviceName) ? payload.serviceName : null;
|
|
23273
|
+
const serviceId = payload && isNonEmptyString(payload.serviceId) ? payload.serviceId : null;
|
|
23274
|
+
if (!result.success || !serviceName) {
|
|
23275
|
+
throw new Error(
|
|
23276
|
+
railwayOutputTail(`${result.stdout}
|
|
23270
23277
|
${result.stderr}`) ?? "Could not provision Railway Postgres."
|
|
23271
|
-
|
|
23272
|
-
|
|
23273
|
-
|
|
23274
|
-
|
|
23275
|
-
|
|
23276
|
-
|
|
23277
|
-
|
|
23278
|
-
|
|
23278
|
+
);
|
|
23279
|
+
}
|
|
23280
|
+
const service = { id: serviceId ?? serviceName, name: serviceName };
|
|
23281
|
+
provisionSpinner.message("Waiting for the database connection string");
|
|
23282
|
+
const variables = await waitForPostgresVariables(session, cwd, service);
|
|
23283
|
+
if (!variables.DATABASE_PUBLIC_URL) {
|
|
23284
|
+
throw new Error(
|
|
23285
|
+
`Railway created ${service.name}, but DATABASE_PUBLIC_URL was not available. Rerun init after the database is ready.`
|
|
23286
|
+
);
|
|
23287
|
+
}
|
|
23288
|
+
return { service, databaseUrl: variables.DATABASE_PUBLIC_URL };
|
|
23289
|
+
} finally {
|
|
23290
|
+
provisionSpinner.clear();
|
|
23279
23291
|
}
|
|
23280
|
-
return { service, databaseUrl: variables.DATABASE_PUBLIC_URL };
|
|
23281
23292
|
}
|
|
23282
23293
|
function parseBucket(value) {
|
|
23283
23294
|
if (!value || typeof value !== "object") return void 0;
|
|
@@ -23308,6 +23319,15 @@ function parseBucketCredentials(value) {
|
|
|
23308
23319
|
async function ensureRailwayBucket(session, cwd, options) {
|
|
23309
23320
|
const name = options.name ?? "media";
|
|
23310
23321
|
const environmentArgs = ["--environment", session.project.environmentName];
|
|
23322
|
+
const provisionSpinner = spinner2();
|
|
23323
|
+
provisionSpinner.start("Creating your Railway bucket");
|
|
23324
|
+
try {
|
|
23325
|
+
return await provisionRailwayBucketResource(session, cwd, name, options.region, environmentArgs);
|
|
23326
|
+
} finally {
|
|
23327
|
+
provisionSpinner.clear();
|
|
23328
|
+
}
|
|
23329
|
+
}
|
|
23330
|
+
async function provisionRailwayBucketResource(session, cwd, name, region, environmentArgs) {
|
|
23311
23331
|
const list = await runRailway(session.runner, ["bucket", "list", ...environmentArgs, "--json"], {
|
|
23312
23332
|
cwd,
|
|
23313
23333
|
mode: "capture",
|
|
@@ -23332,7 +23352,7 @@ ${list.stderr}`) ?? "Could not list Railway buckets."
|
|
|
23332
23352
|
if (!bucket) {
|
|
23333
23353
|
const create = await runRailway(
|
|
23334
23354
|
session.runner,
|
|
23335
|
-
["bucket", "create", name, "--region",
|
|
23355
|
+
["bucket", "create", name, "--region", region, ...environmentArgs, "--json"],
|
|
23336
23356
|
{ cwd, mode: "capture", env: session.env }
|
|
23337
23357
|
);
|
|
23338
23358
|
const createPayload = create.success ? parseRailwayJson(create.stdout) : void 0;
|
|
@@ -27289,9 +27309,6 @@ async function runInitCommand(name, options) {
|
|
|
27289
27309
|
databaseUrl = await promptConnectionString();
|
|
27290
27310
|
}
|
|
27291
27311
|
} else {
|
|
27292
|
-
p22.log.warn(
|
|
27293
|
-
"Railway Postgres is container-backed. Plan and test your own backups, upgrades, and high-availability strategy before production use."
|
|
27294
|
-
);
|
|
27295
27312
|
try {
|
|
27296
27313
|
const session = await getRailwaySession();
|
|
27297
27314
|
const postgres = await ensureRailwayPostgres(session, cwd);
|