Skip to content

Commit

Permalink
fix: indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
PreziosiRaffaele committed Jan 30, 2024
1 parent 9ba3a5d commit 6525351
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sf-perms",
"description": "",
"version": "1.0.1",
"version": "1.0.2",
"dependencies": {
"@oclif/core": "^3.18.1",
"@salesforce/core": "^6.4.7",
Expand Down
18 changes: 10 additions & 8 deletions src/PermissionSetUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ interface PermissionSet {
}

export class PermissionSetUpdater {
private parserOptions = { ignoreAttributes: false };
private builderOptions = { ignoreAttributes: false, format: true };

private parser = new XMLParser(this.parserOptions);
private builder = new XMLBuilder(this.builderOptions);
private fs;

public constructor(fs: typeof fsPromises) {
Expand All @@ -35,7 +30,9 @@ export class PermissionSetUpdater {
): Promise<void> {
const completeFilePath: string = path.resolve(directoryPath, 'permissionsets', permissionSet);
const permissionSetXml: string = await this.fs.readFile(completeFilePath, 'utf8');
const permissionSetParsedJSON: PermissionSet = this.parser.parse(permissionSetXml) as PermissionSet;
const indentation: string = this.getIndentation(permissionSetXml);
const parser = new XMLParser({ ignoreAttributes: false });
const permissionSetParsedJSON: PermissionSet = parser.parse(permissionSetXml) as PermissionSet;

for (const field in fieldsPermissionSelected) {
if (Object.prototype.hasOwnProperty.call(fieldsPermissionSelected, field)) {
Expand All @@ -58,11 +55,16 @@ export class PermissionSetUpdater {
}
}
}

const xmlContent: string = this.builder.build(permissionSetParsedJSON) as string;
const builder = new XMLBuilder({ ignoreAttributes: false, format: true, indentBy: indentation });
const xmlContent: string = builder.build(permissionSetParsedJSON) as string;
await this.fs.writeFile(completeFilePath, xmlContent);
}

private getIndentation(permissionSetXml: string): string {
const match = permissionSetXml.match(/^( |\t)+/m);
return match ? match[0] : ' '; // Default to two spaces if no indentation is found
}

private insertRespectingSorting(fieldPermissions: FieldPermission[], newFieldPermission: FieldPermission): void {
let low = 0;
let high = fieldPermissions.length - 1;
Expand Down

0 comments on commit 6525351

Please sign in to comment.