Closed nabondance closed 10 months ago
Maybe the "official" way would be to parse sfdx-project.json
and read the different path
under packageDirectories
to find all possible project paths.
Would that work for you ?
I need to have a look but maybe there is something doing that in SfProjectJson
from @salesforce/core
.
Maybe the "official" way would be to parse
sfdx-project.json
and read the differentpath
underpackageDirectories
to find all possible project paths. Would that work for you ? I need to have a look but maybe there is something doing that inSfProjectJson
from@salesforce/core
.
indeed it can be done this way too, it should solve the issue
I thought about it some more and that's my outputs:
/my-package
for exemple), the objects folder can be anywhere in it:
/my-package/main/objects
/my-package/force-app/main/objects
/my-package/objects
/my-package/anything/somethingelse/objects
The solution can be to use both:
unrestrict.ts
// Get packages paths
const packagesPaths: string[] = getPackagesPaths(); // command to find/develop
// Get all the objects folder paths inside the package ones
for (const recType of findObjectsFolders(packagesPaths, EXCLUDED_DIRS)) {
objectsFolderPaths.push(recType);
}
sfdxProjectFolder.ts
export function findObjectsFolders(startPaths: string[], excludedDirs: string[] = []): string[] {
const result: string[] = [];
for (const iPath of startPaths) { // the new loop on the new startPaths parameter
const filesAndDirs = fs.readdirSync(startPath);
for (const fileOrDir of filesAndDirs) {
const fullPath = path.join(startPath, fileOrDir);
if (fs.statSync(fullPath).isDirectory()) {
// If the directory is in the exclusion list, skip it.
if (excludedDirs.includes(fileOrDir)) {
continue;
}
if (fileOrDir === 'objects') {
result.push(fullPath);
}
result.push(...findObjectsFolders(fullPath, excludedDirs));
}
}
}
return result;
}
I updated the PR to add the use of SfProject
export async function getPackagesPaths(): Promise<string[]> {
try {
const project: SfProject = await SfProject.resolve();
const packageDirectories: NamedPackageDir[] = project.getPackageDirectories();
return packageDirectories.map((dir) => dir.path);
} catch (error) {
/* eslint-disable no-console */
console.error('Error retrieving package paths: ', error);
return [];
}
}
Thank you !
Proposal to fix the issue https://github.com/texei/texei-sfdx-plugin/issues/134