2024-03-24 19:38:18 +02:00
|
|
|
#!/usr/bin/env node
|
2024-02-11 06:52:10 +02:00
|
|
|
/**
|
2024-06-06 14:40:35 +02:00
|
|
|
* @file
|
2024-02-11 06:52:10 +02:00
|
|
|
* Rewrite some Markdown files.
|
|
|
|
*/
|
|
|
|
|
2024-03-24 19:38:18 +02:00
|
|
|
import {readFile, writeFile} from 'node:fs/promises';
|
2024-02-11 06:52:10 +02:00
|
|
|
import path from 'node:path';
|
2024-03-24 19:38:18 +02:00
|
|
|
import process from 'node:process';
|
|
|
|
import {getDirnameFromImportMeta} from '../../sdk.mjs';
|
2024-02-11 06:52:10 +02:00
|
|
|
|
|
|
|
const LINKS_BRANCH = process.argv[2] || 'develop';
|
|
|
|
|
|
|
|
const __dirname = getDirnameFromImportMeta(import.meta.url);
|
|
|
|
|
2024-03-24 19:38:18 +02:00
|
|
|
const rootDirectory = path.resolve(__dirname, '..', '..');
|
|
|
|
const readmeFile = path.resolve(rootDirectory, 'README.md');
|
|
|
|
const disclaimerFile = path.resolve(rootDirectory, 'DISCLAIMER.md');
|
2024-02-11 06:52:10 +02:00
|
|
|
|
2024-06-06 14:40:35 +02:00
|
|
|
/**
|
|
|
|
* Reformat a file.
|
2024-09-29 16:28:34 +02:00
|
|
|
* @param {string} filePath Path to the file.
|
2024-06-06 14:40:35 +02:00
|
|
|
*/
|
2024-02-11 06:52:10 +02:00
|
|
|
const reformat = async (filePath) => {
|
|
|
|
const fileContent = await readFile(filePath, 'utf8');
|
|
|
|
await writeFile(
|
|
|
|
filePath,
|
|
|
|
fileContent
|
|
|
|
// Replace all CDN links with raw links
|
2024-03-24 19:38:18 +02:00
|
|
|
.replaceAll(
|
2024-02-11 06:52:10 +02:00
|
|
|
/https:\/\/cdn.simpleicons.org\/(.+)\/000\/fff/g,
|
|
|
|
`https://raw.githubusercontent.com/simple-icons/simple-icons/${LINKS_BRANCH}/icons/$1.svg`,
|
|
|
|
)
|
|
|
|
// Replace all GitHub blockquotes with regular markdown
|
|
|
|
// Reference: https://github.com/orgs/community/discussions/16925
|
2024-03-24 19:38:18 +02:00
|
|
|
.replaceAll(
|
|
|
|
/\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)](?!\()/g,
|
|
|
|
function (string_, $0) {
|
|
|
|
const capital = $0.slice(0, 1);
|
|
|
|
const body = $0.slice(1).toLowerCase();
|
2024-02-11 06:52:10 +02:00
|
|
|
return `**${capital + body}**`;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
await Promise.all([reformat(readmeFile), reformat(disclaimerFile)]);
|