|
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
6 | 6 | */ |
7 | 7 |
|
8 | | -import { MultiStageOutput } from '@oclif/multi-stage-output'; |
9 | 8 | import { |
10 | 9 | Lifecycle, |
11 | 10 | Messages, |
12 | 11 | Org, |
13 | 12 | scratchOrgCreate, |
14 | 13 | ScratchOrgLifecycleEvent, |
15 | 14 | scratchOrgLifecycleEventName, |
16 | | - scratchOrgLifecycleStages, |
17 | 15 | SfError, |
18 | 16 | } from '@salesforce/core'; |
19 | 17 | import { Flags, SfCommand } from '@salesforce/sf-plugins-core'; |
20 | 18 | import { Duration } from '@salesforce/kit'; |
21 | | -import terminalLink from 'terminal-link'; |
22 | 19 | import { buildScratchOrgRequest } from '../../../shared/scratchOrgRequest.js'; |
| 20 | +import { buildStatus } from '../../../shared/scratchOrgOutput.js'; |
23 | 21 | import { ScratchCreateResponse } from '../../../shared/orgTypes.js'; |
24 | 22 |
|
25 | 23 | Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); |
26 | 24 | const messages = Messages.loadMessages('@salesforce/plugin-org', 'create_scratch'); |
27 | 25 |
|
28 | 26 | const definitionFileHelpGroupName = 'Definition File Override'; |
29 | | - |
30 | 27 | export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> { |
31 | 28 | public static readonly summary = messages.getMessage('summary'); |
32 | 29 | public static readonly description = messages.getMessage('description'); |
@@ -170,69 +167,38 @@ export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> { |
170 | 167 | flags, |
171 | 168 | flags['client-id'] ? await this.secretPrompt({ message: messages.getMessage('prompt.secret') }) : undefined |
172 | 169 | ); |
| 170 | + let lastStatus: string | undefined; |
173 | 171 |
|
174 | | - const stager = new MultiStageOutput<ScratchOrgLifecycleEvent & { alias: string | undefined }>({ |
175 | | - stages: flags.async ? ['prepare request', 'send request', 'done'] : scratchOrgLifecycleStages, |
176 | | - title: flags.async ? 'Creating Scratch Org (async)' : 'Creating Scratch Org', |
177 | | - data: { alias: flags.alias }, |
178 | | - jsonEnabled: this.jsonEnabled(), |
179 | | - postStagesBlock: [ |
180 | | - { |
181 | | - label: 'Request Id', |
182 | | - type: 'dynamic-key-value', |
183 | | - get: (data) => |
184 | | - data?.scratchOrgInfo?.Id && terminalLink(data.scratchOrgInfo.Id, `${baseUrl}/${data.scratchOrgInfo.Id}`), |
185 | | - bold: true, |
186 | | - }, |
187 | | - { |
188 | | - label: 'OrgId', |
189 | | - type: 'dynamic-key-value', |
190 | | - get: (data) => data?.scratchOrgInfo?.ScratchOrg, |
191 | | - bold: true, |
192 | | - color: 'cyan', |
193 | | - }, |
194 | | - { |
195 | | - label: 'Username', |
196 | | - type: 'dynamic-key-value', |
197 | | - get: (data) => data?.scratchOrgInfo?.SignupUsername, |
198 | | - bold: true, |
199 | | - color: 'cyan', |
200 | | - }, |
201 | | - { |
202 | | - label: 'Alias', |
203 | | - type: 'static-key-value', |
204 | | - get: (data) => data?.alias, |
205 | | - }, |
206 | | - ], |
207 | | - }); |
208 | | - |
209 | | - lifecycle.on<ScratchOrgLifecycleEvent>(scratchOrgLifecycleEventName, async (data): Promise<void> => { |
210 | | - stager.goto(data.stage, data); |
211 | | - if (data.stage === 'done') { |
212 | | - stager.stop(); |
213 | | - } |
214 | | - return Promise.resolve(); |
215 | | - }); |
| 172 | + if (!flags.async) { |
| 173 | + lifecycle.on<ScratchOrgLifecycleEvent>(scratchOrgLifecycleEventName, async (data): Promise<void> => { |
| 174 | + lastStatus = buildStatus(data, baseUrl); |
| 175 | + this.spinner.status = lastStatus; |
| 176 | + return Promise.resolve(); |
| 177 | + }); |
| 178 | + } |
| 179 | + this.log(); |
| 180 | + this.spinner.start( |
| 181 | + flags.async ? 'Requesting Scratch Org (will not wait for completion because --async)' : 'Creating Scratch Org' |
| 182 | + ); |
216 | 183 |
|
217 | 184 | try { |
218 | 185 | const { username, scratchOrgInfo, authFields, warnings } = await scratchOrgCreate(createCommandOptions); |
219 | 186 |
|
| 187 | + this.spinner.stop(lastStatus); |
220 | 188 | if (!scratchOrgInfo) { |
221 | 189 | throw new SfError('The scratch org did not return with any information'); |
222 | 190 | } |
223 | | - |
| 191 | + this.log(); |
224 | 192 | if (flags.async) { |
225 | | - stager.goto('done', { scratchOrgInfo }); |
226 | | - stager.stop(); |
227 | 193 | this.info(messages.getMessage('action.resume', [this.config.bin, scratchOrgInfo.Id])); |
228 | 194 | } else { |
229 | 195 | this.logSuccess(messages.getMessage('success')); |
230 | 196 | } |
231 | 197 |
|
232 | 198 | return { username, scratchOrgInfo, authFields, warnings, orgId: authFields?.orgId }; |
233 | 199 | } catch (error) { |
234 | | - stager.stop(error as Error); |
235 | 200 | if (error instanceof SfError && error.name === 'ScratchOrgInfoTimeoutError') { |
| 201 | + this.spinner.stop(lastStatus); |
236 | 202 | const scratchOrgInfoId = (error.data as { scratchOrgInfoId: string }).scratchOrgInfoId; |
237 | 203 | const resumeMessage = messages.getMessage('action.resume', [this.config.bin, scratchOrgInfoId]); |
238 | 204 |
|
|
0 commit comments