Skip to content

Commit f832981

Browse files
committed
fix root detection
1 parent 305267c commit f832981

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/generate-md-exports.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

33
import {selectAll} from 'hast-util-select';
4+
import {existsSync} from 'node:fs';
45
import {mkdir, opendir, readFile, rm, writeFile} from 'node:fs/promises';
56
import * as path from 'node:path';
67
import rehypeParse from 'rehype-parse';
@@ -9,7 +10,14 @@ import remarkGfm from 'remark-gfm';
910
import remarkStringify from 'remark-stringify';
1011
import {unified} from 'unified';
1112

12-
const root = process.cwd(); // fix this
13+
let root = process.cwd();
14+
while (!existsSync(path.join(root, 'package.json'))) {
15+
const parent = path.dirname(root);
16+
if (parent === root) {
17+
throw new Error('Could not find package.json in parent directories');
18+
}
19+
root = parent;
20+
}
1321
const INPUT_DIR = path.join(root, '.next', 'server', 'app');
1422
const OUTPUT_DIR = path.join(root, 'public', 'md-exports');
1523

@@ -38,7 +46,7 @@ export const genMDFromHTML = async (source, target) => {
3846
};
3947

4048
async function main() {
41-
console.log('🚀 Starting markdown export generation...');
49+
console.log(`🚀 Starting markdown generation from: ${INPUT_DIR}`);
4250
console.log(`📁 Output directory: ${OUTPUT_DIR}`);
4351

4452
// Clear output directory

0 commit comments

Comments
 (0)