Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update new_feature.js #484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 32 additions & 38 deletions new_feature.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,55 @@
'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) {
const readlineSync = require('readline-sync');
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');

function promptValue(tag, possibilities = [], multiple = false) {
let possibilitiesStr = possibilities.length ? ' (' : '';
if (multiple) {
possibilitiesStr += 'one or more of: ';
}

possibilities.forEach(function(possibility) {
// avoid trailing commas
if (possibilities[ possibilities.length - 1] !== possibility) {
possibilitiesStr += possibility + ', ';
}
else {
possibilitiesStr += possibility;
possibilities.forEach((possibility, index) => {
possibilitiesStr += possibility;
if (index < possibilities.length - 1) {
possibilitiesStr += ', ';
}
});
possibilitiesStr += possibilities.length ? ')' : '';

return question('Enter ' + tag + possibilitiesStr + ': ');
return readlineSync.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() {
const slug = feature.name.replace(/ /g, '-').toLowerCase();
const filename = `${slug}.md`;
const fileContent = `
feature: ${feature.name}
status: ${feature.status}
tags: ${feature.tags}
kind: ${feature.kind}
polyfillurls:

...
`;

const filepath = path.join('posts', filename);
fs.writeFile(filepath, fileContent.trim(), (err) => {
if (err) throw err;
callback(filepath);
});
}

var feature = {
const 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);
writePost(feature, (file) => {
console.log(`Created file ${file}`);
exec(`open ${file}`);
});