Skip to content

Commit 7ffe3c0

Browse files
committed
fix analytics datadir for nextjs
1 parent 82d64b4 commit 7ffe3c0

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

  • src/utilities/analytics/reference

src/utilities/analytics/reference/index.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ export class ReferenceLoader {
1313
private dataDir: string;
1414
private locale: string;
1515

16-
constructor(dataDir: string = path.join(__dirname, 'data'), locale: string = 'en') {
17-
this.dataDir = dataDir;
16+
constructor(dataDir?: string, locale: string = 'en') {
1817
this.locale = locale;
18+
19+
if (dataDir) {
20+
this.dataDir = dataDir;
21+
} else {
22+
// Resolve the data directory relative to this file's location
23+
// Use __dirname which works correctly after compilation
24+
this.dataDir = path.join(__dirname, 'data');
25+
}
1926
}
2027

2128
/**
@@ -126,3 +133,25 @@ export class ReferenceLoader {
126133
};
127134
}
128135
}
136+
137+
/**
138+
* Get the default reference data path
139+
*/
140+
export function getReferenceDataPath(): string {
141+
return path.join(__dirname, 'data');
142+
}
143+
144+
/**
145+
* Check if reference data files exist
146+
*/
147+
export function hasReferenceData(): boolean {
148+
const dataPath = getReferenceDataPath();
149+
const requiredFiles = [
150+
'core_lists.en.json',
151+
'common_words.en.json',
152+
'sentences.en.json',
153+
'synonyms.en.json',
154+
'fringe.en.json',
155+
];
156+
return requiredFiles.every((file) => fs.existsSync(path.join(dataPath, file)));
157+
}

0 commit comments

Comments
 (0)