Skip to content

Instantly share code, notes, and snippets.

@RanolP
Last active June 4, 2022 04:48
Show Gist options
  • Save RanolP/d7b8540ecb86c91477d88180ddb96667 to your computer and use it in GitHub Desktop.
Save RanolP/d7b8540ecb86c91477d88180ddb96667 to your computer and use it in GitHub Desktop.
Download, Unzip, Classify.
import { promises as fs, constants as FS } from 'node:fs';
import { exec } from 'node:child_process';
import { promisify } from 'node:util';
import path from 'node:path';
const ColorRegex = /(?:\\([fFbB])([0-9]))|(\\0)/g;
function echo(templates, ...params) {
console.log(
String.raw(templates, ...params)
.replaceAll(ColorRegex, (_, fb, id, zero) =>
zero
? '\x1B[0m'
:`\x1B[${{f:3,F:9,b:4,B:10}[fb]}${id}m`
)
);
}
const execPromise = promisify(exec);
const $ = async (templates, ...params) => {
const cmd = Object.keys(templates)
.reduce(
(acc, index) => acc + templates[index] + String(params[index] ?? ''),
''
);
try {
echo`\F3$\0 \F0${cmd}\0`;
await execPromise(cmd);
} catch (e) {
echo`\F1${e.stderr}\0`;
process.exit(e.code);
}
};
const cwd = process.cwd();
echo`\F2Iosevka NF Concentrator\0`;
echo`Make sure you have installed 7z and it is accessible.`;
echo`1. Download font bundle... (Iosevka Nerd Fonts v2.2.0-RC)`;
try {
await fs.access(path.join(cwd, 'Iosevka.zip'), FS.F_OK);
echo` Zip file found!`;
} catch {
echo` Zip file does not exists.`;
echo` Download via curl...`;
await $`curl -OL https://github.com/ryanoasis/nerd-fonts/releases/download/2.2.0-RC/Iosevka.zip`;
}
echo`2. Unzip the file...`;
try {
await fs.access(path.join(cwd, 'files'), FS.F_OK);
echo` Folder found!`;
} catch {
echo` Folder does not exists.`;
echo` Unzip using 7-zip...`;
await $`7z x Iosevka.zip -ofiles`;
}
echo`3. Classify font files...`;
const NormalWindowsCompat = /^Iosevka (?!Term)\s*(.+)\s*Nerd Font Complete Windows Compatible.ttf$/;
const files = await fs.readdir(path.join(cwd, 'files'));
try {
await fs.mkdir('windows-compat');
} catch {
// do nothing
}
for (const file of files.filter(name => name.match(NormalWindowsCompat))) {
await $`move "${path.join('files', file)}" "${path.join('windows-compat', file)}"`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment