Skip to content

Commit

Permalink
Add support for hostfile.txt output
Browse files Browse the repository at this point in the history
  • Loading branch information
inverse committed Oct 14, 2024
1 parent 1a95080 commit 680fd22
Show file tree
Hide file tree
Showing 8 changed files with 6,309 additions and 1,796 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/lint.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: CI
on:
push:
branches: [master]
Expand Down Expand Up @@ -26,3 +26,22 @@ jobs:
npm run lint:prettier
env:
CI: true
test:
name: Run test
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run test
run: |
npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules/
/connectors.ts
25 changes: 19 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fs from 'fs';
import util from 'util';
import fetch from 'node-fetch';
import { connectorsToHostFile } from './utils';

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

async function main(args: string[]) {
const latestTag = args.at(-1);
Expand All @@ -27,9 +29,18 @@ async function main(args: string[]) {
let exitCode = 0;
try {
await downloadModule(latestTag);
await dumpConnectors();

if (!fs.existsSync(resDir)) {
mkdir(resDir);
}

await dumpConnectors();
console.log(`Dumped connectors from ${latestTag} release.`);

await dumpHostfile();
console.log(`Dumped hostfile from ${latestTag} release.`);

// await removeFile(moduleFile);
} catch (e) {
console.error(`Unable to dump connectors from ${latestTag} release.`);
console.log(e);
Expand Down Expand Up @@ -58,12 +69,14 @@ async function dumpConnectors() {
const labelArray = connectors.map((entry) => entry.label);
const contents = JSON.stringify(labelArray, null, 2) + '\n';

if (!fs.existsSync(resDir)) {
mkdir(resDir);
}

await writeFile(listFile, contents);
await removeFile(moduleFile);
}

async function dumpHostfile() {
const connectors = (await import(`./${moduleFile}`)).default as any[];
const contents = connectorsToHostFile(connectors);
console.log(contents);
await writeFile(hostFile, contents);
}

function getModuleUrl(tagName) {
Expand Down
Loading

0 comments on commit 680fd22

Please sign in to comment.