@@ -5,10 +5,11 @@ const { join } = require('path')
55const { initializeStore } = require ( '../store' )
66const { validateProjectData, validateIndexData } = require ( '../schemas' )
77
8- const indexTemplatePath = join ( process . cwd ( ) , 'src' , 'reports' , 'templates' , 'index.ejs' )
9- const projectTemplatePath = join ( process . cwd ( ) , 'src' , 'reports' , 'templates' , 'project.ejs' )
10- const assetsFolder = join ( process . cwd ( ) , 'src' , 'reports' , 'assets' )
11- const destinationFolder = join ( process . cwd ( ) , 'output' )
8+ const baseTemplatesPath = join ( __dirname , 'templates' )
9+ const indexTemplatePath = join ( baseTemplatesPath , 'index.ejs' )
10+ const projectTemplatePath = join ( baseTemplatesPath , 'project.ejs' )
11+ const assetsFolder = join ( __dirname , 'assets' )
12+ const destinationFolder = join ( __dirname , '../../output' )
1213const copyFolder = async ( from , to ) => {
1314 try {
1415 // Ensure the target directory exists
@@ -108,7 +109,7 @@ const collectProjectData = async (knex, projectId) => {
108109 }
109110}
110111
111- const internalLinkBuilder = ( mode = 'static' ) => ( ref , project ) => {
112+ const internalLinkBuilder = ( mode = 'static' ) => ( ref = '' , project ) => {
112113 let finalRef = ref
113114 // remove leading slash
114115 if ( mode === 'static' ) {
@@ -197,7 +198,7 @@ const generateStaticReports = async (knex, options = { clearPreviousReports: fal
197198 // Populate the project HTML template
198199 const projectHtml = ejs . render ( projectTemplate , projectsData [ project . name ] , {
199200 filename : projectTemplatePath ,
200- views : [ join ( process . cwd ( ) , 'src' , 'reports' , 'templates' ) ]
201+ views : [ join ( __dirname , 'templates' ) ]
201202 } )
202203 // @TODO : Prevent overwriting (edge case) at creation level
203204 if ( project . name !== 'index' ) {
@@ -208,8 +209,8 @@ const generateStaticReports = async (knex, options = { clearPreviousReports: fal
208209 }
209210
210211 await Promise . all ( [
211- writeFile ( 'output/ index_data.json', JSON . stringify ( indexData , null , 2 ) ) ,
212- writeFile ( 'output/ projects_data.json', JSON . stringify ( projectsData , null , 2 ) )
212+ writeFile ( join ( destinationFolder , ' index_data.json') , JSON . stringify ( indexData , null , 2 ) ) ,
213+ writeFile ( join ( destinationFolder , ' projects_data.json') , JSON . stringify ( projectsData , null , 2 ) )
213214 ] )
214215
215216 // copy assets folder
@@ -218,11 +219,11 @@ const generateStaticReports = async (knex, options = { clearPreviousReports: fal
218219 // Populate the index HTML template
219220 const indexHtml = ejs . render ( indexTemplate , indexData , {
220221 filename : indexTemplatePath ,
221- views : [ join ( process . cwd ( ) , 'src' , 'reports' , 'templates' ) ]
222+ views : [ join ( __dirname , 'templates' ) ]
222223 } )
223224
224225 // Save the index HTML file
225- await writeFile ( 'output/ index.html', indexHtml )
226+ await writeFile ( join ( destinationFolder , ' index.html') , indexHtml )
226227 logger . info ( 'Reports generated successfully' )
227228}
228229
0 commit comments