2020-02-19 11:14:37 +00:00
|
|
|
const Path = require('path')
|
2024-01-10 12:02:06 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const { callbackifyMultiResult } = require('@overleaf/promise-utils')
|
2014-02-12 17:27:43 +00:00
|
|
|
|
2024-01-10 12:02:06 +00:00
|
|
|
async function walkFolder(compileDir, d, files, allEntries) {
|
|
|
|
const dirents = await fs.promises.readdir(Path.join(compileDir, d), {
|
|
|
|
withFileTypes: true,
|
|
|
|
})
|
|
|
|
for (const dirent of dirents) {
|
|
|
|
const p = Path.join(d, dirent.name)
|
|
|
|
if (dirent.isDirectory()) {
|
|
|
|
await walkFolder(compileDir, p, files, allEntries)
|
|
|
|
allEntries.push(p + '/')
|
|
|
|
} else if (dirent.isFile()) {
|
|
|
|
files.push(p)
|
|
|
|
allEntries.push(p)
|
|
|
|
} else {
|
|
|
|
allEntries.push(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-12 17:27:43 +00:00
|
|
|
|
2024-01-10 12:02:06 +00:00
|
|
|
async function findOutputFiles(resources, directory) {
|
|
|
|
const files = []
|
|
|
|
const allEntries = []
|
|
|
|
await walkFolder(directory, '', files, allEntries)
|
2017-09-26 08:47:29 +00:00
|
|
|
|
2024-01-10 12:02:06 +00:00
|
|
|
const incomingResources = new Set(resources.map(resource => resource.path))
|
2014-02-12 17:27:43 +00:00
|
|
|
|
2024-01-10 12:02:06 +00:00
|
|
|
const outputFiles = []
|
|
|
|
for (const path of files) {
|
|
|
|
if (incomingResources.has(path)) continue
|
|
|
|
if (path === '.project-sync-state') continue
|
|
|
|
outputFiles.push({
|
|
|
|
path,
|
|
|
|
type: Path.extname(path).replace(/^\./, '') || undefined,
|
2020-02-19 11:14:37 +00:00
|
|
|
})
|
2024-01-10 12:02:06 +00:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
outputFiles,
|
|
|
|
allEntries,
|
|
|
|
}
|
2020-02-19 11:14:37 +00:00
|
|
|
}
|
2022-07-07 12:27:20 +00:00
|
|
|
|
2024-01-10 12:02:06 +00:00
|
|
|
module.exports = {
|
|
|
|
findOutputFiles: callbackifyMultiResult(findOutputFiles, [
|
|
|
|
'outputFiles',
|
|
|
|
'allEntries',
|
|
|
|
]),
|
|
|
|
promises: {
|
|
|
|
findOutputFiles,
|
|
|
|
},
|
2022-07-07 12:27:20 +00:00
|
|
|
}
|