Skip to content

Commit

Permalink
Merge branch 'release/0.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhranshu committed Apr 10, 2020
2 parents 43ad866 + 07e13bb commit c4447e6
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"printWidth": 120
"printWidth": 120,
"trailingComma": "es5"
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodejs-starter-template",
"version": "0.0.2",
"version": "0.0.3",
"description": "Template repository to get strated with NodeJs CLI development",
"main": "lib/index.js",
"repository": "git@github.com:shubhranshu/nodeJs-starter-template.git",
Expand All @@ -14,7 +14,9 @@
"watch-run": "npx nodemon --exec npx babel-node src/index.js"
},
"dependencies": {
"chalk": "^4.0.0"
"chalk": "^4.0.0",
"inquirer": "^7.1.0",
"progress": "^2.0.3"
},
"devDependencies": {
"@ava/babel": "^1.0.1",
Expand Down
46 changes: 46 additions & 0 deletions src/ChalkTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Chalk from 'chalk';
class ChalkTest {
test() {
const log = console.log;

// Combine styled and normal strings
log(Chalk.blue('Hello') + ' World' + Chalk.red('!'));

// Compose multiple styles using the chainable API
log(Chalk.blue.bgRed.bold('Hello world!'));

// Pass in multiple arguments
log(Chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));

// Nest styles
log(Chalk.red('Hello', Chalk.underline.bgBlue('world') + '!'));

// Nest styles of the same type even (color, underline, background)
log(
Chalk.green(
'I am a green line ' + Chalk.blue.underline.bold('with a blue substring') + ' that becomes green again!'
)
);

// ES2015 template literal
log(`
CPU: ${Chalk.red('90%')}
RAM: ${Chalk.green('40%')}
DISK: ${Chalk.yellow('70%')}
`);

// // ES2015 tagged template literal
// log(Chalk`
// CPU: {red ${cpu.totalPercent}%}
// RAM: {green ${(ram.used / ram.total) * 100}%}
// DISK: {rgb(255,131,0) ${(disk.used / disk.total) * 100}%}
// `);

// Use RGB colors in terminal emulators that support it.
log(Chalk.keyword('orange')('Yay for orange colored text!'));
log(Chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
log(Chalk.hex('#DEADED').bold('Bold gray!'));
}
}

export { ChalkTest };
103 changes: 103 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import inquirer from 'inquirer';
import ProgressBar from 'progress';

const FruitChoice = {
type: 'list',
name: 'pickFruit',
message: 'Pick ingredients for your smoothie',
help: '',
choices: [
{
name: 'Orange',
value: 'orange',
},
{
name: 'Banan',
value: 'banan',
},
{
name: 'Apple',
value: 'apple',
},
{
name: 'Blackberry',
value: 'blackberry',
},
{
name: 'Kale',
value: 'kale',
},
{
name: 'Strawberry',
value: 'strawberry',
},
{
name: 'Spinach',
value: 'spinach',
},
],
};

const SmoothieBase = {
type: 'list',
name: 'pickBase',
message: 'Now pick your smoothie base',
help: '',
choices: [
{
name: 'Yogurt',
value: 'yogurt',
},
{
name: 'Milk',
value: 'milk',
},
],
};

let AnswerSet = {};

const HandleAnswers = (answers) => {
let questionSet = null;
if (!answers) {
questionSet = FruitChoice;
} else {
AnswerSet = { ...AnswerSet, ...answers };
if (answers.pickFruit) {
questionSet = SmoothieBase;
} else if (answers.pickBase) {
MakeSmoothie(AnswerSet);
}
}
if (questionSet) {
inquirer
.prompt(questionSet)
.then((answers) => HandleAnswers(answers))
.catch((error) => {
if (error.isTtyError) {
console.error('isTtyError');
}
console.error(error);
});
}
};

const MakeSmoothie = (answerSet) => {
console.log(`Making an awesome ${answerSet.pickFruit} ${answerSet.pickBase} smoothie`);
var bar = new ProgressBar(':bar', { total: 80 });
var timer = setInterval(function () {
bar.tick();
if (bar.complete) {
console.log('\nSmoothie Done !\n');
clearInterval(timer);
}
}, 100);
};

class InquirerCli {
start(options) {
HandleAnswers(options);
}
}

export { InquirerCli };
49 changes: 9 additions & 40 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
import Chalk from "chalk";
const log = console.log;
import { ChalkTest } from './ChalkTest';
import { InquirerCli } from './cli';

// Combine styled and normal strings
log(Chalk.blue('Hello') + ' World' + Chalk.red('!'));
console.log('############## Running Chalk test #############');
var chalkTest = new ChalkTest();
chalkTest.test();
console.log('################ Chalk test Done ##############');

// Compose multiple styles using the chainable API
log(Chalk.blue.bgRed.bold('Hello world!'));

// Pass in multiple arguments
log(Chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));

// Nest styles
log(Chalk.red('Hello', Chalk.underline.bgBlue('world') + '!'));

// Nest styles of the same type even (color, underline, background)
log(
Chalk.green(
'I am a green line ' +
Chalk.blue.underline.bold('with a blue substring') +
' that becomes green again!'
)
);

// ES2015 template literal
log(`
CPU: ${Chalk.red('90%')}
RAM: ${Chalk.green('40%')}
DISK: ${Chalk.yellow('70%')}
`);

// // ES2015 tagged template literal
// log(Chalk`
// CPU: {red ${cpu.totalPercent}%}
// RAM: {green ${(ram.used / ram.total) * 100}%}
// DISK: {rgb(255,131,0) ${(disk.used / disk.total) * 100}%}
// `);

// Use RGB colors in terminal emulators that support it.
log(Chalk.keyword('orange')('Yay for orange colored text!'));
log(Chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
log(Chalk.hex('#DEADED').bold('Bold gray!'));
console.log('################ CLI Demo Begins ##############');
var cli = new InquirerCli();
cli.start();
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ ini@^1.3.5, ini@~1.3.0:
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==

inquirer@^7.0.0:
inquirer@^7.0.0, inquirer@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.1.0.tgz#1298a01859883e17c7264b82870ae1034f92dd29"
integrity sha512-5fJMWEmikSYu0nv/flMc475MhGbB7TSPd/2IpFV4I4rMklboCH2rQjYY5kKiYGHqUF9gvaambupcJFFG9dvReg==
Expand Down Expand Up @@ -3563,7 +3563,7 @@ process-nextick-args@~2.0.0:
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==

progress@^2.0.0:
progress@^2.0.0, progress@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
Expand Down

0 comments on commit c4447e6

Please sign in to comment.