Code coverage report for lib/scaffold_builder.js

Statements: 67.39% (31 / 46)      Branches: 37.5% (6 / 16)      Functions: 22.22% (2 / 9)      Lines: 67.39% (31 / 46)      Ignored: none     

All files » lib/ » scaffold_builder.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 851 1   1   1   1   1   1   1                                   7 7 7 7   7 7 7   7 7 7   7 7 7   7 7 7   7 7 7 7 7       7 7                                              
(function() {
  var color, fs, path, prompt, _;
 
  fs = require('fs');
 
  path = require('path');
 
  prompt = require('prompt');
 
  color = require('colors');
 
  _ = require('lodash');
 
  module.exports = {
    featureNotSpecified: function() {
      prompt.start();
      return prompt.get({
        message: "You did not specify a feature path. Would you like Pioneer to generate one for you? y/n",
        required: true
      }, (function(_this) {
        return function(err, r) {
          if (['y', 'yes'].indexOf(r.question.toLowerCase()) > -1) {
            return _this.createScaffold();
          } else {
            console.log('Looks like you have no feature files or have not passed the path to them. http://www.github.com/mojotech/pioneer/docs');
            return process.exit();
          }
        };
      })(this));
    },
    createScaffold: function(options) {
      var features, fixtures, hiddenPioneer, p, steps, widgets;
      p = path.join(process.cwd(), '/tests');
      Eif (!fs.existsSync(p)) {
        fs.mkdirSync(p);
      }
      features = path.join(p, '/features');
      Eif (!fs.existsSync(features)) {
        fs.mkdirSync(features);
      }
      fixtures = path.join(p, '/fixtures');
      Eif (!fs.existsSync(fixtures)) {
        fs.mkdirSync(fixtures);
      }
      widgets = path.join(p, '/widgets');
      Eif (!fs.existsSync(widgets)) {
        fs.mkdirSync(widgets);
      }
      steps = path.join(p, '/steps');
      Eif (!fs.existsSync(steps)) {
        fs.mkdirSync(steps);
      }
      fs.writeFileSync(path.join(features, 'simple.feature'), fs.readFileSync(path.join(__dirname, "scaffold/simple.txt"), 'utf8'));
      fs.writeFileSync(path.join(steps, 'simple.js'), fs.readFileSync(path.join(__dirname, "scaffold/simple.js"), 'utf8'));
      hiddenPioneer = path.join(process.cwd(), '/pioneer.json');
      Eif (!fs.existsSync(hiddenPioneer)) {
        fs.writeFileSync(hiddenPioneer, fs.readFileSync(path.join(__dirname, "scaffold/example.json"), 'utf8'));
      } else {
        this.askToOverWrite(hiddenPioneer, fs.readFileSync(path.join(__dirname, "scaffold/example.json"), 'utf8'));
      }
      this._logCompleted();
      return process.exit();
    },
    askToOverWrite: function(file, data) {
      prompt.start();
      return prompt.get({
        message: "It looks like you already have a " + file + " , are you sure that you would like to overwrite this? y/n",
        required: true
      }, (function(_this) {
        return function(err, r) {
          if (['y', 'yes'].indexOf(r.question.toLowerCase()) > -1) {
            return fs.writeFileSync(file, data);
          } else {
            return console.log("You chose not to overwrite " + file + " to run the scaffold files include tests/features in the feature option of your config files.");
          }
        };
      })(this));
    },
    _logCompleted: function() {
      return console.log('Scaffold created. You may now run your first test'.inverse.green);
    }
  };
 
}).call(this);