Skip to content

Commit

Permalink
feat: update mso
Browse files Browse the repository at this point in the history
  • Loading branch information
soridalac committed Dec 13, 2024
1 parent 04c180d commit b81a7c8
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions src/commands/org/create/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
*/

import { Duration } from '@salesforce/kit';
import { MultiStageOutput } from '@oclif/multi-stage-output';
import { Flags } from '@salesforce/sf-plugins-core';
import { Lifecycle, Messages, SandboxEvents, SandboxRequest, SfError } from '@salesforce/core';
import { Lifecycle, Messages, SandboxEvents, SandboxProcessObject, SandboxRequest, SfError } from '@salesforce/core';
import { Interfaces } from '@oclif/core';
import requestFunctions, { readSandboxDefFile } from '../../../shared/sandboxRequest.js';
import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js';
import { SandboxLicenseType } from '../../../shared/orgTypes.js';
import sandboxRequest from '../../../shared/sandboxRequest.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-org', 'create.sandbox');
Expand Down Expand Up @@ -124,6 +126,7 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResp

this.debug('Create started with args %s ', this.flags);
this.validateFlags();

return this.createSandbox();
}

Expand Down Expand Up @@ -203,26 +206,66 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResp
});
this.initSandboxProcessData(sandboxReq);

const mso = new MultiStageOutput<{status: string; id: string}>({
stages: this.flags.async
? ['Prepare request', 'Send request', 'Done']
: ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'],
title: this.flags.async ? 'Create Sandbox (async)': 'Create Sandbox',
jsonEnabled: false,
postStagesBlock: [
{
label: 'SandboxId',
get: (data) => data?.id,
type: 'dynamic-key-value',
bold: true
},
{
label: 'Status',
get: (data) => data?.status,
type: 'dynamic-key-value',
bold: true
},
]
});

mso.goto('Prepare request', {status: 'Pending'});

if (!this.flags.async) {
this.spinner.start('Sandbox Create');
mso.skipTo('Send request');
}

this.debug('Calling create with SandboxRequest: %s ', sandboxReq);

try {
mso.goto('Send request', {status: 'In Progress'});
const sandboxProcessObject = await this.prodOrg.createSandbox(sandboxReq, {
wait: this.flags.wait,
interval: this.flags['poll-interval'],
async: this.flags.async,
});
console.log('Sandbox Process Object', sandboxProcessObject);

mso.updateData({status: sandboxProcessObject.Status, id: sandboxProcessObject.Id});

if (sandboxProcessObject.Status === 'In Progress') {
mso.goto('Waiting for org to respond', { status: 'In Progress', id: sandboxProcessObject.Id});
}

this.latestSandboxProgressObj = sandboxProcessObject;
this.saveSandboxProgressConfig();

mso.goto('Done', {status: sandboxProcessObject.Status, id: sandboxProcessObject.Id});
if (this.flags.async) {
mso.goto('Waiting for org to respond', { status: 'Pending', id: sandboxProcessObject.Id});

mso.skipTo('Done', {status: sandboxProcessObject.Status, id: sandboxProcessObject.Id});
mso.stop();
process.exitCode = 68;
}
return this.getSandboxCommandResponse();
} catch (err) {
this.spinner.stop();
mso.error()
mso.stop();
if (this.pollingTimeOut && this.latestSandboxProgressObj) {
void lifecycle.emit(SandboxEvents.EVENT_ASYNC_RESULT, undefined);
process.exitCode = 68;
Expand Down

0 comments on commit b81a7c8

Please sign in to comment.