1
1
import fs from "fs/promises" ;
2
2
import path from "path" ;
3
- const dirname : string = path . dirname ( new URL ( import . meta . url ) . pathname ) ;
3
+ import { fileURLToPath } from " url" ;
4
4
import yargs from "yargs" ;
5
5
import { hideBin } from "yargs/helpers" ;
6
6
import { connect } from "../db" ;
@@ -17,6 +17,8 @@ import {
17
17
} from "../models" ;
18
18
import { RecurrenceRule } from "../models/RecurrenceRule" ;
19
19
20
+ const dirname : string = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
21
+
20
22
interface InterfaceArgs {
21
23
items ?: string ;
22
24
format ?: boolean ;
@@ -26,9 +28,9 @@ interface InterfaceArgs {
26
28
/**
27
29
* Lists sample data files and their document counts in the sample_data directory.
28
30
*/
29
- async function listSampleData ( ) : Promise < void > {
31
+ export async function listSampleData ( ) : Promise < void > {
30
32
try {
31
- const sampleDataPath = path . join ( dirname , "../../sample_data" ) ;
33
+ const sampleDataPath = path . resolve ( dirname , "../../sample_data" ) ;
32
34
const files = await fs . readdir ( sampleDataPath ) ;
33
35
34
36
console . log ( "Sample Data Files:\n" ) ;
@@ -41,7 +43,7 @@ async function listSampleData(): Promise<void> {
41
43
) ;
42
44
43
45
for ( const file of files ) {
44
- const filePath = path . join ( sampleDataPath , file ) ;
46
+ const filePath = path . resolve ( sampleDataPath , file ) ;
45
47
const stats = await fs . stat ( filePath ) ;
46
48
if ( stats . isFile ( ) ) {
47
49
const data = await fs . readFile ( filePath , "utf8" ) ;
@@ -110,7 +112,7 @@ async function insertCollections(collections: string[]): Promise<void> {
110
112
// Insert data into each specified collection
111
113
for ( const collection of collections ) {
112
114
const data = await fs . readFile (
113
- path . join ( dirname , `../../sample_data/${ collection } .json` ) ,
115
+ path . resolve ( dirname , `../../sample_data/${ collection } .json` ) ,
114
116
"utf8" ,
115
117
) ;
116
118
const docs = JSON . parse ( data ) as Record < string , unknown > [ ] ;
0 commit comments