2025-01-11 17:22:48 +06:00
|
|
|
const fs = require('fs');
|
2025-01-12 19:41:34 +06:00
|
|
|
const { execSync } = require('child_process');
|
2025-01-11 17:22:48 +06:00
|
|
|
|
|
|
|
|
function create(fileName, emoji) {
|
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
let data = fs.readFileSync('README.md', 'utf8');
|
|
|
|
|
const emojis = new Set(["🪟", "🍎", "🐧", "🟢", "⭐"]);
|
|
|
|
|
let result = [];
|
|
|
|
|
let lineCount = 0;
|
|
|
|
|
const lines = data.split('\n');
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
|
let line = lines[i];
|
|
|
|
|
if (lineCount < 20) {
|
|
|
|
|
result.push(line);
|
|
|
|
|
lineCount++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
line = line.replace(/ /g, '');
|
|
|
|
|
if ([...emojis].some(emojiChar => line.includes(emojiChar)) && !line.includes(emoji)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
result.push(lines[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(`${fileName}.md`, result.join('\n'));
|
|
|
|
|
console.log(`${fileName} execution time: ${Date.now() - startTime}ms`);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 19:36:35 +06:00
|
|
|
function categorize() {
|
|
|
|
|
create("windows-only", "🪟");
|
|
|
|
|
create("macOS-only", "🍎");
|
|
|
|
|
create("linux-only", "🐧");
|
|
|
|
|
create("open-source-only", "🟢");
|
|
|
|
|
create("recommended-only", "⭐");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function format() {
|
|
|
|
|
const data = fs.readFileSync('README.md', 'utf8');
|
|
|
|
|
|
|
|
|
|
const updatedData = data
|
|
|
|
|
.split('\n')
|
|
|
|
|
.map(line => {
|
|
|
|
|
line = line.replace(/https:\/\/www\./g, 'https://');
|
|
|
|
|
if (line.startsWith('- [')) {
|
|
|
|
|
const parts = line.split(' - ');
|
|
|
|
|
if (parts.length >= 2) {
|
|
|
|
|
let description = parts[1];
|
|
|
|
|
description = description.replace(/^A\s+/i, '').replace(/^An\s+/i, '');
|
|
|
|
|
description = description.charAt(0).toUpperCase() + description.slice(1);
|
|
|
|
|
parts[1] = description;
|
|
|
|
|
line = parts.join(' - ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return line;
|
|
|
|
|
})
|
|
|
|
|
.join('\n');
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync('README.md', updatedData, 'utf8');
|
|
|
|
|
console.log('README.md has been formatted.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function countLinks() {
|
|
|
|
|
const data = fs.readFileSync('README.md', 'utf8');
|
|
|
|
|
const linkCount = (data.match(/\[.*?\]\(https?:\/\/.*?\)/g) || []).length;
|
|
|
|
|
console.log(`Total links in README.md: \x1b[32m${linkCount}\x1b[0m`);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 19:41:34 +06:00
|
|
|
function fastGit(message = "update") {
|
|
|
|
|
try {
|
|
|
|
|
execSync('git add -A', { stdio: 'inherit' });
|
|
|
|
|
execSync(`git commit -m "${message}"`, { stdio: 'inherit' });
|
|
|
|
|
execSync('git push', { stdio: 'inherit' });
|
|
|
|
|
console.log('Changes have been committed and pushed.');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error running git commands:', error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 20:11:32 +06:00
|
|
|
function runAll() {
|
|
|
|
|
countLinks();
|
|
|
|
|
format();
|
|
|
|
|
categorize();
|
|
|
|
|
countLinks();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 19:36:35 +06:00
|
|
|
const args = process.argv.slice(2);
|
|
|
|
|
|
|
|
|
|
if (args.includes('--categorize')) {
|
|
|
|
|
categorize();
|
|
|
|
|
} else if (args.includes('--format')) {
|
|
|
|
|
format();
|
|
|
|
|
} else if (args.includes('--links')) {
|
|
|
|
|
countLinks();
|
2025-01-12 19:41:34 +06:00
|
|
|
} else if (args.includes('--fastgit')) {
|
|
|
|
|
const commitMessage = args.slice(1).join(' ');
|
|
|
|
|
if (commitMessage) {
|
|
|
|
|
fastGit(commitMessage);
|
|
|
|
|
} else {
|
|
|
|
|
console.log('Please provide a commit message after --fastgit');
|
|
|
|
|
}
|
2025-01-12 20:11:32 +06:00
|
|
|
} else if (args.includes('--all')) {
|
|
|
|
|
runAll();
|
2025-01-12 19:36:35 +06:00
|
|
|
} else {
|
|
|
|
|
console.log("Usage:");
|
2025-01-12 19:56:27 +06:00
|
|
|
console.log(" node index.js --categorize Categorize based on icons");
|
|
|
|
|
console.log(" node index.js --format Format README.md");
|
2025-01-12 19:36:35 +06:00
|
|
|
console.log(" node index.js --links Count and display total links in README.md");
|
2025-01-12 19:41:34 +06:00
|
|
|
console.log(" node index.js --fastgit <msg> Run git commands with the specified commit message");
|
2025-01-12 21:26:59 +06:00
|
|
|
console.log(" node index.js --all Run all the commands (format, categorize, links)");
|
2025-01-12 19:36:35 +06:00
|
|
|
}
|