Code coverage report for lib/pioneer.js

Statements: 53.13% (34 / 64)      Branches: 30% (9 / 30)      Functions: 50% (6 / 12)      Lines: 53.13% (34 / 64)      Ignored: none     

All files » lib/ » pioneer.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 1111 1   1   1   1   1   1   1   1   1 1 1 1 1 1                                 1                                               1               1             1 2 2 2   1 1       1 2     1 8 4   8 5   3       1       1      
(function() {
  var Pioneer, color, configBuilder, cucumber, fs, moment, path, scaffoldBuilder;
 
  moment = require('moment');
 
  fs = require('fs');
 
  path = require('path');
 
  configBuilder = require('./config_builder');
 
  scaffoldBuilder = require('./scaffold_builder');
 
  color = require('colors');
 
  cucumber = require('cucumber');
 
  Pioneer = (function() {
    function Pioneer(libPath, args) {
      var configPath, p;
      Eif (this.isVersionRequested(args)) {
        console.log(require('../package').version);
        return;
      }
      if (args.configPath && fs.existsSync(args.configPath)) {
        configPath = args.configPath;
      } else if (args.scaffold) {
        scaffoldBuilder.createScaffold();
      } else {
        p = path.join(process.cwd(), '/pioneer.json');
        if (fs.existsSync(p)) {
          configPath = p;
        } else {
          configPath = null;
        }
      }
      this.getSpecifications(configPath, libPath, args);
    }
 
    Pioneer.prototype.getSpecifications = function(path, libPath, args) {
      var configObject;
      configObject = {};
      if (path) {
        return fs.readFile(path, 'utf8', (function(_this) {
          return function(err, data) {
            if (err) {
              throw err;
            }
            configObject = _this.parseAndValidateJSON(data, path);
            if (_this.isVerbose(args, configObject)) {
              console.log(('Configuration loaded from ' + path).yellow.inverse);
            }
            return _this.applySpecifications(configObject, libPath, args);
          };
        })(this));
      } else {
        if (this.isVerbose(args, configObject)) {
          console.log('No configuration path specified'.yellow.inverse);
        }
        return this.applySpecifications(configObject, libPath, args);
      }
    };
 
    Pioneer.prototype.applySpecifications = function(obj, libPath, args) {
      var opts;
      opts = configBuilder.generateOptions(args, obj, libPath);
      if (opts) {
        return this.start(opts);
      }
    };
 
    Pioneer.prototype.start = function(opts) {
      require('./environment')();
      return cucumber.Cli(opts).run(function(success) {
        return process.exit(success ? 0 : 1);
      });
    };
 
    Pioneer.prototype.parseAndValidateJSON = function(config, path) {
      var err;
      try {
        return JSON.parse(config);
      } catch (_error) {
        err = _error;
        throw new Error(path + " does not include a valid JSON object.\n");
      }
    };
 
    Pioneer.prototype.isVersionRequested = function(args) {
      return args.version || args.v;
    };
 
    Pioneer.prototype.isVerbose = function(args, config) {
      if (config == null) {
        config = {};
      }
      if (args.verbose != null) {
        return args.verbose && args.verbose !== "false";
      } else {
        return !!config.verbose;
      }
    };
 
    return Pioneer;
 
  })();
 
  module.exports = Pioneer;
 
}).call(this);