-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDosya-Diff.js
More file actions
44 lines (32 loc) · 1.3 KB
/
Dosya-Diff.js
File metadata and controls
44 lines (32 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import fs from 'fs/promises';
import chalk from 'chalk';
import { diffChars } from 'diff';
const dosya1Yolu = process.argv[2];
const dosya2Yolu = process.argv[3];
async function karsilastir() {
const [d1, d2] = await Promise.all([
fs.readFile(dosya1Yolu, 'utf-8'),
fs.readFile(dosya2Yolu, 'utf-8')
]).catch(err=>{console.error("Dosya Okuma Hatası:"), er.message});
const dosya1 = d1.split(/\r?\n/);
const dosya2 = d2.split(/\r?\n/);
const maxSatir = Math.max(dosya1.length, dosya2.length);
console.log(chalk.bold(`\n--- DIFF ANALİZİ: ${dosya1Yolu} vs ${dosya2Yolu} ---\n`));
for (let i = 0; i < maxSatir; i++) {
const satir1 = dosya1[i] || "";
const satir2 = dosya2[i] || "";
const farklar = diffChars(satir1, satir2);
let satirCiktisi = "";
farklar.forEach((part) => {
if (part.added) {
satirCiktisi += chalk.bgGreen.black(part.value); // Yeni eklenen
} else if (part.removed) {
satirCiktisi += chalk.bgRed.black(part.value); // Silinen/Değişen
} else {
satirCiktisi += chalk.gray(part.value); // Ortak olanlar
}
});
console.log(`${i + 1}: ${satirCiktisi}`);
}
}
karsilastir();