• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * You should have ts-node installed globally before executing this, probably!
3 * Otherwise you'll need to compile this script before you start bisecting!
4 */
5import cp = require("child_process");
6import fs = require("fs");
7
8// Slice off 'node bisect-test.js' from the command line args
9const args = process.argv.slice(2);
10
11function tsc(tscArgs: string, onExit: (exitCode: number) => void) {
12    const tsc = cp.exec("node built/local/tsc.js " + tscArgs,() => void 0);
13    tsc.on("close", tscExitCode => {
14        onExit(tscExitCode);
15    });
16}
17
18// TODO: Rewrite bisect script to handle the post-jake/gulp swap period
19const jake = cp.exec("jake clean local", () => void 0);
20jake.on("close", jakeExitCode => {
21    if (jakeExitCode === 0) {
22        // See what we're being asked to do
23        if (args[1] === "compiles" || args[1] === "!compiles") {
24            tsc(args[0], tscExitCode => {
25                if ((tscExitCode === 0) === (args[1] === "compiles")) {
26                    console.log("Good");
27                    process.exit(0); // Good
28                }
29                else {
30                    console.log("Bad");
31                    process.exit(1); // Bad
32                }
33            });
34        }
35        else if (args[1] === "emits" || args[1] === "!emits") {
36            tsc(args[0], tscExitCode => {
37                fs.readFile(args[2], "utf-8", (err, data) => {
38                    const doesContains = data.indexOf(args[3]) >= 0;
39                    if (doesContains === (args[1] === "emits")) {
40                        console.log("Good");
41                        process.exit(0); // Good
42                    }
43                    else {
44                        console.log("Bad");
45                        process.exit(1); // Bad
46                    }
47                });
48            });
49        }
50        else {
51            console.log("Unknown command line arguments.");
52            console.log("Usage (compile errors): git bisect run ts-node scripts\bisect-test.ts '../failure.ts --module amd' !compiles");
53            console.log("Usage (emit check): git bisect run ts-node scripts\bisect-test.ts bar.ts emits bar.js '_this = this'");
54            // Aborts the 'git bisect run' process
55            process.exit(-1);
56        }
57    }
58    else {
59        // Compiler build failed; skip this commit
60        console.log("Skip");
61        process.exit(125); // bisect skip
62    }
63});
64