Compare commits
2 Commits
8c242214fb
...
4c2441b9e5
| Author | SHA1 | Date | |
|---|---|---|---|
|
4c2441b9e5
|
|||
|
494b4b239d
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -103,4 +103,5 @@ distribution/*
|
|||||||
mirrorlist
|
mirrorlist
|
||||||
mirrors*.json
|
mirrors*.json
|
||||||
mirrors.md
|
mirrors.md
|
||||||
|
head.md
|
||||||
.env
|
.env
|
||||||
|
|||||||
23
src/index.ts
23
src/index.ts
@@ -10,6 +10,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 fixtureFile = process.env['FIXTURE'] || path.join(process.cwd(), 'mirrors.fixture.json');
|
||||||
const mirrorList = process.env['MIRRORLIST'] || path.join(process.cwd(), 'mirrorlist');
|
const mirrorList = process.env['MIRRORLIST'] || path.join(process.cwd(), 'mirrorlist');
|
||||||
const mirrorMd = process.env['MIRRORMD'] || path.join(process.cwd(), 'mirrors.md');
|
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 verbose = !!process.env['VERBOSE'];
|
||||||
|
|
||||||
const protocolId: Record<Protocol, number> = {
|
const protocolId: Record<Protocol, number> = {
|
||||||
@@ -182,7 +183,7 @@ function generateMirrorlist(mirrors: MirrorProfile[] = []): string {
|
|||||||
const lines: string[] = [
|
const lines: string[] = [
|
||||||
'##',
|
'##',
|
||||||
'## Artix Linux repository mirrorlist',
|
'## Artix Linux repository mirrorlist',
|
||||||
`## Generated on ${getDateTime()}`,
|
`## Generated on ${getDateTime()} by artix-mlg`,
|
||||||
'##',
|
'##',
|
||||||
'',
|
'',
|
||||||
'# Artix mirrors',
|
'# Artix mirrors',
|
||||||
@@ -198,7 +199,18 @@ function generateMirrorlist(mirrors: MirrorProfile[] = []): string {
|
|||||||
return lines.join('\n');
|
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) {
|
function pushTableRowIfTruthy(lines: string[], label: string, value: string | undefined | null | false) {
|
||||||
if (value) {
|
if (value) {
|
||||||
lines.push(`| ${label} | ${value} |`);
|
lines.push(`| ${label} | ${value} |`);
|
||||||
@@ -207,9 +219,8 @@ function generateMirrorMd(): string {
|
|||||||
function findFirstWithChild<T, K extends keyof T>(profiles: T[], key: K): T[K] | undefined {
|
function findFirstWithChild<T, K extends keyof T>(profiles: T[], key: K): T[K] | undefined {
|
||||||
return profiles.find(p => !!p[key])?.[key];
|
return profiles.find(p => !!p[key])?.[key];
|
||||||
}
|
}
|
||||||
const lines: string[] = [
|
const lines: string[] = await tryReadHeader();
|
||||||
'# Mirrors\n\nContact or other information for the mirrors of our repositories and ISOs.\n'
|
lines.push('# Mirrors\n\nContact or other information for the mirrors of our repositories and ISOs.\n');
|
||||||
]
|
|
||||||
for (let mirrorName in mirrorProfilesByMirrorName) {
|
for (let mirrorName in mirrorProfilesByMirrorName) {
|
||||||
const profiles: MirrorProfile[] = mirrorProfilesByMirrorName[mirrorName];
|
const profiles: MirrorProfile[] = mirrorProfilesByMirrorName[mirrorName];
|
||||||
const activeProfiles: MirrorProfile[] = profiles.filter(p => p.active);
|
const activeProfiles: MirrorProfile[] = profiles.filter(p => p.active);
|
||||||
@@ -264,7 +275,7 @@ async function main() {
|
|||||||
|
|
||||||
await fsp.writeFile(fixtureFile, JSON.stringify(composeMirrorFixture(), null, 4));
|
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(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;
|
export default main;
|
||||||
|
|||||||
Reference in New Issue
Block a user