|
| 1 | +import fs from "fs"; |
| 2 | +import path from "path"; |
| 3 | +import cp from "child_process"; |
| 4 | +function* walk(dir) { |
| 5 | + for (const file of fs.readdirSync(dir)) { |
| 6 | + const filePath = path.join(dir, file); |
| 7 | + if (fs.statSync(filePath).isDirectory()) { |
| 8 | + yield* walk(filePath); |
| 9 | + } else { |
| 10 | + yield filePath; |
| 11 | + } |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +function* deprecatedFiles(dir) { |
| 16 | + for (const file of walk(dir)) { |
| 17 | + if (file.endsWith(".ql") || file.endsWith(".qll")) { |
| 18 | + const contents = fs.readFileSync(file, "utf8"); |
| 19 | + if (/\sdeprecated\s/.test(contents)) { |
| 20 | + yield file; |
| 21 | + } |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +const blameRegExp = |
| 27 | + /^(\^?\w+)\s.+\s+(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (?:\+|-)\d{4})\s+(\d+)\).*$/; |
| 28 | + |
| 29 | +function* deprecationMessages(dir) { |
| 30 | + for (const file of deprecatedFiles(dir)) { |
| 31 | + const blame = cp.execFileSync("git", ["blame", "--", file]); |
| 32 | + const lines = blame.toString().split("\n"); |
| 33 | + for (let i = 0; i < lines.length; i++) { |
| 34 | + const line = lines[i]; |
| 35 | + if (line.includes(" deprecated ")) { |
| 36 | + try { |
| 37 | + const [_, sha, time, lineNumber] = line.match(blameRegExp); |
| 38 | + const date = new Date(time); |
| 39 | + // check if it's within the last year |
| 40 | + if (date.getTime() >= Date.now() - 365 * 24 * 60 * 60 * 1000) { |
| 41 | + continue; |
| 42 | + } |
| 43 | + const message = `${file}:${lineNumber} was last updated on ${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`; |
| 44 | + yield [message, date]; |
| 45 | + } catch (e) { |
| 46 | + console.log(e); |
| 47 | + console.log("----"); |
| 48 | + console.log(line); |
| 49 | + console.log("----"); |
| 50 | + process.exit(0); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | +[...deprecationMessages(".")] |
| 57 | + .sort((a, b) => a[1].getTime() - b[1].getTime()) |
| 58 | + .forEach((msg) => console.log(msg[0])); |
0 commit comments