diff --git a/README.md b/README.md index 8ae555f..bbc7b51 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ EXAMPLE Data exported! ``` -_See code: [src/commands/texei/data/export.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/data/export.ts)_ +_See code: [src/commands/texei/data/export.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/data/export.ts)_ ## `sfdx texei:data:import -d [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -97,7 +97,7 @@ EXAMPLE Data imported! ``` -_See code: [src/commands/texei/data/import.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/data/import.ts)_ +_See code: [src/commands/texei/data/import.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/data/import.ts)_ ## `sfdx texei:data:plan:generate -d -o [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -124,7 +124,7 @@ EXAMPLE $ sfdx texei:data:plan:generate --objects Account,Contact,MyCustomObject__c --outputdir ./data ``` -_See code: [src/commands/texei/data/plan/generate.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/data/plan/generate.ts)_ +_See code: [src/commands/texei/data/plan/generate.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/data/plan/generate.ts)_ ## `sfdx texei:org:contractfieldhistory:fix [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -152,7 +152,7 @@ EXAMPLE History tracking fixed. ``` -_See code: [src/commands/texei/org/contractfieldhistory/fix.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/org/contractfieldhistory/fix.ts)_ +_See code: [src/commands/texei/org/contractfieldhistory/fix.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/org/contractfieldhistory/fix.ts)_ ## `sfdx texei:org:shape:extract [-d ] [-s ] [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -187,7 +187,7 @@ EXAMPLE $ sfdx texei:org:shape:extract -u bulma@capsulecorp.com" ``` -_See code: [src/commands/texei/org/shape/extract.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/org/shape/extract.ts)_ +_See code: [src/commands/texei/org/shape/extract.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/org/shape/extract.ts)_ ## `sfdx texei:package:dependencies:install [-k ] [-b ] [-p ] [-s ] [-n ] [-w ] [-r] [-v ] [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -245,7 +245,7 @@ EXAMPLE $ texei:package:dependencies:install -u MyScratchOrg -v MyDevHub -k "1:MyPackage1Key 2: 3:MyPackage3Key" -b "DEV" ``` -_See code: [src/commands/texei/package/dependencies/install.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/package/dependencies/install.ts)_ +_See code: [src/commands/texei/package/dependencies/install.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/package/dependencies/install.ts)_ ## `sfdx texei:profile:clean [-k ] [-p ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -279,7 +279,7 @@ EXAMPLES custom-sfdx-source-folder/main/profiles,source-folder-2/main/profiles/myAdmin.profile-meta.xml ``` -_See code: [src/commands/texei/profile/clean.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/profile/clean.ts)_ +_See code: [src/commands/texei/profile/clean.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/profile/clean.ts)_ ## `sfdx texei:skinnyprofile:retrieve [-t ] [-v ] [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -312,7 +312,7 @@ EXAMPLE $ texei:skinnyprofile:retrieve -u MyScratchOrg ``` -_See code: [src/commands/texei/skinnyprofile/retrieve.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/skinnyprofile/retrieve.ts)_ +_See code: [src/commands/texei/skinnyprofile/retrieve.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/skinnyprofile/retrieve.ts)_ ## `sfdx texei:source:customlabel:replace -l -v [-p ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -336,7 +336,7 @@ EXAMPLE $ texei:source:customlabel:replace --label GreatSalesforceBlog --value https://blog.texei.com ``` -_See code: [src/commands/texei/source/customlabel/replace.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/source/customlabel/replace.ts)_ +_See code: [src/commands/texei/source/customlabel/replace.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/source/customlabel/replace.ts)_ ## `sfdx texei:source:layouts:cleanorg [-p ] [-v ] [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -369,7 +369,7 @@ EXAMPLES $ texei:source:layouts:cleanorg --targetusername myScratchOrg --targetdevhubusername myDevHub ``` -_See code: [src/commands/texei/source/layouts/cleanorg.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/source/layouts/cleanorg.ts)_ +_See code: [src/commands/texei/source/layouts/cleanorg.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/source/layouts/cleanorg.ts)_ ## `sfdx texei:user:update [-v ] [-u ] [--apiversion ] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]` @@ -401,5 +401,5 @@ EXAMPLES $ sfdx texei:user:update --values "UserPermissionsKnowledgeUser=true" --json ``` -_See code: [src/commands/texei/user/update.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.0/src/commands/texei/user/update.ts)_ +_See code: [src/commands/texei/user/update.ts](https://github.com/texei/texei-sfdx-plugin/blob/v1.4.1/src/commands/texei/user/update.ts)_ diff --git a/package.json b/package.json index 8130454..43845b6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "texei-sfdx-plugin", "description": "Texeï's plugin for sfdx", - "version": "1.4.0", + "version": "1.4.1", "author": "Texeï", "bugs": "https://github.com/https://github.com/texei/texei-sfdx-plugin/issues", "dependencies": { diff --git a/src/commands/texei/source/layouts/cleanorg.ts b/src/commands/texei/source/layouts/cleanorg.ts index 4ccd3e7..f1870eb 100644 --- a/src/commands/texei/source/layouts/cleanorg.ts +++ b/src/commands/texei/source/layouts/cleanorg.ts @@ -59,56 +59,70 @@ export default class CleanOrg extends SfdxCommand { // Read files const readDir = util.promisify(fs.readdir); - let layoutsFiles = await readDir(filesPath, "utf8"); - // Don't know why metadata API retrieved & as %26 whereas other characters are ok. Hardcoding for now (booo) - layoutsFiles = layoutsFiles.map(x => x.replace('.layout-meta.xml','').replace('%26','&').replace('%27','\'')); - - // Only look at standard objects - let standardObjects:Set = new Set(layoutsFiles.map(x => { - const obj = x.split('-')[0]; - if (!obj.includes('__')) { - // Should be enough to know if it's a standard object - return obj; + let layoutsFiles = await readDir(filesPath, "utf8").catch(err => { + if (err.code === 'ENOENT') { + const noent = 'No layouts folder found'; + this.ux.log(noent); + deletedLayouts.push(noent); } - })); - standardObjects.delete(undefined); - - // Query the org to get layouts for these standard objects - const conn = this.org.getConnection(); - const objectList:string = `'${Array.from(standardObjects).join().replace(/,/gi,'\',\'')}'`; - const query = `Select TableEnumOrId, Name from Layout where TableEnumOrId IN (${objectList}) order by TableEnumOrId`; - const results = await conn.tooling.query(query) as any; - - let layoutsOnOrg:Set = new Set(); - for (const layout of results.records) { - layoutsOnOrg.add(`${layout.TableEnumOrId}-${layout.Name}`); - } - - const layoutsToDelete:string[] = Array.from(layoutsOnOrg).filter(lay => layoutsFiles.includes(lay) ? undefined : lay) as string[]; - - if (layoutsToDelete.length > 0) { - - // TODO: log after delete, once errors are handled correctly - this.ux.log(`Deleting layouts:`); - for (const lay of layoutsToDelete) { - this.ux.log(lay); + else { + this.ux.error(err); } + }); - // Use metadata API so that this won't be visible in force:source:status - // This call is limited to 10 records, splitting (maybe refactor later to use destructiveChanges.xml) - let promises: Array> = new Array>(); + if (layoutsFiles) { + + // Don't know why metadata API retrieved & as %26 whereas other characters are ok. Hardcoding for now (booo) + layoutsFiles = layoutsFiles.map(x => x.replace('.layout-meta.xml','').replace('%26','&').replace('%27','\'')); - while(layoutsToDelete.length) { - promises.push(conn.metadata.delete('Layout', layoutsToDelete.splice(0,10))); + // Only look at standard objects + let standardObjects:Set = new Set(layoutsFiles.map(x => { + const obj = x.split('-')[0]; + if (!obj.includes('__')) { + // Should be enough to know if it's a standard object + return obj; + } + })); + standardObjects.delete(undefined); + + // Query the org to get layouts for these standard objects + const conn = this.org.getConnection(); + const objectList:string = `'${Array.from(standardObjects).join().replace(/,/gi,'\',\'')}'`; + const query = `Select TableEnumOrId, Name from Layout where TableEnumOrId IN (${objectList}) order by TableEnumOrId`; + const results = await conn.tooling.query(query) as any; + + let layoutsOnOrg:Set = new Set(); + for (const layout of results.records) { + layoutsOnOrg.add(`${layout.TableEnumOrId}-${layout.Name}`); + } + + const layoutsToDelete:string[] = Array.from(layoutsOnOrg).filter(lay => layoutsFiles.includes(lay) ? undefined : lay) as string[]; + + if (layoutsToDelete.length > 0) { + + // TODO: log after delete, once errors are handled correctly + this.ux.log(`Deleting layouts:`); + for (const lay of layoutsToDelete) { + this.ux.log(lay); + deletedLayouts.push(lay); + } + + // Use metadata API so that this won't be visible in force:source:status + // This call is limited to 10 records, splitting (maybe refactor later to use destructiveChanges.xml) + let promises: Array> = new Array>(); + + while(layoutsToDelete.length) { + promises.push(conn.metadata.delete('Layout', layoutsToDelete.splice(0,10))); + } + + // TODO: handle errors correctly + await Promise.all(promises); + } + else { + this.ux.log(`Nothing to delete.`); } - - // TODO: handle errors correctly - await Promise.all(promises); - } - else { - this.ux.log(`Nothing to delete.`); } - + return { deleted: deletedLayouts }; } } \ No newline at end of file