This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathretrieve.ts
More file actions
128 lines (112 loc) · 4.65 KB
/
Copy pathretrieve.ts
File metadata and controls
128 lines (112 loc) · 4.65 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
import { Messages, Org } from '@salesforce/core';
import * as fs from 'fs-extra';
import { isNil } from 'lodash';
import { Sfpowerkit } from '@dxatscale/sfprofiles/lib/utils/sfpowerkit';
import ProfileSync from '@dxatscale/sfprofiles/lib/impl/source/profileSync';
import SfpowerscriptsCommand from '../../SfpowerscriptsCommand';
import Table from 'cli-table';
import { ZERO_BORDER_TABLE } from '../../ui/TableConstants';
import { arrayFlagSfdxStyle, loglevel, orgApiVersionFlagSfdxStyle, requiredUserNameFlag } from '../../flags/sfdxflags';
import { Flags } from '@oclif/core';
import SFPLogger, { COLOR_KEY_MESSAGE, COLOR_WARNING, LoggerLevel } from '@dxatscale/sfp-logger';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@dxatscale/sfpowerscripts', 'profile_retrieve');
export default class Retrieve extends SfpowerscriptsCommand {
public static description = messages.getMessage('commandDescription');
public static examples = [
`$ sfp profile:retrieve -u prod`,
`$ sfp profile:retrieve -f force-app -n "My Profile" -u prod`,
`$ sfp profile:retrieve -f "module1, module2, module3" -n "My Profile1, My profile2" -u prod`,
];
public static flags = {
folder: arrayFlagSfdxStyle({
char: 'f',
description: messages.getMessage('folderFlagDescription'),
required: false,
}),
profilelist: arrayFlagSfdxStyle({
char: 'n',
description: messages.getMessage('profileListFlagDescription'),
required: false,
}),
delete: Flags.boolean({
char: 'd',
description: messages.getMessage('deleteFlagDescription'),
required: false,
}),
targetorg: requiredUserNameFlag,
'apiversion': orgApiVersionFlagSfdxStyle,
loglevel,
};
// Comment this out if your command does not require an org username
protected static requiresUsername = true;
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
protected static requiresProject = true;
public async execute(): Promise<any> {
let argFolder: string = this.flags.folder;
let argProfileList: string[] = this.flags.profilelist;
let folders: string[] = [];
if (!isNil(argFolder) && argFolder.length !== 0) {
for (let dir of argFolder) {
if (!fs.existsSync(dir)) {
throw new Error(`The profile path ${dir} does not exist.`);
}
}
folders.push(...argFolder);
}
Sfpowerkit.initCache(true);
SFPLogger.log(COLOR_WARNING(messages.getMessage('retriveDelayWarning')),LoggerLevel.INFO);
SFPLogger.log(COLOR_KEY_MESSAGE(`Retrieving profiles from ${this.flags.targetorg}`),LoggerLevel.INFO );
this.org = await Org.create({ aliasOrUsername: this.flags.targetorg });
const profileUtils = new ProfileSync(this.org);
let syncProfiles = await profileUtils.sync(folders, argProfileList || [], this.flags.delete);
const table = new Table({
head: ['State', 'Full Name', 'Type', 'Path'],
chars: ZERO_BORDER_TABLE,
});
if (syncProfiles.added) {
syncProfiles.added.forEach((profile) => {
table.push({
state: 'Add',
fullName: profile.name,
type: 'Profile',
path: profile.path,
});
});
}
if (syncProfiles.updated) {
syncProfiles.updated.forEach((profile) => {
table.push({
state: 'Updated',
fullName: profile.name,
type: 'Profile',
path: profile.path,
});
});
}
if (this.flags.delete) {
if (syncProfiles.deleted) {
syncProfiles.deleted.forEach((profile) => {
table.push({
state: 'Deleted',
fullName: profile.name,
type: 'Profile',
path: profile.path,
});
});
}
} else {
if (syncProfiles.deleted) {
syncProfiles.deleted.forEach((profile) => {
table.push({
state: 'Skipped',
fullName: profile.name,
type: 'Profile',
path: profile.path,
});
});
}
}
return syncProfiles;
}
}