node-elm-compiler
Advanced tools
Comparing version 4.2.1 to 4.3.0
85
index.js
@@ -30,44 +30,78 @@ 'use strict'; | ||
function prepareSources(sources) { | ||
if (!(sources instanceof Array || typeof sources === "string")) { | ||
throw "compile() received neither an Array nor a String for its sources argument."; | ||
} | ||
function compile(sources, options) { | ||
if (typeof sources === "string") { | ||
sources = [sources]; | ||
return typeof sources === "string" ? [sources] : sources; | ||
} | ||
function prepareOptions(options, spawnFn) { | ||
return _.defaults({ spawn: spawnFn }, options, defaultOptions); | ||
} | ||
function prepareProcessArgs(sources, options) { | ||
var preparedSources = prepareSources(sources); | ||
var compilerArgs = compilerArgsFromOptions(options, options.emitWarning); | ||
return preparedSources ? preparedSources.concat(compilerArgs) : compilerArgs; | ||
} | ||
function prepareProcessOpts(options) { | ||
var env = _.merge({LANG: 'en_US.UTF-8'}, process.env); | ||
return _.merge({ env: env, stdio: "inherit", cwd: options.cwd }, options.processOpts); | ||
} | ||
function runCompiler(sources, options, pathToMake) { | ||
if (typeof options.spawn !== "function") { | ||
throw "options.spawn was a(n) " + (typeof options.spawn) + " instead of a function."; | ||
} | ||
if (!(sources instanceof Array)) { | ||
throw "compile() received neither an Array nor a String for its sources argument." | ||
var processArgs = prepareProcessArgs(sources, options); | ||
var processOpts = prepareProcessOpts(options); | ||
if (options.verbose) { | ||
console.log(["Running", pathToMake].concat(processArgs || []).join(" ")); | ||
} | ||
options = _.defaults({}, options, defaultOptions); | ||
return options.spawn(pathToMake, processArgs, processOpts); | ||
} | ||
if (typeof options.spawn !== "function") { | ||
throw "options.spawn was a(n) " + (typeof options.spawn) + " instead of a function." | ||
function handleCompilerError(err, pathToMake) { | ||
if ((typeof err === "object") && (typeof err.code === "string")) { | ||
handleError(pathToMake, err); | ||
} else { | ||
console.error("Exception thrown when attempting to run Elm compiler " + JSON.stringify(pathToMake) + ":\n" + err); | ||
} | ||
throw err; | ||
var compilerArgs = compilerArgsFromOptions(options, options.emitWarning); | ||
var processArgs = sources ? sources.concat(compilerArgs) : compilerArgs; | ||
var env = _.merge({LANG: 'en_US.UTF-8'}, process.env); | ||
var processOpts = _.merge({ env: env, stdio: "inherit", cwd: options.cwd }, options.processOpts); | ||
process.exit(1); | ||
} | ||
function compileSync(sources, options) { | ||
var optionsWithDefaults = prepareOptions(options, spawn.sync); | ||
var pathToMake = options.pathToMake || compilerBinaryName; | ||
var verbose = options.verbose; | ||
try { | ||
if (verbose) { | ||
console.log(["Running", pathToMake].concat(processArgs || []).join(" ")); | ||
} | ||
return runCompiler(sources, optionsWithDefaults, pathToMake); | ||
} catch (err) { | ||
handleCompilerError(err, pathToMake); | ||
} | ||
} | ||
return options.spawn(pathToMake, processArgs, processOpts) | ||
function compile(sources, options) { | ||
var optionsWithDefaults = prepareOptions(options, spawn); | ||
var pathToMake = options.pathToMake || compilerBinaryName; | ||
try { | ||
return runCompiler(sources, optionsWithDefaults, pathToMake) | ||
.on('error', function(err) { | ||
handleError(pathToMake, err); | ||
process.exit(1) | ||
process.exit(1); | ||
}); | ||
} catch (err) { | ||
if ((typeof err === "object") && (typeof err.code === "string")) { | ||
handleError(pathToMake, err); | ||
} else { | ||
console.error("Exception thrown when attempting to run Elm compiler " + JSON.stringify(pathToMake) + ":\n" + err); | ||
} | ||
process.exit(1) | ||
handleCompilerError(err, pathToMake); | ||
} | ||
@@ -312,2 +346,3 @@ } | ||
compile: compile, | ||
compileSync: compileSync, | ||
compileWorker: require("./worker.js")(compile), | ||
@@ -314,0 +349,0 @@ compileToString: compileToString, |
{ | ||
"name": "node-elm-compiler", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "A Node.js interface to the Elm compiler binaries. Supports Elm version 0.17", | ||
@@ -36,4 +36,5 @@ "main": "index.js", | ||
"chai-spies": "0.7.1", | ||
"glob": "7.1.1", | ||
"mocha": "3.0.2" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # node-elm-compiler [![Version](https://img.shields.io/npm/v/node-elm-compiler.svg)](https://www.npmjs.com/package/node-elm-compiler) [![Travis build Status](https://travis-ci.org/rtfeldman/node-elm-compiler.svg?branch=master)](http://travis-ci.org/rtfeldman/node-elm-compiler) [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/xv83jcomgb81i1iu/branch/master?svg=true)](https://ci.appveyor.com/project/rtfeldman/node-elm-compiler/branch/master) | ||
Supports Elm version 0.17 | ||
Supports Elm version 0.17, 0.18 | ||
@@ -18,2 +18,6 @@ # Example | ||
## 4.3.0 | ||
Add `compileSync` via @yormi | ||
## 4.2.1 | ||
@@ -20,0 +24,0 @@ |
@@ -12,6 +12,6 @@ { | ||
"dependencies": { | ||
"elm-lang/core": "4.0.0 <= v < 5.0.0", | ||
"elm-lang/html": "1.0.0 <= v < 2.0.0" | ||
"elm-lang/core": "5.0.0 <= v < 6.0.0", | ||
"elm-lang/html": "2.0.0 <= v < 3.0.0" | ||
}, | ||
"elm-version": "0.17.0 <= v < 0.18.0" | ||
"elm-version": "0.18.0 <= v < 0.19.0" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37029
33
764
98
4
8