Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e055d338f0
Fetching contributors…

Cannot retrieve contributors at this time

executable file 50 lines (38 sloc) 1.304 kb
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
#!/usr/bin/env node

var fs = require("fs"),
    colors = require("colors"),
    cp = require("child_process"),
    _ = require("underscore"),
    exec = cp.exec,

    args = process.argv.slice(2),
    spec, path;


if ( !args.length ) {
  console.log( "Please specify a new test 'spec' to create." );
  process.exit();
}

spec = (args[ 0 ]).trim();
path = "tests/" + spec;

fs.readdir( path, function( err, files ) {

  if ( err !== null && !/No such file/.test(err) ) {
    exec( "cp -r tests/boilerplate/ " + path, function( err, stdout, stderr ) {

      if ( err === null ) {

        console.log( "Copied!".green );

        fs.readdir( path, function( err, files ) {
          files.forEach(function( file ) {
            var target = path + "/" + file,
                source = fs.readFileSync( target ).toString(),
                out = fs.openSync( target, "w+" ),
                title = spec.split("-").map(function(val) {
                  return val[0].toUpperCase() + val.slice(1);
                }).join(" ");

            spec
            fs.writeSync( out, _.template( source, { spec: spec, title: title }) );
          });

          console.log( "Configured!".green );
        });
      }
    });
  } else {
    console.log( ("Directory: " + path + " already exists").red );
  }
});
Something went wrong with that request. Please try again.