1#!/usr/bin/env node
2
3import fs from 'node:fs';
4import { createInterface } from 'node:readline';
5
6const dataFolder = new URL('../../doc/changelogs/', import.meta.url);
7
8const result = [];
9async function getVersionsFromFile(file) {
10  const input = fs.createReadStream(file);
11  let toc = false;
12  for await (const line of createInterface({
13    input,
14    crlfDelay: Infinity,
15  })) {
16    if (toc === false && line === '<table>') {
17      toc = true;
18    } else if (toc && line[0] !== '<') {
19      input.close();
20      return;
21    } else if (toc && line.startsWith('<a')) {
22      result.push(line.slice(line.indexOf('>') + 1, -'</a><br/>'.length));
23    } else if (toc && line.startsWith('<b><a')) {
24      result.push(line.slice(line.indexOf('>', 3) + 1, -'</a></b><br/>'.length));
25    }
26  }
27}
28
29const filesToCheck = [];
30
31const dir = await fs.promises.opendir(dataFolder);
32for await (const dirent of dir) {
33  if (dirent.isFile()) {
34    filesToCheck.push(
35      getVersionsFromFile(new URL(dirent.name, dataFolder)),
36    );
37  }
38}
39
40await Promise.all(filesToCheck);
41
42console.log(`NODE_RELEASED_VERSIONS=${result.join(',')}`);
43