prettier: convert app/js decaffeinated files to Prettier format
This commit is contained in:
@@ -11,34 +11,47 @@
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let DraftModeManager;
|
||||
const fs = require("fs");
|
||||
const logger = require("logger-sharelatex");
|
||||
let DraftModeManager
|
||||
const fs = require('fs')
|
||||
const logger = require('logger-sharelatex')
|
||||
|
||||
module.exports = (DraftModeManager = {
|
||||
injectDraftMode(filename, callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
return fs.readFile(filename, "utf8", function(error, content) {
|
||||
if (error != null) { return callback(error); }
|
||||
// avoid adding draft mode more than once
|
||||
if ((content != null ? content.indexOf("\\documentclass\[draft") : undefined) >= 0) {
|
||||
return callback();
|
||||
}
|
||||
const modified_content = DraftModeManager._injectDraftOption(content);
|
||||
logger.log({
|
||||
content: content.slice(0,1024), // \documentclass is normally v near the top
|
||||
modified_content: modified_content.slice(0,1024),
|
||||
filename
|
||||
}, "injected draft class");
|
||||
return fs.writeFile(filename, modified_content, callback);
|
||||
});
|
||||
},
|
||||
|
||||
_injectDraftOption(content) {
|
||||
return content
|
||||
// With existing options (must be first, otherwise both are applied)
|
||||
.replace(/\\documentclass\[/g, "\\documentclass[draft,")
|
||||
// Without existing options
|
||||
.replace(/\\documentclass\{/g, "\\documentclass[draft]{");
|
||||
}
|
||||
});
|
||||
module.exports = DraftModeManager = {
|
||||
injectDraftMode(filename, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
}
|
||||
return fs.readFile(filename, 'utf8', function(error, content) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
// avoid adding draft mode more than once
|
||||
if (
|
||||
(content != null
|
||||
? content.indexOf('\\documentclass[draft')
|
||||
: undefined) >= 0
|
||||
) {
|
||||
return callback()
|
||||
}
|
||||
const modified_content = DraftModeManager._injectDraftOption(content)
|
||||
logger.log(
|
||||
{
|
||||
content: content.slice(0, 1024), // \documentclass is normally v near the top
|
||||
modified_content: modified_content.slice(0, 1024),
|
||||
filename
|
||||
},
|
||||
'injected draft class'
|
||||
)
|
||||
return fs.writeFile(filename, modified_content, callback)
|
||||
})
|
||||
},
|
||||
|
||||
_injectDraftOption(content) {
|
||||
return (
|
||||
content
|
||||
// With existing options (must be first, otherwise both are applied)
|
||||
.replace(/\\documentclass\[/g, '\\documentclass[draft,')
|
||||
// Without existing options
|
||||
.replace(/\\documentclass\{/g, '\\documentclass[draft]{')
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user