diff --git a/package.json b/package.json index e78621a..05fe01e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "texei-sfdx-plugin", "description": "Texeï's plugin for sfdx", - "version": "2.2.2", + "version": "2.2.3", "author": "Texeï", "bugs": "https://github.com/texei/texei-sfdx-plugin/issues", "dependencies": { diff --git a/src/commands/texei/skinnyprofile/check.ts b/src/commands/texei/skinnyprofile/check.ts index 4293465..55905a7 100644 --- a/src/commands/texei/skinnyprofile/check.ts +++ b/src/commands/texei/skinnyprofile/check.ts @@ -40,58 +40,65 @@ export default class Check extends SfCommand { let commandResult = ''; // Get profiles files path + let profileDirPath = ''; if (flags.path) { // A path was provided with the flag - profilesToCheck = getProfilesInPath(flags.path, true); + profileDirPath = flags.path; } else { // Else look in the default package directory - const defaultPackageDirectory = path.join(await getDefaultPackagePath(), 'profiles'); - profilesToCheck = getProfilesInPath(defaultPackageDirectory, true); + profileDirPath = path.join(await getDefaultPackagePath(), 'profiles'); } - if (profilesToCheck === undefined || profilesToCheck.length === 0) { - commandResult = 'No Profile found'; - } else { - for (const profilePath of profilesToCheck) { - // Generate path - const filePath = path.join(process.cwd(), profilePath); - - // Read data file - const data = fs.readFileSync(filePath, 'utf8'); - - // Parsing file - // TODO: refactor to avoid await in loop ? Not sure we want all metadata in memory - // eslint-disable-next-line - const profileJson: ProfileMetadataType = (await xml2js.parseStringPromise(data)) as ProfileMetadataType; - - // Looking for unwanted nodes - for (const [key, value] of Object.entries(profileJson?.Profile)) { - this.debug('key:'); - this.debug(key); - this.debug('value:'); - this.debug(value); - - if (Object.prototype.hasOwnProperty.call(profileJson.Profile, key)) { - if (nodesNotAllowed.includes(key)) { - // Could definitely be improved - if (!invalidProfiles.includes(profilePath)) { - invalidProfiles.push(profilePath); + if (fs.existsSync(profileDirPath)) { + // There is a profiles folder + profilesToCheck = getProfilesInPath(profileDirPath, true); + + if (profilesToCheck === undefined || profilesToCheck.length === 0) { + commandResult = 'No Profile found'; + } else { + for (const profilePath of profilesToCheck) { + // Generate path + const filePath = path.join(process.cwd(), profilePath); + + // Read data file + const data = fs.readFileSync(filePath, 'utf8'); + + // Parsing file + // TODO: refactor to avoid await in loop ? Not sure we want all metadata in memory + // eslint-disable-next-line + const profileJson: ProfileMetadataType = (await xml2js.parseStringPromise(data)) as ProfileMetadataType; + + // Looking for unwanted nodes + for (const [key, value] of Object.entries(profileJson?.Profile)) { + this.debug('key:'); + this.debug(key); + this.debug('value:'); + this.debug(value); + + if (Object.prototype.hasOwnProperty.call(profileJson.Profile, key)) { + if (nodesNotAllowed.includes(key)) { + // Could definitely be improved + if (!invalidProfiles.includes(profilePath)) { + invalidProfiles.push(profilePath); + } + break; } - break; } } } } - } - if (invalidProfiles.length === 0) { - commandResult = 'All Profiles valid'; + if (invalidProfiles.length === 0) { + commandResult = 'All Profiles valid'; + } else { + throw new SfError( + `Invalid Profile${invalidProfiles.length > 1 ? 's' : ''} found: ${invalidProfiles.join( + ', ' + )}. Please run sf texei skinnyprofile retrieve` + ); + } } else { - throw new SfError( - `Invalid Profile${invalidProfiles.length > 1 ? 's' : ''} found: ${invalidProfiles.join( - ', ' - )}. Please run sfdx texei:skinnyprofile:retrieve` - ); + commandResult = 'No profiles folder found'; } this.log(commandResult);