generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 18
/
status.ts
116 lines (104 loc) · 3.82 KB
/
status.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* 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 { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { ChangeResult, StatusOutputRow } from '@salesforce/source-tracking';
import { StatusFormatter, StatusResult } from '../../../formatters/source/statusFormatter';
import { trackingSetup } from '../../../trackingFunctions';
Messages.importMessagesDirectory(__dirname);
const messages: Messages = Messages.loadMessages('@salesforce/plugin-source', 'status');
export default class Status extends SfdxCommand {
public static description = messages.getMessage('description');
public static aliases = ['force:source:beta:status'];
public static readonly examples = messages.getMessage('examples').split(os.EOL);
protected static flagsConfig: FlagsConfig = {
local: flags.boolean({
char: 'l',
description: messages.getMessage('flags.local'),
longDescription: messages.getMessage('flags.localLong'),
exclusive: ['remote'],
}),
remote: flags.boolean({
char: 'r',
description: messages.getMessage('flags.remote'),
longDescription: messages.getMessage('flags.remoteLong'),
exclusive: ['local'],
}),
concise: flags.builtin({
description: messages.getMessage('flags.concise'),
}),
};
protected static requiresUsername = true;
protected static requiresProject = true;
protected results = new Array<StatusResult>();
protected localAdds: ChangeResult[] = [];
public async run(): Promise<StatusResult[]> {
const wantsLocal = (this.flags.local as boolean) || (!this.flags.remote && !this.flags.local);
const wantsRemote = (this.flags.remote as boolean) || (!this.flags.remote && !this.flags.local);
this.logger.debug(
`project is ${this.project.getPath()} and pkgDirs are ${this.project
.getPackageDirectories()
.map((dir) => dir.path)
.join(',')}`
);
const tracking = await trackingSetup({
commandName: 'force:source:status',
ignoreConflicts: true,
org: this.org,
project: this.project,
ux: this.ux,
apiVersion: this.flags.apiversion as string,
});
const stlStatusResult = await tracking.getStatus({ local: wantsLocal, remote: wantsRemote });
this.results = stlStatusResult.map((result) => resultConverter(result));
return this.formatResult();
}
protected formatResult(): StatusResult[] {
const formatter = new StatusFormatter(
this.logger,
this.ux,
{ concise: this.flags.concise as boolean },
this.results
);
if (!this.flags.json) {
formatter.display();
}
return formatter.getJson();
}
}
/**
* STL provides a more useful json output.
* This function makes it consistent with the Status command's json.
*/
const resultConverter = (input: StatusOutputRow): StatusResult => {
const { fullName, type, ignored, filePath, conflict } = input;
const origin = originMap.get(input.origin);
const actualState = stateMap.get(input.state);
return {
fullName,
type,
// this string became the place to store information.
// The JSON now breaks out that info but preserves this property for backward compatibility
state: `${origin} ${actualState}${conflict ? ' (Conflict)' : ''}`,
ignored,
filePath,
origin,
actualState,
conflict,
};
};
const originMap = new Map<StatusOutputRow['origin'], StatusResult['origin']>([
['local', 'Local'],
['remote', 'Remote'],
]);
const stateMap = new Map<StatusOutputRow['state'], StatusResult['actualState']>([
['delete', 'Deleted'],
['add', 'Add'],
['modify', 'Changed'],
['nondelete', 'Changed'],
]);