-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·46 lines (44 loc) · 1.03 KB
/
cli.js
File metadata and controls
executable file
·46 lines (44 loc) · 1.03 KB
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
#!/usr/bin/env node
'use strict';
const { normalize } = require('path');
const { error, success } = require('log-symbols');
const { green, red } = require('chalk');
const dateFormat = require('dateformat');
const inquirer = require('inquirer');
const newGatsbyPost = require('new-gatsby-post');
inquirer
.prompt([
{
type: 'input',
name: 'location',
message: 'Location:',
default: normalize('./src/pages/blog'),
},
{
type: 'input',
name: 'title',
message: 'Title:',
validate: x => (x.length > 0 ? true : '`Title` is required'),
},
{
type: 'input',
name: 'date',
message: 'Date (yyyy-mm-dd):',
default: dateFormat(Date.now(), 'isoDate'),
},
])
.then(answers =>
newGatsbyPost(answers.title, {
location: answers.location,
date: answers.date,
})
)
.then(path => {
console.log();
console.log(success, green('Created:'));
console.log(path);
})
.catch(err => {
console.log();
console.log(error, red(err));
});