This repository has been archived by the owner on Jun 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
scaffolt
executable file
·80 lines (63 loc) · 2.12 KB
/
scaffolt
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
#!/usr/bin/env node
var program = require('commander');
var argv = process.argv;
program
.version(require('./package.json').version)
.usage('<type> <name> [options]')
.option('-p, --parentPath [path]', 'override path to directory to which recipe will be copied')
.option('-r, --revert', 'should scaffolt revert changes done by previous scaffolding?')
.option('-g, --generators [path]', 'path to directory which contains generators specifications [./generators]')
.option('-l, --list', 'list availables generators')
.option('-d, --doc [type]', 'display generator documentation');
program.on('--help', function() {
console.log(' Examples:');
console.log('');
console.log(' scaffolt view user');
console.log(' scaffolt model cart --revert');
console.log(' scaffolt controller header --path controllers/regions/header.coffee');
console.log(' scaffolt --list');
console.log(' scaffolt collection --doc');
console.log('');
});
program.parse(process.argv);
var args = program.args;
var count = args.length;
var first = args[0];
var type, name;
var scaffolt = require('./');
if (program.list) {
scaffolt.list({
generatorsPath: program.generators
});
} else if (program.doc) {
if (count < 1) program.help();
if ([program.doc].indexOf(first) === -1) {
type = first;
} else {
type = args[count - 1];
}
scaffolt.help(type, {generatorsPath: program.generators});
} else {
if (count < 2) program.help();
if ([program.parentPath, program.revert, program.generators].indexOf(first) === -1) {
type = first;
name = args[1];
} else {
type = args[count - 2];
name = args[count - 1];
}
if (!type || !name) program.help();
var templateData = {
parentPath: program.parentPath,
generatorsPath: program.generators,
revert: program.revert
};
// Add args with prefix `$`
var entry, colon;
for(var i = 0; i < args.length ; i++) {
templateData["$" + i.toString()] = (entry = args[i]);
if (-1 != (colon = entry.indexOf(':')))
templateData["@" + entry.substring(0, colon)] = entry.substring(colon + 1);
}
scaffolt(type, name, templateData);
}