fix(cjs): use __dirname if defined

This commit is contained in:
Rafael Bardini 2021-11-14 15:47:22 +01:00
parent 8c7df6b563
commit ffca75350a
1 changed files with 7 additions and 5 deletions

View File

@ -6,10 +6,12 @@ import Handlebars from 'handlebars'
import micromark from 'micromark' import micromark from 'micromark'
import striptags from 'striptags' import striptags from 'striptags'
const __filename = fileURLToPath(import.meta.url) const dirname =
const __dirname = path.dirname(__filename) typeof __dirname === 'string'
? __dirname
: path.dirname(fileURLToPath(import.meta.url))
const extname = '.hbs' const extname = '.hbs'
const partialsDir = path.join(__dirname, 'partials') const partialsDir = path.join(dirname, 'partials')
fs.readdirSync(partialsDir) fs.readdirSync(partialsDir)
.filter(filename => path.extname(filename) === extname) .filter(filename => path.extname(filename) === extname)
@ -60,8 +62,8 @@ Handlebars.registerHelper('stripTags', html => striptags(html))
export const pdfRenderOptions = { mediaType: 'print' } export const pdfRenderOptions = { mediaType: 'print' }
export const render = resume => { export const render = resume => {
const template = fs.readFileSync(path.join(__dirname, 'resume.hbs'), 'utf-8') const template = fs.readFileSync(path.resolve(dirname, 'resume.hbs'), 'utf-8')
const css = fs.readFileSync(path.join(__dirname, 'style.css'), 'utf-8') const css = fs.readFileSync(path.resolve(dirname, 'style.css'), 'utf-8')
return Handlebars.compile(template)({ css, resume }) return Handlebars.compile(template)({ css, resume })
} }