2024-11-08 05:21:56 -05:00
|
|
|
const Path = require('node:path')
|
|
|
|
const fs = require('node:fs')
|
2024-01-10 07:02:06 -05:00
|
|
|
const { callbackifyMultiResult } = require('@overleaf/promise-utils')
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2024-01-10 07:02:06 -05: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 12:27:43 -05:00
|
|
|
|
2024-01-10 07:02:06 -05:00
|
|
|
async function findOutputFiles(resources, directory) {
|
|
|
|
const files = []
|
|
|
|
const allEntries = []
|
|
|
|
await walkFolder(directory, '', files, allEntries)
|
2017-09-26 04:47:29 -04:00
|
|
|
|
2024-01-10 07:02:06 -05:00
|
|
|
const incomingResources = new Set(resources.map(resource => resource.path))
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2024-01-10 07:02:06 -05: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 06:14:37 -05:00
|
|
|
})
|
2024-01-10 07:02:06 -05:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
outputFiles,
|
|
|
|
allEntries,
|
|
|
|
}
|
2020-02-19 06:14:37 -05:00
|
|
|
}
|
2022-07-07 08:27:20 -04:00
|
|
|
|
2024-01-10 07:02:06 -05:00
|
|
|
module.exports = {
|
|
|
|
findOutputFiles: callbackifyMultiResult(findOutputFiles, [
|
|
|
|
'outputFiles',
|
|
|
|
'allEntries',
|
|
|
|
]),
|
|
|
|
promises: {
|
|
|
|
findOutputFiles,
|
|
|
|
},
|
2022-07-07 08:27:20 -04:00
|
|
|
}
|