UNPKG

@salesforce/plugin-org

Version:

Commands to interact with Salesforce orgs

65 lines 2.92 kB
/* * Copyright (c) 2021, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import { AuthInfo, AuthRemover, Messages, Org } from '@salesforce/core'; import { Flags, SfCommand } from '@salesforce/sf-plugins-core'; import { ensureString } from '@salesforce/ts-types'; import { orgThatMightBeDeleted } from '../../../shared/flags.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-org', 'delete_scratch'); export default class DeleteScratch extends SfCommand { static summary = messages.getMessage('summary'); static description = messages.getMessage('description'); static examples = messages.getMessages('examples'); static aliases = ['env:delete:scratch']; static deprecateAliases = true; static flags = { 'target-org': orgThatMightBeDeleted({ summary: messages.getMessage('flags.target-org.summary'), required: true, }), 'no-prompt': Flags.boolean({ char: 'p', summary: messages.getMessage('flags.no-prompt.summary'), }), }; async run() { const flags = (await this.parse(DeleteScratch)).flags; const resolvedUsername = flags['target-org']; const { orgId, isScratch } = (await AuthInfo.create({ username: resolvedUsername })).getFields(); if (!isScratch) { throw messages.createError('error.unknownScratch', [resolvedUsername]); } if (flags['no-prompt'] || (await this.confirm({ message: messages.getMessage('prompt.confirm', [resolvedUsername]) }))) { try { const org = await Org.create({ aliasOrUsername: resolvedUsername }); await org.delete(); return { username: org.getUsername(), orgId: org.getOrgId() }; } catch (e) { if (e instanceof Error && e.name === 'DomainNotFoundError') { // the org has expired, so remote operations won't work // let's clean up the files locally const authRemover = await AuthRemover.create(); await authRemover.removeAuth(resolvedUsername); this.logSuccess(messages.getMessage('success', [resolvedUsername])); } else if (e instanceof Error && e.name === 'ScratchOrgNotFound') { this.logSuccess(messages.getMessage('success.Idempotent', [resolvedUsername])); } else { throw e; } } } return { username: resolvedUsername, orgId: ensureString(orgId), }; } } //# sourceMappingURL=scratch.js.map