-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
61 lines (55 loc) · 1.54 KB
/
index.ts
File metadata and controls
61 lines (55 loc) · 1.54 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as childProcess from "child_process";
import * as path from "path";
import { sync as which } from "which";
interface ProcessResult {
stdout: string;
stderr: string;
statusCode: Number;
}
function callChild(path: string, stdin: string, allowFail: Number, ...args): Promise<string> {
return new Promise<string>((resolve, reject) => {
if(!path) {
return reject("")
}
let proc = childProcess.spawn(path, args);
let stdout = "";
proc.stdout.on("data", (data) => {
stdout = stdout + data.toString();
});
proc.on("close", (code, signal) => {
if(code !== 0) {
if(allowFail && allowFail === code) {
resolve(stdout);
} else {
reject(code);
}
} else {
resolve(stdout);
}
});
if(stdin) {
proc.stdin.write(stdin)
}
});
}
let binDir = path.join(__dirname, "bin");
let diff3Path;
try {
if(process.platform === "win32") {
diff3Path = path.join(binDir, "diff3.exe");
} else {
diff3Path = which("diff3");
}
} catch(e) {
if(process.platform !== "win32") {
console.error("module node-diff3-wrapper requires gnu difftools to be on the path");
}
}
export module Diff3 {
export function diff(fileA: string, fileO: string, fileB:string, stdin?: string): Promise<string> {
return callChild(diff3Path, stdin, null, fileA, fileO, fileB);
}
export function diffM(fileA: string, fileO: string, fileB: string, stdin?: string): Promise<string> {
return callChild(diff3Path, stdin, 1, "-m", fileA, fileO, fileB);
}
}