-
Notifications
You must be signed in to change notification settings - Fork 21
/
new
executable file
·50 lines (38 loc) · 1.27 KB
/
new
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 );
}
});