bin/van

Summary

Maintainability
Test Coverage
#!/usr/bin/env node

var format = require('chalk');
var fs = require('fs');
var argv = require('minimist')(process.argv.slice(2), {alias: {c: ['config']}});

function errorOut(message, code) {
  code = code || 1
  process.stderr.write(format.red("Error: ") + message + "\n");
  process.exit(code);
}

function loadVanfile() {
  if (argv.c) {
    if (fs.existsSync(process.cwd() + argv.c)) {
      return require(process.cwd() + argv.c);
    } else {
      errorOut("Could not load file at location " + format.bold(argv.c));
    }
  } else {
    // TODO: Make this crawl up the directory tree
    if (fs.existsSync(process.cwd() + "/Vanfile.js")) {
      return require(process.cwd() + "/Vanfile.js");
    } else {
      errorOut("Could not find " + format.bold("Vanfile.js") + " in this directory");
    }
  }
}

var van = loadVanfile()

if (argv._[0] === 'run') {
  van.run();
} else if (argv._[0] === 'start') {
  van.start();
  
  process.on('SIGINT', function() {
    van.stop('SIGINT');
  });
}