mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -28,9 +28,9 @@ const _ = require('underscore')
|
||||
module.exports = ProjectRootDocManager = {
|
||||
setRootDocAutomatically(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectEntityHandler.getAllDocs(project_id, function(error, docs) {
|
||||
return ProjectEntityHandler.getAllDocs(project_id, function (error, docs) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -38,23 +38,23 @@ module.exports = ProjectRootDocManager = {
|
||||
const jobs = _.map(
|
||||
docs,
|
||||
(doc, path) =>
|
||||
function(cb) {
|
||||
function (cb) {
|
||||
if (
|
||||
ProjectEntityUpdateHandler.isPathValidForRootDoc(path) &&
|
||||
DocumentHelper.contentHasDocumentclass(doc.lines)
|
||||
) {
|
||||
async.setImmediate(function() {
|
||||
async.setImmediate(function () {
|
||||
cb(doc._id)
|
||||
})
|
||||
} else {
|
||||
async.setImmediate(function() {
|
||||
async.setImmediate(function () {
|
||||
cb(null)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return async.series(jobs, function(root_doc_id) {
|
||||
return async.series(jobs, function (root_doc_id) {
|
||||
if (root_doc_id != null) {
|
||||
return ProjectEntityUpdateHandler.setRootDoc(
|
||||
project_id,
|
||||
@@ -70,7 +70,7 @@ module.exports = ProjectRootDocManager = {
|
||||
|
||||
findRootDocFileFromDirectory(directoryPath, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, path, content) {}
|
||||
callback = function (error, path, content) {}
|
||||
}
|
||||
const filePathsPromise = globby(['**/*.{tex,Rtex}'], {
|
||||
cwd: directoryPath,
|
||||
@@ -88,7 +88,7 @@ module.exports = ProjectRootDocManager = {
|
||||
ProjectRootDocManager._sortFileList(
|
||||
unsortedFiles,
|
||||
directoryPath,
|
||||
function(err, files) {
|
||||
function (err, files) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
@@ -96,12 +96,12 @@ module.exports = ProjectRootDocManager = {
|
||||
|
||||
return async.until(
|
||||
() => doc != null || files.length === 0,
|
||||
function(cb) {
|
||||
function (cb) {
|
||||
const file = files.shift()
|
||||
return fs.readFile(
|
||||
Path.join(directoryPath, file),
|
||||
'utf8',
|
||||
function(error, content) {
|
||||
function (error, content) {
|
||||
if (error != null) {
|
||||
return cb(error)
|
||||
}
|
||||
@@ -131,11 +131,11 @@ module.exports = ProjectRootDocManager = {
|
||||
|
||||
setRootDocFromName(project_id, rootDocName, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectEntityHandler.getAllDocPathsFromProjectById(
|
||||
project_id,
|
||||
function(error, docPaths) {
|
||||
function (error, docPaths) {
|
||||
let doc_id, path
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
@@ -180,89 +180,91 @@ module.exports = ProjectRootDocManager = {
|
||||
|
||||
ensureRootDocumentIsSet(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectGetter.getProject(project_id, { rootDoc_id: 1 }, function(
|
||||
error,
|
||||
project
|
||||
) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback(new Error('project not found'))
|
||||
}
|
||||
return ProjectGetter.getProject(
|
||||
project_id,
|
||||
{ rootDoc_id: 1 },
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback(new Error('project not found'))
|
||||
}
|
||||
|
||||
if (project.rootDoc_id != null) {
|
||||
return callback()
|
||||
} else {
|
||||
return ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
if (project.rootDoc_id != null) {
|
||||
return callback()
|
||||
} else {
|
||||
return ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
ensureRootDocumentIsValid(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectGetter.getProject(project_id, { rootDoc_id: 1 }, function(
|
||||
error,
|
||||
project
|
||||
) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback(new Error('project not found'))
|
||||
}
|
||||
return ProjectGetter.getProject(
|
||||
project_id,
|
||||
{ rootDoc_id: 1 },
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback(new Error('project not found'))
|
||||
}
|
||||
|
||||
if (project.rootDoc_id != null) {
|
||||
return ProjectEntityHandler.getAllDocPathsFromProjectById(
|
||||
project_id,
|
||||
function(error, docPaths) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
let rootDocValid = false
|
||||
for (let doc_id in docPaths) {
|
||||
const _path = docPaths[doc_id]
|
||||
if (doc_id === project.rootDoc_id) {
|
||||
rootDocValid = true
|
||||
if (project.rootDoc_id != null) {
|
||||
return ProjectEntityHandler.getAllDocPathsFromProjectById(
|
||||
project_id,
|
||||
function (error, docPaths) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
let rootDocValid = false
|
||||
for (let doc_id in docPaths) {
|
||||
const _path = docPaths[doc_id]
|
||||
if (doc_id === project.rootDoc_id) {
|
||||
rootDocValid = true
|
||||
}
|
||||
}
|
||||
if (rootDocValid) {
|
||||
return callback()
|
||||
} else {
|
||||
return ProjectEntityUpdateHandler.unsetRootDoc(project_id, () =>
|
||||
ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
if (rootDocValid) {
|
||||
return callback()
|
||||
} else {
|
||||
return ProjectEntityUpdateHandler.unsetRootDoc(project_id, () =>
|
||||
ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
return ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
)
|
||||
} else {
|
||||
return ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
_sortFileList(listToSort, rootDirectory, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, result) {}
|
||||
callback = function (error, result) {}
|
||||
}
|
||||
return async.mapLimit(
|
||||
listToSort,
|
||||
5,
|
||||
(filePath, cb) =>
|
||||
fs.stat(Path.join(rootDirectory, filePath), function(err, stat) {
|
||||
fs.stat(Path.join(rootDirectory, filePath), function (err, stat) {
|
||||
if (err != null) {
|
||||
return cb(err)
|
||||
}
|
||||
@@ -273,7 +275,7 @@ module.exports = ProjectRootDocManager = {
|
||||
name: Path.basename(filePath)
|
||||
})
|
||||
}),
|
||||
function(err, files) {
|
||||
function (err, files) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user