* Get list of files that have since been updated since last run * Also return files that do not have a corresponding build * * @param {string[]} files file names * @returns {Promise }
(files)
| 27 | * @returns {Promise<string[]>} |
| 28 | */ |
| 29 | async function getChangedFiles(files) { |
| 30 | const cachePath = fileURLToPath( |
| 31 | new URL("../../.cache/cache.txt", import.meta.url) |
| 32 | ); |
| 33 | /** @type {Map<string, string>} */ |
| 34 | let contents = new Map(); |
| 35 | |
| 36 | try { |
| 37 | await fs.access(".cache"); |
| 38 | } catch { |
| 39 | await fs.mkdir(".cache"); |
| 40 | } |
| 41 | |
| 42 | try { |
| 43 | const bytes = await fs.readFile(cachePath); |
| 44 | const fileText = new TextDecoder("utf-8").decode(bytes); |
| 45 | contents = new Map( |
| 46 | fileText |
| 47 | .split("\n") |
| 48 | .map((line) => /** @type {[string, string]} */ (line.split(":"))) |
| 49 | ); |
| 50 | } catch {} |
| 51 | |
| 52 | const filePromises = files.map(async (name) => { |
| 53 | const path = fileURLToPath( |
| 54 | new URL(`../../exercises/${name}`, import.meta.url) |
| 55 | ); |
| 56 | const bytes = await fs.readFile(path); |
| 57 | |
| 58 | return [name, await getSha1Hash(bytes)]; |
| 59 | }); |
| 60 | |
| 61 | const fileHashes = await Promise.all(filePromises); |
| 62 | |
| 63 | const changedFiles = fileHashes |
| 64 | .filter(([name, hash]) => contents.get(name) !== hash) |
| 65 | .map(([name]) => name); |
| 66 | |
| 67 | return changedFiles; |
| 68 | } |
| 69 | |
| 70 | /** @param {string | undefined} fileNameFilter */ |
| 71 | async function getFileNames(fileNameFilter) { |
no test coverage detected