Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static createSpineStringsFromTemplate() {
log.info('opf build [spine]')
const { flattened } = state.spine
// We add entries to the spine programatically, but then they're
// also found on the system, so we dedupe them here
// TODO: but also, this is super confusing ...
const generatedFiles = remove(flattened, file => file.generated === true)
generatedFiles.forEach(file => {
if (!find(flattened, { fileName: file.fileName })) {
flattened.push(file)
}
})
const spineXML = Spine.items(flattened)
if (curr.linear === false) {
if (state.build === 'mobi') {
log.info(
`opf templates/spine omitting non-linear asset [${fileName}] for mobi build`
)
return acc
}
log.info(`opf templates/spine writing non-linear asset [${fileName}]`)
}
if (fileName.match(/figure/)) {
// TODO: this should be handled more transparently, rn it feels a bit like a side-effect
// https://github.com/triplecanopy/b-ber/issues/208
log.info('opf templates/spine writing [loi]')
if (state.loi.length) {
return acc.concat(
state.loi.reduce(
(acc2, curr2) =>
acc2.concat(Spine.item({ ...curr2, linear: true })),
Spine.item(curr)
)
)
}
}
return acc.concat(Spine.item(curr))
}, '')
}
static createGuideStringsFromTemplate() {
log.info('opf build [guide]')
const guideXML = Guide.items(state.guide)
return Template.render(guideXML, Guide.body())
}
if (!d) {
throw new Error('Specify a directory to remove')
}
let dirPath
try {
dirPath = path.resolve(process.cwd(), d)
} catch (err) {
throw err
}
if (!fs.existsSync(dirPath)) {
throw new Error(`The directory [${dirPath}] does not exist`)
}
return clean(dirPath).then(log.info(`remove [${dirPath}]`))
}
static async createTocStringsFromTemplate() {
log.info('opf build [toc.xhtml]')
const { toc } = state
const data = new File({
contents: Buffer.from(Template.render(Toc.items(toc), Toc.body())),
})
const file = [{ name: 'toc.xhtml', data }]
const [{ contents }] = await getFileObjects(file)
return contents
}
.then(() =>
log.info(
'scripts emit [%s]',
`javascripts${path.sep}${path.basename(output)}`
)
)
.then(() => log.info('clean remove [%s]', state.distDir))
)
files.forEach(file => {
const { size } = fs.statSync(path.join(dir.to, file))
log.info('copy [%s - {%d}]', `${baseTo}/${file}`, size)
if (size > FILE_SIZE_WARNING_LIMIT) {
log.warn(
'copy [%s - {%d}] exceeds recommended file size of {%d}',
file,
size,
FILE_SIZE_WARNING_LIMIT
)
}
})
})
.then(() => {
log.info('cover generated image [%s]', this.coverImagePath)
resolve()
})
.catch(log.error)
static createEmptyNavDocuments() {
const navDocs = ['toc.ncx', 'toc.xhtml']
log.info(`opf build navigation documents [${navDocs.join(', ')}]`)
const promises = navDocs.map(doc => fs.writeFile(state.dist.ops(doc), ''))
return Promise.all(promises)
}