-
Notifications
You must be signed in to change notification settings - Fork 2
/
cleanshave
executable file
·50 lines (45 loc) · 1.25 KB
/
cleanshave
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'),
opts = require('nomnom')
.options({
'template':{
abbr: 't',
help: 'Path to the template file or dir'
},
'dest': {
help: 'The destination directory',
abbr: 'd'
},
'amd': {
help: 'Creates the domplate using the AMD pattern',
flag: true
},
'node': {
help: 'Creates the domplate using the CommonJS module pattern, compatible with browserify.',
flag: true
}
}).parse();
var FileIO = require('./src/fileIO'),
io = new FileIO(opts);
var finish = function(){
console.log('All done!');
process.exit(0);
};
var templateStat = fs.statSync(opts.template),
singleTemplate = opts.template && templateStat.isFile(),
templateDir = opts.template && templateStat.isDirectory();
if(opts.dest && opts.dest.substr(-1, 1) !== '/') opts.dest += '/';
//template and destination defined
if(singleTemplate && opts.dest){
io.createSingle(opts.template, opts.dest, finish);
//template dir and dest dir
} else if(templateDir && opts.dest) {
if(opts.template.substr(-1, 1) !== '/') opts.template += '/';
io.createBatch(opts.template, opts.dest, finish);
//template only defined, use stdout
} else if(singleTemplate){
io.createSingle(opts.template, process.stdout, function(){
//exit without any message
process.exit(0);
});
}