@studiometa/forge-cli 0.5.5 → 0.5.6

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 CHANGED
@@ -5365,20 +5365,27 @@ var REPOSITORY_HINT = (serverId) => `Check that the git host accepts the key of
5365
5365
  var defaultSleep = (ms) => new Promise((resolve) => {
5366
5366
  setTimeout(resolve, ms);
5367
5367
  });
5368
- async function waitForSite(file, serverId, siteId, ctx, options) {
5368
+ /**
5369
+ * Read a new resource until Forge has installed it. Throw the error of `fail` when its status is
5370
+ * `failed` or when it is not installed in time.
5371
+ */
5372
+ async function waitForInstalled(read, fail, options) {
5369
5373
  const sleep = options.sleep ?? defaultSleep;
5370
5374
  const interval = options.pollIntervalMs ?? 5e3;
5371
5375
  const timeout = options.timeoutMs ?? 6e5;
5372
5376
  for (let waited = 0;; waited += interval) {
5373
- const site = (await getSite({
5374
- server_id: serverId,
5375
- site_id: siteId
5376
- }, ctx)).data;
5377
- if (site.status === "installed") return;
5378
- if (waited >= timeout) throw new ApplyError(`Site ${site.name} is still ${site.status} on Forge`, ["Run forge sites apply again once the site is installed", ...file.repository ? [REPOSITORY_HINT(serverId)] : []]);
5377
+ const resource = await read();
5378
+ if (resource.status === "installed") return;
5379
+ if (resource.status === "failed" || waited >= timeout) throw fail(resource);
5379
5380
  await sleep(interval);
5380
5381
  }
5381
5382
  }
5383
+ async function waitForSite(file, serverId, siteId, ctx, options) {
5384
+ await waitForInstalled(async () => (await getSite({
5385
+ server_id: serverId,
5386
+ site_id: siteId
5387
+ }, ctx)).data, (site) => new ApplyError(`Site ${site.name} is still ${site.status} on Forge`, ["Run forge sites apply again once the site is installed", ...file.repository ? [REPOSITORY_HINT(serverId)] : []]), options);
5388
+ }
5382
5389
  /**
5383
5390
  * Create the database and its user. Returns their IDs and the .env values to write.
5384
5391
  */
@@ -5392,10 +5399,15 @@ async function applyDatabase(file, plan, state, serverId, ctx, options) {
5392
5399
  let databaseId = state.databases?.find((db) => db.name === file.database.name)?.id;
5393
5400
  for (const change of plan.changes) if (change.action === "create-database") {
5394
5401
  options.onChange?.(change);
5395
- databaseId = (await createDatabase({
5402
+ const id = (await createDatabase({
5396
5403
  server_id: serverId,
5397
5404
  name: change.name
5398
5405
  }, ctx)).data.id;
5406
+ await waitForInstalled(async () => (await getDatabase({
5407
+ server_id: serverId,
5408
+ id: String(id)
5409
+ }, ctx)).data, (database) => new ApplyError(`Database ${change.name} is ${database.status} on Forge, not installed`, ["Run forge sites apply again once the database is installed"]), options);
5410
+ databaseId = id;
5399
5411
  } else if (change.action === "create-database-user") {
5400
5412
  options.onChange?.(change);
5401
5413
  const password = (options.generatePassword ?? generatePassword)();
@@ -5405,6 +5417,10 @@ async function applyDatabase(file, plan, state, serverId, ctx, options) {
5405
5417
  password,
5406
5418
  ...databaseId === void 0 ? {} : { database_ids: [databaseId] }
5407
5419
  }, ctx);
5420
+ await waitForInstalled(async () => (await getDatabaseUser({
5421
+ server_id: serverId,
5422
+ id: String(user.data.id)
5423
+ }, ctx)).data, (created) => new ApplyError(`Database user ${change.name} is ${created.status} on Forge, not installed`, [`The database user ${change.name} exists on Forge, but its password was not saved`, `Delete the database user ${change.name} on Forge before you run forge sites apply again`]), options);
5408
5424
  ids.database_user_id = String(user.data.id);
5409
5425
  const keys = databaseEnvKeys(file.database);
5410
5426
  env.set(keys.name, change.database);
@@ -6799,7 +6815,7 @@ function isVersionRequest({ command, options }) {
6799
6815
  }
6800
6816
  //#endregion
6801
6817
  //#region src/cli.ts
6802
- var VERSION = "0.5.5";
6818
+ var VERSION = "0.5.6";
6803
6819
  function showHelp() {
6804
6820
  console.log(`
6805
6821
  ${colors.bold("forge")} v${VERSION}