UNPKG

ci-sf-plugin

Version:

Set of commands making CI and dev's life easier.

59 lines 2.81 kB
/* * Copyright (c) 2020, 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 * as os from 'os'; import * as util from 'util'; import * as childProcess from 'child_process'; import { requiredOrgFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core'; import { Messages, SfError } from '@salesforce/core'; import { ux } from '@oclif/core'; // promisify child process const execSync = util.promisify(childProcess.exec); // Initialize Messages with the current plugin directory Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); // Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, // or any library that is using the messages framework can also be loaded this way. const messages = Messages.loadMessages('ci-sf-plugin', 'org.delete'); export default class Delete extends SfCommand { static description = messages.getMessage('commandDescription'); static examples = messages.getMessage('examples').split(os.EOL); static flags = { 'target-org': requiredOrgFlagWithDeprecations // flag with a value (-n, --name=VALUE) }; // Set this to true if your command requires a project workspace; 'requiresProject' is false by default static requiresProject = false; async run() { try { const { flags } = await this.parse(Delete); // fetch needed flags const targetOrgUsername = flags['target-org'].getUsername(); ux.action.start(messages.getMessage('infoDeletingOrg', [targetOrgUsername]), 'in progress', { stdout: true }); // build the command, without --json to see details const commandStr = `sf org delete scratch --target-org ${targetOrgUsername} --no-prompt`; // execute and print output const commandPromise = execSync(commandStr, { encoding: 'utf8', maxBuffer: 1024 * 1024 }); commandPromise.child.stdout.on('data', (data) => { if (data?.trim()) { process.stdout.write(data); } }); commandPromise.child.stderr.on('data', (data) => { if (data?.trim()) { process.stderr.write(data.trim()); } }); const { stdout, stderr } = await commandPromise; ux.action.stop('done'); // Return an object return { stdout, stderr }; } catch (error) { ux.action.stop('failed'); throw new SfError(messages.getMessage('errorDeletingOrgFailed', [JSON.stringify(error, null, 2)])); } } } //# sourceMappingURL=delete.js.map