Compare commits
3 Commits
8c242214fb
...
v0.2.7
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d21b8958b | |||
|
4c2441b9e5
|
|||
|
494b4b239d
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -103,4 +103,5 @@ distribution/*
|
||||
mirrorlist
|
||||
mirrors*.json
|
||||
mirrors.md
|
||||
head.md
|
||||
.env
|
||||
|
||||
7
package-lock.json
generated
7
package-lock.json
generated
@@ -10,6 +10,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"country-code-lookup": "0.1.3",
|
||||
"email-addresses": "5.0.0",
|
||||
"extract-tld": "1.1.2"
|
||||
},
|
||||
"bin": {
|
||||
@@ -36,6 +37,12 @@
|
||||
"integrity": "sha512-gLu+AQKHUnkSQNTxShKgi/4tYd0vEEait3JMrLNZgYlmIZ9DJLkHUjzXE9qcs7dy3xY/kUx2/nOxZ0Z3D9JE+A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/email-addresses": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/email-addresses/-/email-addresses-5.0.0.tgz",
|
||||
"integrity": "sha512-4OIPYlA6JXqtVn8zpHpGiI7vE6EQOAg16aGnDMIAlZVinnoZ8208tW1hAbjWydgN/4PLTT9q+O1K6AH/vALJGw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/extract-tld": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/extract-tld/-/extract-tld-1.1.2.tgz",
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"country-code-lookup": "0.1.3",
|
||||
"email-addresses": "5.0.0",
|
||||
"extract-tld": "1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
35
src/index.ts
35
src/index.ts
@@ -1,6 +1,7 @@
|
||||
import path from 'path';
|
||||
import fsp from 'fs/promises';
|
||||
import parseUrl from 'extract-tld';
|
||||
import addrs from "email-addresses";
|
||||
import { resolveCountry } from './resolveCountry.js';
|
||||
import MirrorsByRegion from './mirrorsByRegion.js';
|
||||
import type { PathLike } from 'fs';
|
||||
@@ -10,6 +11,7 @@ const inputFile = process.env['INPUT'] || path.join(process.cwd(), 'mirrors.json
|
||||
const fixtureFile = process.env['FIXTURE'] || path.join(process.cwd(), 'mirrors.fixture.json');
|
||||
const mirrorList = process.env['MIRRORLIST'] || path.join(process.cwd(), 'mirrorlist');
|
||||
const mirrorMd = process.env['MIRRORMD'] || path.join(process.cwd(), 'mirrors.md');
|
||||
const mdHeadFile = process.env['MDHEADER'] || path.join(process.cwd(), 'head.md');
|
||||
const verbose = !!process.env['VERBOSE'];
|
||||
|
||||
const protocolId: Record<Protocol, number> = {
|
||||
@@ -182,7 +184,7 @@ function generateMirrorlist(mirrors: MirrorProfile[] = []): string {
|
||||
const lines: string[] = [
|
||||
'##',
|
||||
'## Artix Linux repository mirrorlist',
|
||||
`## Generated on ${getDateTime()}`,
|
||||
`## Generated on ${getDateTime()} by artix-mlg`,
|
||||
'##',
|
||||
'',
|
||||
'# Artix mirrors',
|
||||
@@ -198,7 +200,18 @@ function generateMirrorlist(mirrors: MirrorProfile[] = []): string {
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function generateMirrorMd(): string {
|
||||
async function generateMirrorMd(): Promise<string> {
|
||||
async function tryReadHeader(): Promise<string[]> {
|
||||
try {
|
||||
return [await fsp.readFile(mdHeadFile, 'utf-8')];
|
||||
}
|
||||
catch (err) {
|
||||
if (verbose) {
|
||||
console.error(err);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
function pushTableRowIfTruthy(lines: string[], label: string, value: string | undefined | null | false) {
|
||||
if (value) {
|
||||
lines.push(`| ${label} | ${value} |`);
|
||||
@@ -207,9 +220,15 @@ function generateMirrorMd(): string {
|
||||
function findFirstWithChild<T, K extends keyof T>(profiles: T[], key: K): T[K] | undefined {
|
||||
return profiles.find(p => !!p[key])?.[key];
|
||||
}
|
||||
const lines: string[] = [
|
||||
'# Mirrors\n\nContact or other information for the mirrors of our repositories and ISOs.\n'
|
||||
]
|
||||
function printEmail(email: string | undefined) {
|
||||
if (!email) {
|
||||
return email;
|
||||
}
|
||||
const addr = addrs.parseOneAddress(email)?.['address'];
|
||||
return `[${email.replaceAll('<', '<').replaceAll('>', '>')}](mailto:${addr})`;
|
||||
}
|
||||
const lines: string[] = await tryReadHeader();
|
||||
lines.push('# Mirrors\n\nContact or other information for the mirrors of our repositories and ISOs.\n');
|
||||
for (let mirrorName in mirrorProfilesByMirrorName) {
|
||||
const profiles: MirrorProfile[] = mirrorProfilesByMirrorName[mirrorName];
|
||||
const activeProfiles: MirrorProfile[] = profiles.filter(p => p.active);
|
||||
@@ -231,8 +250,8 @@ function generateMirrorMd(): string {
|
||||
// pushTableRowIfTruthy(lines, 'Frequency', findFirstWithChild(activeProfiles, 'frequency'));
|
||||
// pushTableRowIfTruthy(lines, 'Hosted by', findFirstWithChild(activeProfiles, 'org'));
|
||||
pushTableRowIfTruthy(lines, 'Location', findFirstWithChild(activeProfiles, 'country') || findFirstWithChild(profiles, 'country'));
|
||||
pushTableRowIfTruthy(lines, 'Contact Details', findFirstWithChild(activeProfiles, 'admin_email') || findFirstWithChild(profiles, 'admin_email'));
|
||||
pushTableRowIfTruthy(lines, 'Altenate Contact Details', findFirstWithChild(activeProfiles, 'alternate_email') || findFirstWithChild(profiles, 'alternate_email'));
|
||||
pushTableRowIfTruthy(lines, 'Contact Details', printEmail(findFirstWithChild(activeProfiles, 'admin_email') || findFirstWithChild(profiles, 'admin_email')));
|
||||
pushTableRowIfTruthy(lines, 'Altenate Contact Details', printEmail(findFirstWithChild(activeProfiles, 'alternate_email') || findFirstWithChild(profiles, 'alternate_email')));
|
||||
lines.push('');
|
||||
}
|
||||
return lines.join('\n');
|
||||
@@ -264,7 +283,7 @@ async function main() {
|
||||
|
||||
await fsp.writeFile(fixtureFile, JSON.stringify(composeMirrorFixture(), null, 4));
|
||||
await fsp.writeFile(mirrorList, generateMirrorlist(input.mirrors?.filter(m => m.public && m.active && !m.suppress) || []));
|
||||
await fsp.writeFile(mirrorMd, generateMirrorMd());
|
||||
await fsp.writeFile(mirrorMd, await generateMirrorMd());
|
||||
}
|
||||
|
||||
export default main;
|
||||
|
||||
Reference in New Issue
Block a user