-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (67 loc) · 2.29 KB
/
index.js
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
#! /usr/bin/env node
var generate = require('project-name-generator');
var commandLineArgs = require('command-line-args');
var color = require('cli-color');
const optionDefinitions = [
{ name: 'help', type: Boolean },
{ name: 'nodash', type: Boolean },
{ name: 'addnumber', type: Boolean },
{ name: 'words', type: Number },
{ name: 'count', type: Number },
{ name: 'alliterative', type: Boolean },
{ name: 'letter', type: String }
];
const options = commandLineArgs(optionDefinitions);
if (options.help) {
console.log(color.yellow('release-codename [options]'));
console.log(color.green('--nodash') + ' - output with spaces instead of using a dash');
console.log(color.green('--addnumber') + ' - add a random number to the codename');
console.log(color.green('--words=#') + ' - specify the number of words in the codename');
console.log(color.green('--count=#') + ' - specify the number of codenames to display');
console.log(color.green('--alliterative') + ' - make alliterative codenames');
console.log(color.green('--letter="s"') + ' - make alliterative codenames starting with this letter');
process.exit(0);
}
const genOptions = getGenOptions(options);
var codenames = [];
// default to 1 codename
if (!options.count)
options.count = 1;
// default to dashes not spaces
if (options.nodash === undefined)
options.nodash = false;
for (var i = 0, l = options.count; i < l; i++) {
codenames.push(getCodename(options.nodash, genOptions));
}
if (options.count === 1)
console.log(color.yellow.underline('Your codename is:'));
else
console.log(color.yellow.underline('Your codenames are:'));
codenames.forEach(c => {
console.log(color.red.bold(c));
});
////////////////////
function getGenOptions(opts) {
var genOptions = {};
var setOption = false;
if (opts.words) {
genOptions.words = opts.words;
setOption = true;
}
if (opts.addnumber) {
genOptions.number = true;
setOption = true;
}
if (opts.alliterative) {
genOptions.alliterative = true;
setOption = true;
}
if (opts.letter) {
genOptions.alliterative = opts.letter.substring(0, 1).toLowerCase();
setOption = true;
}
return setOption ? genOptions : null;
}
function getCodename(useSpaces, genOptions) {
return useSpaces ? generate(genOptions).spaced : generate(genOptions).dashed;
}