Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-17672123 feat: multi-stage output #1203

Merged
merged 29 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c4ddf5a
Merge pull request #1120 from salesforcecli/mdonnalley/ink
WillieRuemmele Aug 20, 2024
43c38d4
chore: bump mso
mdonnalley Sep 4, 2024
d256725
chore: bump mso
mdonnalley Sep 4, 2024
c0c75d8
chore: bump mso
mdonnalley Sep 4, 2024
b2af5fe
chore(release): 4.5.8-beta.0 [skip ci]
svc-cli-bot Sep 4, 2024
fec8e7d
fix: bump mso
mdonnalley Sep 4, 2024
7ba097d
chore(release): 4.5.8-beta.1 [skip ci]
svc-cli-bot Sep 4, 2024
921bcf2
fix: bump mso
mdonnalley Sep 6, 2024
9585531
chore(release): 4.5.8-beta.2 [skip ci]
svc-cli-bot Sep 6, 2024
2f77ffa
Merge branch 'main' into prerelease/beta
mdonnalley Sep 11, 2024
c647850
fix: bump mso
mdonnalley Sep 11, 2024
b036fde
chore(release): 4.5.8-beta.3 [skip ci]
svc-cli-bot Sep 11, 2024
1654a22
Merge branch 'main' into prerelease/beta
mdonnalley Sep 18, 2024
3bf9b2b
chore(release): 4.5.10-dev.0 [skip ci]
svc-cli-bot Sep 18, 2024
1a68668
Merge branch 'main' into prerelease/beta
mdonnalley Sep 25, 2024
2f3cf92
chore(release): 4.5.11-dev.0 [skip ci]
svc-cli-bot Sep 25, 2024
4623840
Merge branch 'main' into prerelease/beta
mdonnalley Sep 30, 2024
15a1e20
chore(release): 4.6.1-dev.0 [skip ci]
svc-cli-bot Sep 30, 2024
4521a15
Merge branch 'main' into prerelease/beta
mdonnalley Oct 7, 2024
17051a7
fix: upgrade mso
mdonnalley Oct 7, 2024
3e52d14
chore(release): 4.6.1-dev.1 [skip ci]
svc-cli-bot Oct 7, 2024
a742bd0
Merge branch 'main' into prerelease/beta
mdonnalley Oct 14, 2024
62ac5ef
chore(release): 4.6.3-dev.0 [skip ci]
svc-cli-bot Oct 14, 2024
311b19c
fix: ensure stages are capital case
mdonnalley Oct 14, 2024
cf140de
chore(release): 4.6.3-dev.1 [skip ci]
svc-cli-bot Oct 14, 2024
699aea8
fix: bump @oclif/multi-stage-output
mdonnalley Oct 14, 2024
776b689
chore(release): 4.6.3-dev.2 [skip ci]
svc-cli-bot Oct 14, 2024
e9699b2
fix: change prerelease tag
mdonnalley Oct 15, 2024
a96a017
chore(release): 4.6.3-beta.3 [skip ci]
svc-cli-bot Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ FLAG DESCRIPTIONS
sandbox.
```

_See code: [src/commands/org/create/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/create/sandbox.ts)_
_See code: [src/commands/org/create/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/create/sandbox.ts)_

## `sf org create scratch`

Expand Down Expand Up @@ -383,7 +383,7 @@ FLAG DESCRIPTIONS
Omit this flag to have Salesforce generate a unique username for your org.
```

_See code: [src/commands/org/create/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/create/scratch.ts)_
_See code: [src/commands/org/create/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/create/scratch.ts)_

## `sf org delete sandbox`

Expand Down Expand Up @@ -429,7 +429,7 @@ EXAMPLES
$ sf org delete sandbox --target-org my-sandbox --no-prompt
```

_See code: [src/commands/org/delete/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/delete/sandbox.ts)_
_See code: [src/commands/org/delete/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/delete/sandbox.ts)_

## `sf org delete scratch`

Expand Down Expand Up @@ -473,7 +473,7 @@ EXAMPLES
$ sf org delete scratch --target-org my-scratch-org --no-prompt
```

_See code: [src/commands/org/delete/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/delete/scratch.ts)_
_See code: [src/commands/org/delete/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/delete/scratch.ts)_

## `sf org disable tracking`

Expand Down Expand Up @@ -512,7 +512,7 @@ EXAMPLES
$ sf org disable tracking
```

_See code: [src/commands/org/disable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/disable/tracking.ts)_
_See code: [src/commands/org/disable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/disable/tracking.ts)_

## `sf org display`

Expand Down Expand Up @@ -557,7 +557,7 @@ EXAMPLES
$ sf org display --target-org TestOrg1 --verbose
```

_See code: [src/commands/org/display.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/display.ts)_
_See code: [src/commands/org/display.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/display.ts)_

## `sf org enable tracking`

Expand Down Expand Up @@ -599,7 +599,7 @@ EXAMPLES
$ sf org enable tracking
```

_See code: [src/commands/org/enable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/enable/tracking.ts)_
_See code: [src/commands/org/enable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/enable/tracking.ts)_

## `sf org list`

Expand Down Expand Up @@ -638,7 +638,7 @@ EXAMPLES
$ sf org list --clean
```

_See code: [src/commands/org/list.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/list.ts)_
_See code: [src/commands/org/list.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/list.ts)_

## `sf org list metadata`

Expand Down Expand Up @@ -705,7 +705,7 @@ FLAG DESCRIPTIONS
Examples of metadata types that use folders are Dashboard, Document, EmailTemplate, and Report.
```

_See code: [src/commands/org/list/metadata.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/list/metadata.ts)_
_See code: [src/commands/org/list/metadata.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/list/metadata.ts)_

## `sf org list metadata-types`

Expand Down Expand Up @@ -760,7 +760,7 @@ FLAG DESCRIPTIONS
Override the api version used for api requests made by this command
```

_See code: [src/commands/org/list/metadata-types.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/list/metadata-types.ts)_
_See code: [src/commands/org/list/metadata-types.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/list/metadata-types.ts)_

## `sf org open`

Expand Down Expand Up @@ -832,7 +832,7 @@ EXAMPLES
$ sf org open --source-file force-app/main/default/flows/Hello.flow-meta.xml
```

_See code: [src/commands/org/open.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/open.ts)_
_See code: [src/commands/org/open.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/open.ts)_

## `sf org refresh sandbox`

Expand Down Expand Up @@ -909,7 +909,7 @@ FLAG DESCRIPTIONS
By default, a sandbox auto-activates after a refresh. Use this flag to control sandbox activation manually.
```

_See code: [src/commands/org/refresh/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/refresh/sandbox.ts)_
_See code: [src/commands/org/refresh/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/refresh/sandbox.ts)_

## `sf org resume sandbox`

Expand Down Expand Up @@ -972,7 +972,7 @@ FLAG DESCRIPTIONS
returns the job ID. To resume checking the sandbox creation, rerun this command.
```

_See code: [src/commands/org/resume/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/resume/sandbox.ts)_
_See code: [src/commands/org/resume/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/resume/sandbox.ts)_

## `sf org resume scratch`

Expand Down Expand Up @@ -1019,6 +1019,6 @@ FLAG DESCRIPTIONS
The job ID is valid for 24 hours after you start the scratch org creation.
```

_See code: [src/commands/org/resume/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.2/src/commands/org/resume/scratch.ts)_
_See code: [src/commands/org/resume/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.3-beta.0/src/commands/org/resume/scratch.ts)_

<!-- commandsstop -->
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
{
"name": "@salesforce/plugin-org",
"description": "Commands to interact with Salesforce orgs",
"version": "4.6.2",
"version": "4.6.3-beta.3",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^4.0.28",
"@oclif/multi-stage-output": "^0.7.7",
"@salesforce/core": "^8.6.1",
"@salesforce/kit": "^3.2.3",
"@salesforce/sf-plugins-core": "^11.3.12",
"@salesforce/source-deploy-retrieve": "^12.7.1",
"ansis": "^3.2.0",
"change-case": "^5.4.4",
"is-wsl": "^3.1.0",
"open": "^10.1.0"
"open": "^10.1.0",
"terminal-link": "^3.0.0"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^5.2.18",
Expand Down
69 changes: 53 additions & 16 deletions src/commands/org/create/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { MultiStageOutput } from '@oclif/multi-stage-output';
import {
Lifecycle,
Messages,
Org,
scratchOrgCreate,
ScratchOrgLifecycleEvent,
scratchOrgLifecycleEventName,
scratchOrgLifecycleStages,
SfError,
} from '@salesforce/core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Duration } from '@salesforce/kit';
import terminalLink from 'terminal-link';
import { capitalCase } from 'change-case';
import { buildScratchOrgRequest } from '../../../shared/scratchOrgRequest.js';
import { buildStatus } from '../../../shared/scratchOrgOutput.js';
import { ScratchCreateResponse } from '../../../shared/orgTypes.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-org', 'create_scratch');

const definitionFileHelpGroupName = 'Definition File Override';

export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
Expand Down Expand Up @@ -167,38 +171,71 @@ export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> {
flags,
flags['client-id'] ? await this.secretPrompt({ message: messages.getMessage('prompt.secret') }) : undefined
);
let lastStatus: string | undefined;

if (!flags.async) {
lifecycle.on<ScratchOrgLifecycleEvent>(scratchOrgLifecycleEventName, async (data): Promise<void> => {
lastStatus = buildStatus(data, baseUrl);
this.spinner.status = lastStatus;
return Promise.resolve();
});
}
this.log();
this.spinner.start(
flags.async ? 'Requesting Scratch Org (will not wait for completion because --async)' : 'Creating Scratch Org'
);
const mso = new MultiStageOutput<ScratchOrgLifecycleEvent & { alias: string | undefined }>({
stages: (flags.async ? ['prepare request', 'send request', 'done'] : scratchOrgLifecycleStages).map((stage) =>
capitalCase(stage)
),
title: flags.async ? 'Creating Scratch Org (async)' : 'Creating Scratch Org',
data: { alias: flags.alias },
jsonEnabled: this.jsonEnabled(),
postStagesBlock: [
{
label: 'Request Id',
type: 'dynamic-key-value',
get: (data) =>
data?.scratchOrgInfo?.Id && terminalLink(data.scratchOrgInfo.Id, `${baseUrl}/${data.scratchOrgInfo.Id}`),
bold: true,
},
{
label: 'OrgId',
type: 'dynamic-key-value',
get: (data) => data?.scratchOrgInfo?.ScratchOrg,
bold: true,
color: 'cyan',
},
{
label: 'Username',
type: 'dynamic-key-value',
get: (data) => data?.scratchOrgInfo?.SignupUsername,
bold: true,
color: 'cyan',
},
{
label: 'Alias',
type: 'static-key-value',
get: (data) => data?.alias,
},
],
});

lifecycle.on<ScratchOrgLifecycleEvent>(scratchOrgLifecycleEventName, async (data): Promise<void> => {
mso.skipTo(capitalCase(data.stage), data);
if (data.stage === 'done') {
mso.stop();
}
return Promise.resolve();
});

try {
const { username, scratchOrgInfo, authFields, warnings } = await scratchOrgCreate(createCommandOptions);

this.spinner.stop(lastStatus);
if (!scratchOrgInfo) {
throw new SfError('The scratch org did not return with any information');
}
this.log();

if (flags.async) {
mso.skipTo('Done', { scratchOrgInfo });
mso.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) {
mso.error();
if (error instanceof SfError && error.name === 'ScratchOrgInfoTimeoutError') {
this.spinner.stop(lastStatus);
const scratchOrgInfoId = (error.data as { scratchOrgInfoId: string }).scratchOrgInfoId;
const resumeMessage = messages.getMessage('action.resume', [this.config.bin, scratchOrgInfoId]);

Expand Down
57 changes: 47 additions & 10 deletions src/commands/org/resume/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import {
ScratchOrgCache,
ScratchOrgLifecycleEvent,
scratchOrgLifecycleEventName,
scratchOrgLifecycleStages,
scratchOrgResume,
SfError,
} from '@salesforce/core';
import terminalLink from 'terminal-link';
import { MultiStageOutput } from '@oclif/multi-stage-output';
import { capitalCase } from 'change-case';
import { ScratchCreateResponse } from '../../../shared/orgTypes.js';
import { buildStatus } from '../../../shared/scratchOrgOutput.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-org', 'resume_scratch');
Expand Down Expand Up @@ -55,26 +58,60 @@ export default class OrgResumeScratch extends SfCommand<ScratchCreateResponse> {

// oclif doesn't know that the exactlyOne flag will ensure that one of these is set, and there we definitely have a jobID.
assert(jobId);
const hubBaseUrl = cache.get(jobId)?.hubBaseUrl;
let lastStatus: string | undefined;
const cached = cache.get(jobId);
const hubBaseUrl = cached?.hubBaseUrl;

const mso = new MultiStageOutput<ScratchOrgLifecycleEvent & { alias: string | undefined }>({
stages: scratchOrgLifecycleStages.map((stage) => capitalCase(stage)),
title: 'Resuming Scratch Org',
data: { alias: cached?.alias },
jsonEnabled: this.jsonEnabled(),
postStagesBlock: [
{
label: 'Request Id',
type: 'dynamic-key-value',
get: (data) =>
data?.scratchOrgInfo?.Id && terminalLink(data.scratchOrgInfo.Id, `${hubBaseUrl}/${data.scratchOrgInfo.Id}`),
bold: true,
},
{
label: 'OrgId',
type: 'dynamic-key-value',
get: (data) => data?.scratchOrgInfo?.ScratchOrg,
bold: true,
color: 'cyan',
},
{
label: 'Username',
type: 'dynamic-key-value',
get: (data) => data?.scratchOrgInfo?.SignupUsername,
bold: true,
color: 'cyan',
},
{
label: 'Alias',
type: 'static-key-value',
get: (data) => data?.alias,
},
],
});

lifecycle.on<ScratchOrgLifecycleEvent>(scratchOrgLifecycleEventName, async (data): Promise<void> => {
lastStatus = buildStatus(data, hubBaseUrl);
this.spinner.status = lastStatus;
mso.skipTo(capitalCase(data.stage), data);
if (data.stage === 'done') {
mso.stop();
}
return Promise.resolve();
});

this.log();
this.spinner.start('Creating Scratch Org');

try {
const { username, scratchOrgInfo, authFields, warnings } = await scratchOrgResume(jobId);
this.spinner.stop(lastStatus);

this.log();
this.logSuccess(messages.getMessage('success'));
return { username, scratchOrgInfo, authFields, warnings, orgId: authFields?.orgId };
} catch (e) {
mso.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
throw messages.createError('error.jobIdMismatch', [jobId]);
Expand Down
41 changes: 0 additions & 41 deletions src/shared/scratchOrgOutput.ts

This file was deleted.

Loading