generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 18
/
clear.ts
54 lines (47 loc) · 1.87 KB
/
clear.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* 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 { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import * as chalk from 'chalk';
import { SourceTracking, throwIfInvalid } from '@salesforce/source-tracking';
Messages.importMessagesDirectory(__dirname);
const messages: Messages = Messages.loadMessages('@salesforce/plugin-source', 'tracking');
export type SourceTrackingClearResult = {
clearedFiles: string[];
};
export class Clear extends SfdxCommand {
public static readonly description = messages.getMessage('clearDescription');
public static aliases = ['force:source:beta:tracking:clear'];
public static readonly requiresProject = true;
public static readonly requiresUsername = true;
public static readonly flagsConfig: FlagsConfig = {
noprompt: flags.boolean({
char: 'p',
description: messages.getMessage('nopromptDescription'),
required: false,
}),
};
public async run(): Promise<SourceTrackingClearResult> {
throwIfInvalid({
org: this.org,
projectPath: this.project.getPath(),
toValidate: 'plugin-source',
command: 'force:source:tracking:clear',
});
let clearedFiles: string[] = [];
if (this.flags.noprompt || (await this.ux.confirm(chalk.dim(messages.getMessage('promptMessage'))))) {
const sourceTracking = await SourceTracking.create({
project: this.project,
org: this.org,
apiVersion: this.flags.apiversion as string,
});
clearedFiles = await Promise.all([sourceTracking.clearLocalTracking(), sourceTracking.clearRemoteTracking()]);
this.ux.log('Cleared local tracking files.');
}
return { clearedFiles };
}
}