Skip to content

Commit a93e7be

Browse files
authored
Add support for hostfile.txt output (#19)
1 parent 1a95080 commit a93e7be

File tree

8 files changed

+6409
-1796
lines changed

8 files changed

+6409
-1796
lines changed

.github/workflows/lint.yml renamed to .github/workflows/ci.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint
1+
name: CI
22
on:
33
push:
44
branches: [master]
@@ -26,3 +26,22 @@ jobs:
2626
npm run lint:prettier
2727
env:
2828
CI: true
29+
test:
30+
name: Run test
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout the repository
34+
uses: actions/checkout@v4
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version-file: '.nvmrc'
40+
cache: 'npm'
41+
42+
- name: Install dependencies
43+
run: npm ci
44+
45+
- name: Run test
46+
run: |
47+
npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/node_modules/
2+
/connectors.ts

index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fs from 'fs';
44
import util from 'util';
55
import fetch from 'node-fetch';
6+
import { connectorsToHostFile } from './utils';
67

78
const mkdir = util.promisify(fs.mkdir);
89
const writeFile = util.promisify(fs.writeFile);
@@ -15,6 +16,7 @@ const rawContentUrl = `https://raw.githubusercontent.com/${owner}/${repo}`;
1516
const resDir = 'resources';
1617
const moduleFile = 'connectors.ts';
1718
const listFile = `${resDir}/connectors.json`;
19+
const hostFile = `${resDir}/hostfile.txt`;
1820

1921
async function main(args: string[]) {
2022
const latestTag = args.at(-1);
@@ -27,9 +29,18 @@ async function main(args: string[]) {
2729
let exitCode = 0;
2830
try {
2931
await downloadModule(latestTag);
30-
await dumpConnectors();
3132

33+
if (!fs.existsSync(resDir)) {
34+
mkdir(resDir);
35+
}
36+
37+
await dumpConnectors();
3238
console.log(`Dumped connectors from ${latestTag} release.`);
39+
40+
await dumpHostfile();
41+
console.log(`Dumped hostfile from ${latestTag} release.`);
42+
43+
await removeFile(moduleFile);
3344
} catch (e) {
3445
console.error(`Unable to dump connectors from ${latestTag} release.`);
3546
console.log(e);
@@ -58,12 +69,13 @@ async function dumpConnectors() {
5869
const labelArray = connectors.map((entry) => entry.label);
5970
const contents = JSON.stringify(labelArray, null, 2) + '\n';
6071

61-
if (!fs.existsSync(resDir)) {
62-
mkdir(resDir);
63-
}
64-
6572
await writeFile(listFile, contents);
66-
await removeFile(moduleFile);
73+
}
74+
75+
async function dumpHostfile() {
76+
const connectors = (await import(`./${moduleFile}`)).default as any[];
77+
const contents = connectorsToHostFile(connectors);
78+
await writeFile(hostFile, contents);
6779
}
6880

6981
function getModuleUrl(tagName) {

0 commit comments

Comments
 (0)