-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate-api.ts
69 lines (60 loc) · 2.06 KB
/
update-api.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
import * as fs from 'node:fs';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { updateAPIVersion } from '../../utils/xmlParser.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('kc-sf-plugin', 'kc.update-api');
export type KcUpdateApiResult = {
updatedNumber: number;
};
export default class KcUpdateApi extends SfCommand<KcUpdateApiResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly flags = {
'target-dir': Flags.directory({
summary: messages.getMessage('flags.target-dir.summary'),
char: 'd',
exists: true,
default: 'force-app/main/default',
}),
type: Flags.option({
summary: messages.getMessage('flags.type.summary'),
char: 't',
required: true,
multiple: true,
options: ['classes', 'triggers', 'flows'] as string[],
})(),
'api-version': Flags.orgApiVersion({
summary: messages.getMessage('flags.api-version.summary'),
char: 'v',
required: true,
}),
};
public async run(): Promise<KcUpdateApiResult> {
const { flags } = await this.parse(KcUpdateApi);
let updatedNumber = 0;
const targetDir = flags['target-dir'];
if (!fs.existsSync(targetDir)) {
this.warn(targetDir + ' does not exist');
return {
updatedNumber,
};
}
const apiVersion = flags['api-version'];
// multiple types can be specified, so loop through all of them
flags['type'].forEach((type) => {
const componentDir = targetDir.concat('/' + type.toString());
if (!fs.existsSync(componentDir)) {
this.warn(componentDir + ' does not exist');
return {
updatedNumber,
};
}
updatedNumber = updatedNumber + updateAPIVersion(componentDir, apiVersion);
});
return {
updatedNumber,
};
}
}