Skip to content

Commit

Permalink
[draft] Reuse buildrsc
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Sep 10, 2024
1 parent 15490e4 commit 6bf7e28
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions packages/rsc-builder/buildRsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,53 +106,57 @@ async function findAll(
return result.flat();
}

async function run(argv: yargs.ArgumentsCamelCase<CommandOptions>) {
const grep = argv.grep == null ? null : new RegExp(argv.grep);
// eslint-disable-next-line import/prefer-default-export
export async function resolveProject(project: Project, grep: RegExp | null) {
const projectSrc = path.join(project.rootPath, 'src');

await PROJECTS.reduce(async (resolvedPromise, project) => {
await resolvedPromise;
let directories = [projectSrc];

const projectSrc = path.join(project.rootPath, 'src');
if (Array.isArray(project?.additionalPaths)) {
directories = [
...directories,
...project.additionalPaths.map((p) => path.join(project.rootPath, p)),
];
}

let directories = [projectSrc];
const components = await findAll(directories, grep, findComponents);

if (Array.isArray(project?.additionalPaths)) {
directories = [
...directories,
...project.additionalPaths.map((p) => path.join(project.rootPath, p)),
];
components.forEach(async (component) => {
try {
if (!project.ignorePaths?.some((p) => component.filename.includes(p))) {
processFile(component.filename);
}
} catch (error: any) {
error.message = `${path.relative(process.cwd(), component.filename)}: ${error.message}`;
throw error;
}
});

const components = await findAll(directories, grep, findComponents);
const hooks = await findAll(directories, grep, findHooks);

components.forEach(async (component) => {
try {
if (!project.ignorePaths?.some((p) => component.filename.includes(p))) {
processFile(component.filename);
}
} catch (error: any) {
error.message = `${path.relative(process.cwd(), component.filename)}: ${error.message}`;
throw error;
}
});

const hooks = await findAll(directories, grep, findHooks);
hooks.forEach(async (hook) => {
try {
processFile(hook.filename);
} catch (error: any) {
error.message = `${path.relative(process.cwd(), hook.filename)}: ${error.message}`;
throw error;
}
});

hooks.forEach(async (hook) => {
try {
processFile(hook.filename);
} catch (error: any) {
error.message = `${path.relative(process.cwd(), hook.filename)}: ${error.message}`;
throw error;
}
if (Array.isArray(project?.additionalFiles)) {
project.additionalFiles.forEach(async (file) => {
const fullPath = path.join(project.rootPath, file);
processFile(fullPath);
});
}
}
async function run(argv: yargs.ArgumentsCamelCase<CommandOptions>) {
const grep = argv.grep == null ? null : new RegExp(argv.grep);

if (Array.isArray(project?.additionalFiles)) {
project.additionalFiles.forEach(async (file) => {
const fullPath = path.join(project.rootPath, file);
processFile(fullPath);
});
}
await PROJECTS.reduce(async (resolvedPromise, project) => {
await resolvedPromise;

await resolveProject(project, grep);

return Promise.resolve();
}, Promise.resolve());
Expand Down

0 comments on commit 6bf7e28

Please sign in to comment.