Commit 2c07e154 by Adeel

API: Resolve input, output and map w.r.t. cwd.

Issue URL: #731.
Pull Request: #732.
parent 65619ba4
...@@ -27,25 +27,48 @@ function getBinding() { ...@@ -27,25 +27,48 @@ function getBinding() {
} }
/** /**
* Get outfile * Get input file
* *
* @param {Object} options * @param {Object} options
* @api private * @api private
*/ */
function getOutFile(options) { function getInputFile(options) {
var file = options.file; return options.file ? path.resolve(options.file) : null;
}
/**
* Get output file
*
* @param {Object} options
* @api private
*/
function getOutputFile(options) {
var outFile = options.outFile; var outFile = options.outFile;
if (!outFile || typeof outFile !== 'string' || (!options.data && !file)) { if (!outFile || typeof outFile !== 'string' || (!options.data && !options.file)) {
return null; return null;
} }
if (path.resolve(outFile) === path.normalize(outFile).replace(/(.+)([\/|\\])$/, '$1')) { return path.resolve(outFile);
return outFile; }
/**
* Get source map
*
* @param {Object} options
* @api private
*/
function getSourceMap(options) {
var sourceMap = options.sourceMap;
if (sourceMap && typeof sourceMap !== 'string' && options.outFile) {
sourceMap = options.outFile + '.map';
} }
return path.resolve(path.dirname(file), outFile); return sourceMap ? path.resolve(sourceMap) : null;
} }
/** /**
...@@ -99,29 +122,6 @@ function getStyle(options) { ...@@ -99,29 +122,6 @@ function getStyle(options) {
} }
/** /**
* Get source map
*
* @param {Object} options
* @api private
*/
function getSourceMap(options) {
var file = options.file;
var outFile = options.outFile;
var sourceMap = options.sourceMap;
if (sourceMap) {
if (typeof sourceMap !== 'string') {
sourceMap = outFile ? outFile + '.map' : '';
} else if (outFile) {
sourceMap = path.resolve(path.dirname(file), sourceMap);
}
}
return sourceMap;
}
/**
* Get options * Get options
* *
* @param {Object} options * @param {Object} options
...@@ -132,8 +132,8 @@ function getOptions(options, cb) { ...@@ -132,8 +132,8 @@ function getOptions(options, cb) {
options = options || {}; options = options || {};
options.sourceComments = options.sourceComments || false; options.sourceComments = options.sourceComments || false;
options.data = options.data || null; options.data = options.data || null;
options.file = options.file || null; options.file = getInputFile(options);
options.outFile = getOutFile(options); options.outFile = getOutputFile(options);
options.includePaths = (options.includePaths || []).join(path.delimiter); options.includePaths = (options.includePaths || []).join(path.delimiter);
options.precision = parseInt(options.precision) || 5; options.precision = parseInt(options.precision) || 5;
options.sourceMap = getSourceMap(options); options.sourceMap = getSourceMap(options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment