Skip to content

Commit

Permalink
fix: generation of exports on windows (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinderoubaix authored Dec 14, 2023
1 parent fd05f23 commit 00d8e12
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions scripts/generateExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const {existsSync, promises} = require('fs');
const {glob} = require('glob');
const os = require('os');

const pathRegExp = /\\/g;
const normalizePath = (str) => str.replace(pathRegExp, '/');

const parallel = Math.ceil(os.cpus().length / 2);

const worker = async (tasks, initialIndex) => {
Expand Down Expand Up @@ -44,26 +47,30 @@ const generateExports = async (destination, source, dependencyPkg) => {
};

// first we go through all files in the source source folder
const srcFiles = await glob(`**/*.{ts,tsx}`, {cwd: sourceFolder, ignore: ['components/**', '**/internal/**', '**/*.spec.ts', 'index.ts']});
const srcFiles = (
await glob(`{generated/**,services,services/transitions,utils,.}/*.{ts,tsx}`, {cwd: sourceFolder, ignore: ['**/*.spec.ts', 'index.ts']})
).map(normalizePath);
for (const srcFile of srcFiles) {
// removing a potential generated/ prefix, as the lib will go through the generated folder of the headless
const file = srcFile.startsWith('generated/') ? srcFile.substring(10) : srcFile;
await addGenerationFile(file);
}

// then we check if there is any override present in the destination source folder
const destFiles = await glob(`**/*.{ts,tsx}`, {
cwd: destFolder,
ignore: ['components/**', 'generated/**', '**/internal/**', '**/*.spec.ts', 'index.ts'],
});
const destFiles = (
await glob(`{services,services/transitions,utils,.}/*.{ts,tsx}`, {
cwd: destFolder,
ignore: ['**/*.spec.ts', 'index.ts'],
})
).map(normalizePath);
for (const destFile of destFiles) {
await addGenerationFile(destFile, true);
}

const generationInfos = [...generationMap.values()];
const tasks = generationInfos.map((generationInfo) => () => {
const path = join(generationFolder, generationInfo.import) + '.ts';
const importPrefix = generationInfo.isDest ? './' + relative(dirname(path), destFolder) : dependencyPkg;
const importPrefix = generationInfo.isDest ? './' + normalizePath(relative(dirname(path), destFolder)) : dependencyPkg;
return promises.writeFile(path, `export * from '${importPrefix}/${generationInfo.import}';`);
});
// final task, the index in the generation folder that will reference all the generated files
Expand Down

0 comments on commit 00d8e12

Please sign in to comment.