Skip to content
This repository was archived by the owner on Jan 20, 2020. It is now read-only.

Commit 57b8dcd

Browse files
author
Luciano Nooijen
committed
Started progress on CLI
1 parent dce7612 commit 57b8dcd

File tree

5 files changed

+377
-13
lines changed

5 files changed

+377
-13
lines changed

cli/add-post.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function addPost() {
2+
console.log('AddPost Working!');
3+
}
4+
5+
export default addPost;

cli/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* tslint:disable: no-console */
2+
3+
import chalk from 'chalk';
4+
import figlet from 'figlet';
5+
import inquirer from 'inquirer';
6+
7+
import addPost from './add-post';
8+
9+
const prompt = inquirer.createPromptModule();
10+
const choices = ['Add post'];
11+
const question = {
12+
choices,
13+
name: 'action',
14+
type: 'list',
15+
message: 'Please select the action you wish to perform',
16+
};
17+
18+
const intro = () => {
19+
console.clear();
20+
console.log(
21+
chalk.yellow(
22+
figlet.textSync('NodeJS Blog', { horizontalLayout: 'full' })));
23+
};
24+
25+
const promptHandler = async () => {
26+
const answer = await prompt([question]) as any; // Hack to avoid error...
27+
if (answer.action === 'Add post') {
28+
addPost();
29+
}
30+
};
31+
32+
const cli = async () => {
33+
intro();
34+
await promptHandler();
35+
};
36+
37+
cli();

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"scripts": {
3636
"dev": "nodemon",
37+
"cli": "ts-node cli/index.ts",
3738
"start": "ts-node server/server.ts",
3839
"build": "tsc",
3940
"lint": "yarn run lint:js && yarn run lint:ts",
@@ -65,10 +66,13 @@
6566
"devDependencies": {
6667
"@types/eslint": "^4.16.4",
6768
"@types/express": "^4.16.0",
69+
"@types/figlet": "^1.2.0",
70+
"@types/inquirer": "^0.0.43",
6871
"@types/jest": "^23.3.9",
6972
"@types/knex": "^0.15.1",
7073
"@types/node": "^10.12.9",
7174
"babel-eslint": "^10.0.1",
75+
"clui": "^0.3.6",
7276
"eslint": "^4.19.1",
7377
"eslint-config-airbnb": "^16.1.0",
7478
"eslint-plugin-import": "^2.12.0",
@@ -78,7 +82,10 @@
7882
"eslint-plugin-prettier": "^3.0.0",
7983
"eslint-plugin-react": "^7.8.2",
8084
"eslint-plugin-security": "^1.4.0",
85+
"figlet": "^1.2.1",
86+
"inquirer": "^6.2.1",
8187
"jest": "^23.6.0",
88+
"minimist": "^1.2.0",
8289
"nodemon": "^1.18.6",
8390
"prettier": "^1.15.2",
8491
"prettier-eslint": "^8.8.2",

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
/* Basic Options */
4-
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
4+
"target": "es2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
55
"lib": ["es2015"],
6-
"module": "amd", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
77
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
88
"declaration": true, /* Generates corresponding '.d.ts' file. */
99
"sourceMap": true, /* Generates corresponding '.map' file. */

0 commit comments

Comments
 (0)