generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 18
/
reset.ts
75 lines (63 loc) · 2.3 KB
/
reset.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* 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 SourceTrackingResetResult = {
sourceMembersSynced: number;
localPathsSynced: number;
};
export class Reset extends SfdxCommand {
public static readonly description = messages.getMessage('resetDescription');
public static aliases = ['force:source:beta:tracking:reset'];
public static readonly requiresProject = true;
public static readonly requiresUsername = true;
public static readonly flagsConfig: FlagsConfig = {
revision: flags.integer({
char: 'r',
description: messages.getMessage('revisionDescription'),
min: 0,
}),
noprompt: flags.boolean({
char: 'p',
description: messages.getMessage('nopromptDescription'),
}),
};
public async run(): Promise<SourceTrackingResetResult> {
throwIfInvalid({
org: this.org,
projectPath: this.project.getPath(),
toValidate: 'plugin-source',
command: 'force:source:tracking:clear',
});
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,
});
const [remoteResets, localResets] = await Promise.all([
sourceTracking.resetRemoteTracking(this.flags.revision as number),
sourceTracking.resetLocalTracking(),
]);
this.ux.log(
`Reset local tracking files${this.flags.revision ? ` to revision ${this.flags.revision as number}` : ''}.`
);
return {
sourceMembersSynced: remoteResets,
localPathsSynced: localResets.length,
};
}
return {
sourceMembersSynced: 0,
localPathsSynced: 0,
};
}
}