Skip to content

fix: ensure output directory exists before running generators #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/generators.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import publicGenerators from './generators/index.mjs';
import astJs from './generators/ast-js/index.mjs';
import oramaDb from './generators/orama-db/index.mjs';
import { mkdirSync, statSync } from 'node:fs';

const availableGenerators = {
...publicGenerators,
Expand Down Expand Up @@ -51,6 +52,16 @@ const createGenerator = markdownInput => {
* @param {import('./generators/types.d.ts').GeneratorOptions} options The options for the generator runtime
*/
const runGenerators = async ({ generators, ...extra }) => {
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do believe at the very least this code should live somewhere else, and not here.

if (!statSync(extra.output).isDirectory()) {
throw new Error('Output is not a directory');
}
} catch (err) {
if (err.code === 'ENOENT') {
mkdirSync(extra.output, { recursive: true });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think that the expected behavior would be to create a directory if it does not exist.

}
Copy link
Member

@avivkeller avivkeller Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
} else throw err;

We should probably not swallow the error in other cases

}

// Note that this method is blocking, and will only execute one generator per-time
// but it ensures all dependencies are resolved, and that multiple bottom-level generators
// can reuse the already parsed content from the top-level/dependency generators
Expand Down
Loading