@@ -15,19 +15,42 @@ function emit(key?: unknown, value?: unknown): [unknown, unknown] {
1515const __filename = fileURLToPath ( import . meta. url ) ;
1616const __dirname = dirname ( __filename ) ;
1717
18- // Load design documents with absolute paths
18+ // Dual resolution strategy for assets
19+ function getAssetPath ( assetName : string ) : string {
20+ // Strategy 1: Development mode - assets in parent directory
21+ const devModePath = join ( __dirname , '..' , 'assets' , assetName ) ;
22+ if ( fileSystem . existsSync ( devModePath ) ) {
23+ return devModePath ;
24+ }
25+
26+ // Strategy 2: Built module mode - assets in same directory
27+ const moduleModePath = join ( __dirname , 'assets' , assetName ) ;
28+ if ( fileSystem . existsSync ( moduleModePath ) ) {
29+ return moduleModePath ;
30+ }
31+
32+ // Fallback error with helpful context
33+ throw new Error (
34+ `Asset '${ assetName } ' not found. Tried:\n` +
35+ ` Dev mode: ${ devModePath } \n` +
36+ ` Module mode: ${ moduleModePath } \n` +
37+ ` Current __dirname: ${ __dirname } `
38+ ) ;
39+ }
40+
41+ // Load design documents with dual resolution
1942export const classroomDbDesignDoc = fileSystem . readFileSync (
20- join ( __dirname , 'assets' , 'classroomDesignDoc.js' ) ,
43+ getAssetPath ( 'classroomDesignDoc.js' ) ,
2144 'utf-8'
2245) ;
2346
2447export const courseDBDesignDoc = fileSystem . readFileSync (
25- join ( __dirname , 'assets' , 'get-tagsDesignDoc.json' ) ,
48+ getAssetPath ( 'get-tagsDesignDoc.json' ) ,
2649 'utf-8'
2750) ;
2851
2952export const courseValidateDocUpdate = fileSystem . readFileSync (
30- join ( __dirname , 'assets' , 'courseValidateDocUpdate.js' ) ,
53+ getAssetPath ( 'courseValidateDocUpdate.js' ) ,
3154 'utf-8'
3255) ;
3356
0 commit comments