-
Notifications
You must be signed in to change notification settings - Fork 264
/
new_feature.js
61 lines (51 loc) · 1.77 KB
/
new_feature.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
'use strict';
var question = require('readline-sync').question;
var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
function promptValue(tag, possibilities, morePossible) {
possibilities = possibilities || [];
morePossible = morePossible || false;
var possibilitiesStr = possibilities.length ? ' (' : '';
if (morePossible) {
possibilitiesStr += 'one or more of: ';
}
possibilities.forEach(function(possibility) {
// avoid trailing commas
if (possibilities[ possibilities.length - 1] !== possibility) {
possibilitiesStr += possibility + ', ';
}
else {
possibilitiesStr += possibility;
}
});
possibilitiesStr += possibilities.length ? ')' : '';
return question('Enter ' + tag + possibilitiesStr + ': ');
}
function writePost(feature, callback) {
var slug = feature.name.replace(' ', '-').toLowerCase();
var filename = slug + '.md';
var file = '';
file += 'feature: ' + feature.name + '\n';
file += 'status: ' + feature.status + '\n';
file += 'tags: ' + feature.tags + '\n';
file += 'kind: ' + feature.kind + '\n';
file += 'polyfillurls:' + '\n';
file += '\n';
file += '...\n';
var filepath = path.join('posts', filename);
fs.writeFile(filepath, file, function() {
callback(filepath);
});
}
var feature = {
name: promptValue('Feature Name'),
status: promptValue('Status', ['use', 'avoid', 'caution']),
tags: promptValue('Tags', ['gtie6', 'gtie7', 'gtie8', 'prefixes', 'polyfill', 'fallback', 'none'], true),
tags: promptValue('Tags', ['gtie7', 'gtie8', 'prefixes', 'polyfill', 'fallback', 'none'], true),
kind: promptValue('Type', ['css', 'html', 'js', 'api', 'svg'])
};
writePost(feature, function(file) {
console.log('Created file ' + file);
exec('open ' + file);
});