@fluid-app/fluid-cli-mist 0.1.51 → 0.1.53
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/index.mjs +35 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -185,7 +185,8 @@ const ENVIRONMENT_STATES = [
|
|
|
185
185
|
"ready",
|
|
186
186
|
"error",
|
|
187
187
|
"expired",
|
|
188
|
-
"deleting"
|
|
188
|
+
"deleting",
|
|
189
|
+
"deleted"
|
|
189
190
|
];
|
|
190
191
|
const OPERATION_KINDS = [
|
|
191
192
|
"ensure_staging",
|
|
@@ -239,6 +240,16 @@ async function requestStaging(client, slug, request) {
|
|
|
239
240
|
const id = await resolveMistId(client, slug);
|
|
240
241
|
return parseOperationEnvelope(await client.post(`${base(id)}/branch-environments/staging`, { source_revision: request.sourceRevision }, { "X-Operation-Key": request.operationKey }));
|
|
241
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Ask the server to tear down one branch environment. The server only takes
|
|
245
|
+
* it out of service and answers with it deleting (or already deleting or
|
|
246
|
+
* deleted); a worker removes its resources shortly after. Repeating the
|
|
247
|
+
* call is harmless.
|
|
248
|
+
*/
|
|
249
|
+
async function removeBranchEnvironment(client, slug, environmentId) {
|
|
250
|
+
const id = await resolveMistId(client, slug);
|
|
251
|
+
return parseEnvironment(record(await client.delete(`${base(id)}/branch-environments/${encodeURIComponent(environmentId)}`), "response")["environment"], "environment");
|
|
252
|
+
}
|
|
242
253
|
/** Read one branch operation of the project. Never advances it. */
|
|
243
254
|
async function fetchBranchOperation(client, slug, operationId) {
|
|
244
255
|
const id = await resolveMistId(client, slug);
|
|
@@ -4368,11 +4379,11 @@ const stagingWaitCommand = new Command("wait").description("Follow a staging ope
|
|
|
4368
4379
|
//#endregion
|
|
4369
4380
|
//#region src/commands/staging/request.ts
|
|
4370
4381
|
/** `fluid mist staging request` — request staging at a revision. */
|
|
4371
|
-
const stagingRequestCommand = new Command("request").description("Request the staging environment at a pushed commit").argument("[slug]", "The mist slug (defaults to .mist file in CWD)").option("--revision <sha>", "Full commit SHA to stage (defaults to this checkout's HEAD when it is clean and on main)").option("--operation-key <key>", "Resume an interrupted request with the key and --revision it printed").option("--wait", "Follow the operation until staging is ready").option("--timeout <minutes>", "How long --wait follows it (default 30)").option("--json", "Emit the operation as JSON").action((slug, opts) => runAction(async () => {
|
|
4382
|
+
const stagingRequestCommand = new Command("request").description("Request the staging environment at a pushed commit").argument("[slug]", "The mist slug (defaults to .mist file in CWD)").option("--revision <sha>", "Full commit SHA to stage (defaults to this checkout's HEAD when it is clean and on main)").option("--operation-key <key>", "Resume an interrupted request with the key and --revision it printed").option("--dir <path>", "Checkout to stage from when --revision is omitted (defaults to the current directory)").option("--wait", "Follow the operation until staging is ready").option("--timeout <minutes>", "How long --wait follows it (default 30)").option("--json", "Emit the operation as JSON").action((slug, opts) => runAction(async () => {
|
|
4372
4383
|
if (opts.operationKey && !opts.revision) throw new Error("--operation-key needs the --revision it was first sent with. The interrupted request printed both.");
|
|
4373
4384
|
const resolved = resolveSlug(slug);
|
|
4374
4385
|
const client = createMistClient();
|
|
4375
|
-
const sourceRevision = opts.revision ?? await localRevision(client, resolved);
|
|
4386
|
+
const sourceRevision = opts.revision ?? await localRevision(client, resolved, opts.dir ?? process.cwd());
|
|
4376
4387
|
let operation = await requestStagingResumably(client, resolved, {
|
|
4377
4388
|
sourceRevision,
|
|
4378
4389
|
operationKey: opts.operationKey,
|
|
@@ -4386,17 +4397,34 @@ const stagingRequestCommand = new Command("request").description("Request the st
|
|
|
4386
4397
|
if (operation.state === "succeeded") console.log(`✔ Staging is ready. Run \`fluid mist staging status\` for its URL.`);
|
|
4387
4398
|
else console.log(`Requested. Follow it with \`fluid mist staging wait --operation ${operation.id}\`.`);
|
|
4388
4399
|
}));
|
|
4389
|
-
/**
|
|
4390
|
-
async function localRevision(client, slug) {
|
|
4400
|
+
/** The checkout's HEAD, once it is clean and already on the remote's main. */
|
|
4401
|
+
async function localRevision(client, slug, checkout) {
|
|
4391
4402
|
const { git_credential: credential } = await createGitCredential(client, slug);
|
|
4392
|
-
const revision = await resolveLocalStagingRevision(
|
|
4403
|
+
const revision = await resolveLocalStagingRevision(checkout, credential.remote_url);
|
|
4393
4404
|
process.stderr.write(chalk.dim(`Staging this checkout's HEAD, ${revision.slice(0, 7)}.\n`));
|
|
4394
4405
|
return revision;
|
|
4395
4406
|
}
|
|
4396
4407
|
//#endregion
|
|
4408
|
+
//#region src/commands/staging/teardown.ts
|
|
4409
|
+
/** `fluid mist staging teardown` — remove the staging environment. */
|
|
4410
|
+
const stagingTeardownCommand = new Command("teardown").description("Tear down the staging environment: its deployment, variables, Git branch and database branch").argument("[slug]", "The mist slug (defaults to .mist file in CWD)").option("--yes", "Confirm the teardown; nothing is removed without it").option("--json", "Emit the environment as JSON").action((slug, opts) => runAction(async () => {
|
|
4411
|
+
const client = createMistClient();
|
|
4412
|
+
const mist = resolveSlug(slug);
|
|
4413
|
+
const { environment } = await readStagingStatus(client, mist);
|
|
4414
|
+
if (!environment || environment.state === "deleted") {
|
|
4415
|
+
if (opts.json) return printJson({ environment: null });
|
|
4416
|
+
console.log(chalk.dim("No staging environment to tear down."));
|
|
4417
|
+
return;
|
|
4418
|
+
}
|
|
4419
|
+
if (!opts.yes) throw new Error("Tearing down staging removes its deployment, variables, Git branch and database branch. Rerun with --yes to confirm.");
|
|
4420
|
+
const removed = await removeBranchEnvironment(client, mist, environment.id);
|
|
4421
|
+
if (opts.json) return printJson({ environment: removed });
|
|
4422
|
+
console.log(removed.state === "deleted" ? "Staging is already torn down." : `Staging is ${chalk.bold(removed.state)}. Its resources are removed within about a minute; check with \`fluid mist staging status\`.`);
|
|
4423
|
+
}));
|
|
4424
|
+
//#endregion
|
|
4397
4425
|
//#region src/commands/staging/index.ts
|
|
4398
4426
|
/** `fluid mist staging` — sub-command aggregator. */
|
|
4399
|
-
const stagingCommand = new Command("staging").description("Use a mist's isolated staging environment").addCommand(stagingStatusCommand).addCommand(stagingRequestCommand).addCommand(stagingWaitCommand);
|
|
4427
|
+
const stagingCommand = new Command("staging").description("Use a mist's isolated staging environment").addCommand(stagingStatusCommand).addCommand(stagingRequestCommand).addCommand(stagingWaitCommand).addCommand(stagingTeardownCommand);
|
|
4400
4428
|
//#endregion
|
|
4401
4429
|
//#region src/index.ts
|
|
4402
4430
|
/**
|