-
Notifications
You must be signed in to change notification settings - Fork 1
/
volofile
115 lines (98 loc) · 3.92 KB
/
volofile
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var FS = require('fs'),
BEM_PREFIX = 'bem-';
module.exports = {
onCreate: function(d, v, namedArgs, projectName) {
var date = new Date(),
day = date.getDate(),
month = date.getMonth() + 1,
year = date.getFullYear();
// Add leading zero to month
if (String(month).length < 2) month = '0' + month;
var dateStr = day + '.' + month + '.' + year;
var defaultCommand = projectName.indexOf(BEM_PREFIX) === 0 ? projectName.slice(BEM_PREFIX.length)
: projectName;
v.prompt('Command name(' + defaultCommand + '):')
.then(function(command) {
if (!command || command.length === 0) {
command = defaultCommand;
}
return [command, v.prompt('Github login:')];
})
.spread(function(command, login) {
return [command, login, v.prompt('Author name:')];
})
.spread(function(command, login, name) {
return [
command,
login,
name,
v.prompt('Author email:')
];
})
.spread(function(command, login, name, email) {
return [
command,
login,
name,
email,
v.prompt('Github path (in organization/repo format):')
];
})
.spread(function(command, login, name, email, ghPath) {
var ghUrl = 'github.com/' + ghPath;
var packageName = BEM_PREFIX + command,
packageUpper = packageName.toUpperCase();
// Update the files that reference this project by name
[
'package.json',
'index.js',
'GNUmakefile',
'ChangeLog.md',
'README.md.in',
'LICENSE',
'bin/app.in',
'lib/coa.js',
'lib/command.js'
].forEach(function(file) {
var res = v.template(v.read(file), {
app: packageName,
command: command,
APP: packageUpper,
APP_ENV: packageUpper.replace(/-/g, '_'),
authorName: name,
authorEmail: email,
githubUrl: ghUrl,
githubPath: ghPath,
githubLogin: login,
year: year,
date: dateStr
});
if (file === 'package.json') {
res = res.replace('"app"', '"' + packageName + '"');
}
v.write(file, res);
});
// Rename bin/app.in to bin/{app} and make it executable
var from = 'bin/app.in',
to = 'bin/' + packageName;
v.mv(from, to);
FS.chmodSync(to, '0755');
// Rename README.md.in to README.md
v.mv('README.md.in', 'README.md');
// Rename command file
v.mv('lib/command.js', 'lib/' + command + '.js');
// Remove this volofile
v.rm('volofile');
console.log([
'Project directory is ready!',
'',
'Do not forget to',
'- run `npm init` to initialize npm package',
'- run `git init` to create git repository',
'- review CONTRIBUTING.md',
'- commit your project'
].join('\n'));
d.resolve();
});
}
};