texei / texei-sfdx-plugin

Texeï's plugin for sfdx
https://texei.github.io/texei-sfdx-plugin/
BSD 3-Clause "New" or "Revised" License
122 stars 37 forks source link

picklist:unrestrict handle every objects paths #137

Closed nabondance closed 10 months ago

nabondance commented 1 year ago

Proposal to fix the issue https://github.com/texei/texei-sfdx-plugin/issues/134

FabienTaillon commented 1 year 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.

nabondance commented 1 year 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.

indeed it can be done this way too, it should solve the issue

nabondance commented 1 year ago

I thought about it some more and that's my outputs:

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;
}
nabondance commented 1 year ago

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 [];
  }
}
FabienTaillon commented 10 months ago

Thank you !