Skip to content

Commit

Permalink
Merge pull request #20 from rtfeldman/compiler-flag
Browse files Browse the repository at this point in the history
Add a --compiler flag and upgrade to node-elm-compiler 2.0.0
  • Loading branch information
Richard Feldman committed Nov 22, 2015
2 parents 385b0a0 + a5dc16b commit cfe012e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 17 additions & 7 deletions bin/elm-test
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ if (process.argv[2] == "init") {
process.exit(0);
}

var testFile = process.argv[2],
cwd = __dirname;
var testFile = process.argv[2],
cwd = __dirname,
pathToMake = undefined;

function spawnCompiler(cmd, args, opts) {
var compilerOpts = _.defaults({stdio: ["inherit", "pipe", "inherit"]}, opts);
Expand All @@ -60,7 +61,7 @@ function spawnCompiler(cmd, args, opts) {

if (typeof testFile !== "string") {
console.log("Usage: elm-test init [--yes] # Create example tests\n");
console.log("Usage: elm-test TESTFILE # Run tests\n");
console.log("Usage: elm-test TESTFILE [--compiler /path/to/compiler] # Run tests\n");
process.exit(1);
}

Expand All @@ -69,18 +70,27 @@ if (!fs.existsSync(testFile)) {
process.exit(1);
}

if (process.argv[3] == "--compiler" || process.argv[3] == "-c") {
pathToMake = process.argv[4];

if (!pathToMake) {
console.error("The --compiler option must be given a path to an elm-make executable.");
process.exit(1);
}
}

temp.open({ prefix:'elm_test_', suffix:'.js' }, function(err, info) {
var dest = info.path;
var compileProcess = compile([testFile], {output: dest, spawn: spawnCompiler});

console.log("Compiling", testFile);
var compileProcess = compile( [testFile],
{output: dest, spawn: spawnCompiler, pathToMake: pathToMake});

compileProcess.stdout.setEncoding("utf8")
compileProcess.stdout.on("data", function(data) {
// Explicitly strip out the "Successfully generated" message.
// This avoids the nasty compiler output message for the temp file, e.g.
// "Successfully generated /var/folders/f2/afd9fg0acfg32/elm_test_3423940"
if ((typeof data === "string") && !data.match(/^Successfully generated /)) {
// Also strip out "Success! Compiled 1 module."
if ((typeof data === "string") && !/^Success/.test(data)) {
console.log(data);
}
});
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
},
"homepage": "https://github.com/rtfeldman/node-elm-test#readme",
"dependencies": {
"fs-extra": "0.23.1",
"fs-extra": "0.26.2",
"lodash": "3.10.1",
"node-elm-compiler": "1.0.1",
"temp": "0.8.1"
"node-elm-compiler": "2.0.0",
"temp": "0.8.3"
}
}

0 comments on commit cfe012e

Please sign in to comment.