-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsketchplate
executable file
·87 lines (75 loc) · 1.81 KB
/
sketchplate
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
#!/usr/bin/env node
//#Sketchplate
//##by [Kyle Phillips](http://hapticdata.com)
var program = require('commander'),
async = require('async'),
path = require('path'),
fs = require('fs'),
sketchplate = require('../lib/sketchplate'),
hooks = require('../lib/hooks'),
spawn = require('win-spawn'),
configLocation = '../config.json',
config;
config = require( configLocation );
config.templatesPath = path.normalize( __dirname +'/'+ config.templatesPath );
//handle the `new` command
program
.version(require('../package').version)
.usage('<command> [options]');
program.on('--help', function(){
var l = console.log;
l(' Commands:');
l('');
l(' new [options] <location>');
l(' create a new project at <location> with hooks for [options]');
l();
l(' fetch [options] [names…]');
l(' perform resource fetches on your templates');
l();
l(' template [options] [command]');
l(' perform commands on your sketchplate templates');
l();
l(' config [options] [command]');
l(' perform hooks on existing projects');
l();
process.exit();
});
program.parse(process.argv);
// args void of cmd
var args = process.argv.slice(3);
// command
var cmd = program.args[0];
// display help
if (!cmd) {
process.stdout.write(program.helpInformation());
program.emit('--help');
process.exit();
}
var commands = {
fetch: function(){
cmd = 'template';
args.unshift('fetch');
spwn( cmd );
},
template: function(){
spwn( cmd );
},
config: function(){
spwn( cmd );
}
};
commands['new'] = function(){
spwn(cmd);
};
if( commands[cmd] ){
commands[cmd]();
}
function spwn( cmd ){
// executable
var bin = 'sketchplate-' + cmd;
// local
var local = path.join(__dirname, bin);
if (fs.existsSync(local)) bin = local;
// spawn
var proc = spawn(bin, args, { stdio: 'inherit', customFds: [0,1,2] });
}