Skip to content

Commit

Permalink
fix: use sf-plugins-core
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Aug 16, 2024
1 parent f7fbab6 commit 5ad0309
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 255 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^4.0.16",
"@oclif/multi-stage-output": "^0.2.0",
"@salesforce/core": "^8.2.7",
"@salesforce/kit": "^3.2.0",
"@salesforce/sf-plugins-core": "^11.3.0",
"@salesforce/sf-plugins-core": "^11.3.3-dev.2",
"@salesforce/source-deploy-retrieve": "^12.1.12",
"ansis": "^3.2.0",
"change-case": "^5.4.4",
Expand Down
14 changes: 6 additions & 8 deletions src/commands/org/create/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Duration } from '@salesforce/kit';
import terminalLink from 'terminal-link';
import { MultiStageOutput } from '@oclif/multi-stage-output';
import { buildScratchOrgRequest } from '../../../shared/scratchOrgRequest.js';
import { ScratchCreateResponse } from '../../../shared/orgTypes.js';

Expand Down Expand Up @@ -171,10 +170,9 @@ export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> {
flags['client-id'] ? await this.secretPrompt({ message: messages.getMessage('prompt.secret') }) : undefined
);

const ms = new MultiStageOutput<ScratchOrgLifecycleEvent & { alias: string | undefined }>({
const stager = this.initStager<ScratchOrgLifecycleEvent & { alias: string | undefined }>({
stages: flags.async ? ['prepare request', 'send request', 'done'] : scratchOrgLifecycleStages,
title: flags.async ? 'Creating Scratch Org (async)' : 'Creating Scratch Org',
jsonEnabled: this.jsonEnabled(),
data: { alias: flags.alias },
postStagesBlock: [
{
Expand Down Expand Up @@ -207,9 +205,9 @@ export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> {
});

lifecycle.on<ScratchOrgLifecycleEvent>(scratchOrgLifecycleEventName, async (data): Promise<void> => {
ms.goto(data.stage, data);
stager.goto(data.stage, data);
if (data.stage === 'done') {
ms.stop();
stager.stop();
}
return Promise.resolve();
});
Expand All @@ -222,16 +220,16 @@ export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> {
}

if (flags.async) {
ms.goto('done', { scratchOrgInfo });
ms.stop();
stager.goto('done', { scratchOrgInfo });
stager.stop();
this.info(messages.getMessage('action.resume', [this.config.bin, scratchOrgInfo.Id]));
} else {
this.logSuccess(messages.getMessage('success'));
}

return { username, scratchOrgInfo, authFields, warnings, orgId: authFields?.orgId };
} catch (error) {
ms.stop(error as Error);
stager.stop(error as Error);
if (error instanceof SfError && error.name === 'ScratchOrgInfoTimeoutError') {
const scratchOrgInfoId = (error.data as { scratchOrgInfoId: string }).scratchOrgInfoId;
const resumeMessage = messages.getMessage('action.resume', [this.config.bin, scratchOrgInfoId]);
Expand Down
10 changes: 4 additions & 6 deletions src/commands/org/resume/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
SfError,
} from '@salesforce/core';
import terminalLink from 'terminal-link';
import { MultiStageOutput } from '@oclif/multi-stage-output';
import { ScratchCreateResponse } from '../../../shared/orgTypes.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
Expand Down Expand Up @@ -60,10 +59,9 @@ export default class OrgResumeScratch extends SfCommand<ScratchCreateResponse> {
const cached = cache.get(jobId);
const hubBaseUrl = cached?.hubBaseUrl;

const ms = new MultiStageOutput<ScratchOrgLifecycleEvent & { alias: string | undefined }>({
const stager = this.initStager<ScratchOrgLifecycleEvent & { alias: string | undefined }>({
stages: scratchOrgLifecycleStages,
title: 'Resuming Scratch Org',
jsonEnabled: this.jsonEnabled(),
data: { alias: cached?.alias },
postStagesBlock: [
{
Expand Down Expand Up @@ -96,9 +94,9 @@ export default class OrgResumeScratch extends SfCommand<ScratchCreateResponse> {
});

lifecycle.on<ScratchOrgLifecycleEvent>(scratchOrgLifecycleEventName, async (data): Promise<void> => {
ms.goto(data.stage, data);
stager.goto(data.stage, data);
if (data.stage === 'done') {
ms.stop();
stager.stop();
}
return Promise.resolve();
});
Expand All @@ -109,7 +107,7 @@ export default class OrgResumeScratch extends SfCommand<ScratchCreateResponse> {
this.logSuccess(messages.getMessage('success'));
return { username, scratchOrgInfo, authFields, warnings, orgId: authFields?.orgId };
} catch (e) {
ms.stop(e as Error);
stager.stop(e as Error);

if (cache.keys() && e instanceof Error && e.name === 'CacheMissError') {
// we have something in the cache, but it didn't match what the user passed in
Expand Down
Loading

0 comments on commit 5ad0309

Please sign in to comment.