Skip to content

Commit 83653d8

Browse files
committed
fix: ensure output directory exists before running generators
1 parent c6e8099 commit 83653d8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/generators.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import publicGenerators from './generators/index.mjs';
44
import astJs from './generators/ast-js/index.mjs';
55
import oramaDb from './generators/orama-db/index.mjs';
6+
import { mkdirSync, statSync } from 'node:fs';
67

78
const availableGenerators = {
89
...publicGenerators,
@@ -51,6 +52,17 @@ const createGenerator = markdownInput => {
5152
* @param {import('./generators/types.d.ts').GeneratorOptions} options The options for the generator runtime
5253
*/
5354
const runGenerators = async ({ generators, ...extra }) => {
55+
try {
56+
if (!statSync(extra.output).isDirectory()) {
57+
throw new Error('Output is not a directory');
58+
// console.log('Output is a directory')
59+
}
60+
} catch (err) {
61+
if (err.code === 'ENOENT') {
62+
mkdirSync(extra.output, { recursive: true });
63+
}
64+
}
65+
5466
// Note that this method is blocking, and will only execute one generator per-time
5567
// but it ensures all dependencies are resolved, and that multiple bottom-level generators
5668
// can reuse the already parsed content from the top-level/dependency generators

0 commit comments

Comments
 (0)