Skip to content

Commit

Permalink
Fix #16
Browse files Browse the repository at this point in the history
  • Loading branch information
deadratfink committed Mar 19, 2016
1 parent 873130d commit 27ec4b0
Show file tree
Hide file tree
Showing 8 changed files with 2,134 additions and 2,023 deletions.
4 changes: 2 additions & 2 deletions jyt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ cli.main(function(args, options) {
})
.catch(function (err) {
cli.error('////////////////////////////////////////////////////////////////////////////////');
cli.error(err.stack);
cli.error(err);
cli.debug(err.stack);
cli.error('////////////////////////////////////////////////////////////////////////////////');
cli.getUsage(1);
//cli.fatal('Process exit 1');
});
});
40 changes: 21 additions & 19 deletions lib/options-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function OptionsHandler(logger) {
case Constants.JSON:
return resolve(dot + Constants.JSON);
default:
reject(new Error('Invalid target option found while creating destination file extension: ' + options.target));
return reject(new Error('Invalid target option found while creating destination file extension: ' + options.target));
}
});
}
Expand Down Expand Up @@ -115,19 +115,20 @@ function OptionsHandler(logger) {
* @returns {string} - A type value.
* @private
*/
function getTypeFromFilePath(pathStr, origin, defaultValue) {
var getTypeFromFilePath = function (pathStr, origin, defaultValue) {
var ext = path.extname(pathStr);
self.logInstance.debug('extension: ' + ext);
if (ext.charAt(0) === '.') {
ext = ext.substr(1);
}

var type = typeMap[ext];
if (!type) {
self.logInstance.info('cannot resolve ' + origin ? 'origin' : 'target' + ' type from file ' + pathStr + ', using default: ' + defaultValue);
self.logInstance.info('cannot resolve ' + (origin ? 'origin' : 'target') + ' type from file ' + pathStr + ', using default: ' + defaultValue);
type = defaultValue;
}
return type;
}
};

///////////////////////////////////////////////////////////////////////////////
// OPTIONS INIT & VALIDATION METHODS
Expand All @@ -145,20 +146,21 @@ function OptionsHandler(logger) {
*/
this.copyOptions = function (options) {
return new Promise(function (resolve, reject) {
var srcType;
var destType;
if (options.src) {
srcType = getTypeFromFilePath(options.src, true, Constants.DEFAULT_OPTIONS.origin);
}
self.logInstance.debug('srcType: ' + srcType);
if (options.dest) {
destType = getTypeFromFilePath(options.dest, false, Constants.DEFAULT_OPTIONS.target);
}
self.logInstance.debug('destType: ' + destType);
if (options) {
var srcType;
var destType;
if (options.src) {
srcType = getTypeFromFilePath(options.src, true, Constants.YAML);
}
self.logInstance.debug('srcType: ' + srcType);
if (options.dest) {
self.logInstance.debug('options.dest: ' + options.dest);
destType = getTypeFromFilePath(options.dest, false, Constants.JS);
}
self.logInstance.debug('destType: ' + destType);
resolve({
origin: options.origin === Constants.ORIGIN_DEFAULT ? ( srcType || Constants.YAML) : options.origin,
target: options.target === Constants.TARGET_DEFAULT ? ( destType || Constants.JS) : options.target,
origin: (options.origin && (options.origin !== Constants.ORIGIN_DEFAULT)) ? options.origin : (srcType || Constants.YAML),
target: (options.target && (options.target !== Constants.TARGET_DEFAULT)) ? options.target : (destType || Constants.JS),
src: options.src,
dest: options.dest || Constants.DEFAULT_OPTIONS.dest,
indent: options.indent || Constants.DEFAULT_OPTIONS.indent
Expand All @@ -183,7 +185,7 @@ function OptionsHandler(logger) {

// complain about missing source file
if (!options.src) {
reject(new Error('Pls specify existing input file!'));
return reject(new Error('Pls specify existing input file!'));
}

// check for existing source file
Expand All @@ -195,7 +197,7 @@ function OptionsHandler(logger) {
} else {
err.message = 'Some error occurred while accessing input file \'' + options.src + '\': ' + err.code + ', ' + err.message;
}
reject(err);
return reject(err);
}

resolve(options);
Expand All @@ -221,7 +223,7 @@ function OptionsHandler(logger) {
var destName = path.basename(options.src, srcExt);
options.dest = path.join(destDirName, destName + destExt);
self.logInstance.debug('Destination file: ' + options.dest);
return Promise.resolve(options);
return options;//Promise.resolve(options);
});
} else {
self.logInstance.debug('Destination file: ' + options.dest);
Expand Down
4 changes: 0 additions & 4 deletions test/data/swagger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
'use strict';

var something = 'test';

module.exports = {
swagger: "2.0",
info: {
Expand Down

0 comments on commit 27ec4b0

Please sign in to comment.