salesforce-alm
Version:
This package contains tools, and APIs, for an improved salesforce.com developer experience.
97 lines (95 loc) • 4.03 kB
JavaScript
;
/*
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SourceTrackingClearCommand = void 0;
const chalk_1 = require("chalk");
const command_1 = require("@salesforce/command");
const core_1 = require("@salesforce/core");
const source_tracking_1 = require("@salesforce/source-tracking");
const remoteSourceTrackingService_1 = require("../../../../lib/source/remoteSourceTrackingService");
const workspace_1 = require("../../../../lib/source/workspace");
const Org = require('../../../../lib/core/scratchOrgApi');
core_1.Messages.importMessagesDirectory(__dirname);
const messages = core_1.Messages.loadMessages('salesforce-alm', 'source_tracking');
// ConfigFile reads the file on init. We don't want to read the file, just delete it.
class OnlyDeletableMaxRevision extends remoteSourceTrackingService_1.RemoteSourceTrackingService {
// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
async read(throwOnNotFound, force) {
return {};
}
// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
async write(newContents) {
return {};
}
}
// ConfigFile reads the file on init. We don't want to read the file, just delete it.
class OnlyDeletableWorkspace extends workspace_1.Workspace {
// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
async read(throwOnNotFound, force) {
return {};
}
// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
async write(newContents) {
return {};
}
}
class SourceTrackingClearCommand extends command_1.SfdxCommand {
async run() {
const clearedFiles = [];
source_tracking_1.throwIfInvalid({
org: this.org,
projectPath: this.project.getPath(),
toValidate: 'toolbelt',
command: source_tracking_1.replaceRenamedCommands('force:source:tracking:clear'),
});
if (!this.flags.noprompt) {
const answer = await this.ux.prompt(chalk_1.default.dim(messages.getMessage('promptMessage')));
if (answer.toLowerCase() !== 'y') {
// Nothing cleared because it was canceled.
return { clearedFiles };
}
}
// TODO Remove legacy org from source path status manager and workspace.
const legacyOrg = new Org();
const username = this.org.getUsername();
legacyOrg.setName(username);
const revision = await OnlyDeletableMaxRevision.create({ username });
try {
await revision.unlink();
clearedFiles.push(revision.getPath());
// eslint-disable-next-line no-empty
}
catch (e) { }
// // Reset sourcePathInfos locally
const workspace = await OnlyDeletableWorkspace.create({
org: legacyOrg,
forceIgnore: null,
isStateless: true,
});
try {
await workspace.unlink();
clearedFiles.push(workspace.getPath());
// eslint-disable-next-line no-empty
}
catch (e) { }
this.ux.log('Cleared local tracking files.');
return { clearedFiles };
}
}
exports.SourceTrackingClearCommand = SourceTrackingClearCommand;
SourceTrackingClearCommand.description = messages.getMessage('clearDescription');
SourceTrackingClearCommand.requiresProject = true;
SourceTrackingClearCommand.requiresUsername = true;
SourceTrackingClearCommand.flagsConfig = {
noprompt: command_1.flags.boolean({
char: 'p',
description: messages.getMessage('nopromptDescription'),
required: false,
}),
};
//# sourceMappingURL=clear.js.map