(fileNameFilter = process.argv[2])
| 82 | |
| 83 | /** @param {string | undefined} fileNameFilter */ |
| 84 | export async function compileFiles(fileNameFilter = process.argv[2]) { |
| 85 | const fileNames = await getFileNames(fileNameFilter); |
| 86 | |
| 87 | if (!fileNames.length) { |
| 88 | console.log("no changes detected."); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | const parseWast = await getWastParser(); |
| 93 | |
| 94 | const cachePath = fileURLToPath( |
| 95 | new URL("../../.cache/cache.txt", import.meta.url) |
| 96 | ); |
| 97 | const cacheFileHandle = await fs.open(cachePath, "a"); |
| 98 | |
| 99 | let successCount = 0; |
| 100 | try { |
| 101 | await Promise.all( |
| 102 | fileNames.map(async (file) => { |
| 103 | try { |
| 104 | const jsFilePath = fileURLToPath( |
| 105 | new URL( |
| 106 | "../../exercises/" + file.replace(/\.[^.]+$/, ".mjs"), |
| 107 | import.meta.url |
| 108 | ) |
| 109 | ); |
| 110 | await fs.access(jsFilePath); |
| 111 | |
| 112 | console.log(`Running associated JS file for ${file}`); |
| 113 | await import(jsFilePath); |
| 114 | console.log("_".repeat(32) + "\n"); |
| 115 | return; |
| 116 | } catch {} |
| 117 | |
| 118 | const filePath = fileURLToPath( |
| 119 | new URL("../../exercises/" + file, import.meta.url) |
| 120 | ); |
| 121 | |
| 122 | try { |
| 123 | await parseWast(filePath); |
| 124 | |
| 125 | // add WAT hash |
| 126 | const fileBytes = await fs.readFile(filePath); |
| 127 | const hash = await getSha1Hash(fileBytes); |
| 128 | cacheFileHandle.write(`${file}:${hash}\n`); |
| 129 | successCount++; |
| 130 | } catch (e) { |
| 131 | console.error(`Error at ${filePath}:`, e); |
| 132 | process.exit(1); |
| 133 | } |
| 134 | }) |
| 135 | ); |
| 136 | } finally { |
| 137 | await cacheFileHandle.close(); |
| 138 | } |
| 139 | |
| 140 | console.log(`compiled ${successCount} file${successCount === 1 ? "" : "s"}`); |
| 141 | } |
no test coverage detected