Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hostfile.txt output #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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