2022-07-19 14:39:03 +00:00
|
|
|
const fsPromises = require('fs/promises')
|
|
|
|
const { callbackify } = require('util')
|
2022-03-01 15:09:36 +00:00
|
|
|
const logger = require('@overleaf/logger')
|
2016-02-02 14:26:14 +00:00
|
|
|
|
2022-07-19 14:39:03 +00:00
|
|
|
async function injectDraftMode(filename) {
|
|
|
|
const content = await fsPromises.readFile(filename, { encoding: 'utf8' })
|
2022-07-22 08:12:18 +00:00
|
|
|
const modifiedContent =
|
|
|
|
'\\PassOptionsToPackage{draft}{graphicx}\\PassOptionsToPackage{draft}{graphics}' +
|
|
|
|
content
|
2022-07-19 14:39:03 +00:00
|
|
|
logger.debug(
|
|
|
|
{
|
|
|
|
content: content.slice(0, 1024), // \documentclass is normally v near the top
|
|
|
|
modifiedContent: modifiedContent.slice(0, 1024),
|
|
|
|
filename,
|
|
|
|
},
|
|
|
|
'injected draft class'
|
|
|
|
)
|
|
|
|
await fsPromises.writeFile(filename, modifiedContent, { encoding: 'utf8' })
|
2020-02-19 11:14:37 +00:00
|
|
|
}
|
2022-07-07 12:27:20 +00:00
|
|
|
|
2022-07-19 14:39:03 +00:00
|
|
|
module.exports = {
|
|
|
|
injectDraftMode: callbackify(injectDraftMode),
|
|
|
|
promises: { injectDraftMode },
|
2022-07-07 12:27:20 +00:00
|
|
|
}
|