Skip to content

Commit e971858

Browse files
committed
feat(order): write order to file
1 parent 05f2cd2 commit e971858

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

bin/order.bin.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
const commander = require('commander');
33
const version = require('../package').version;
44
const waiter = require('../src/waiter');
5+
const fileAccess = require('../src/file-access');
56

67
commander
78
.version(version)
89
.arguments('<food> <drink>')
910
.option(
10-
'-w --wine-card [string]',
11-
'Additional to the food and drink you want to order the wine card'
11+
'-w --write <string>',
12+
'Specifies the path of the file the order will be written to'
1213
)
1314
.action(function(food, drink) {
14-
const includeWineCard = commander.wineCard;
15-
waiter.order(food, drink);
15+
const fileName = commander.write;
16+
waiter.placeOrder(food, drink);
17+
if (fileName) {
18+
fileAccess.writeFile(fileName, { food, drink });
19+
}
1620
})
1721
.parse(process.argv);

src/file-access.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const chalk = require('chalk');
2+
const jsonfile = require('jsonfile');
3+
4+
function writeFile(fileName, order) {
5+
jsonfile.writeFile(fileName, order, function(err) {
6+
if (err) {
7+
console.log(chalk.red(err));
8+
} else {
9+
console.log(chalk.green(`Success`));
10+
}
11+
});
12+
}
13+
14+
module.exports = { writeFile };

src/waiter.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ const orderTitle =
1010
' \\__, |\\___/ \\__,_|_| \\___/|_| \\__,_|\\___|_| \n' +
1111
' |___/ \n';
1212

13-
function order(food, drink) {
13+
function placeOrder(food, drink) {
1414
const foodOrder = `${chalk.green(
1515
'You ordered the following food: '
1616
)} ${chalk.blue.bold(food)} \n`;
1717
const drinkOrder = `${chalk.green(
1818
'You ordered the following drink: '
1919
)} ${chalk.blue.bold(drink)}`;
2020

21-
console.log(
22-
`${orderTitle} ${boxen(foodOrder + drinkOrder, {
23-
padding: 1,
24-
margin: 1,
25-
borderStyle: 'round'
26-
})}`
27-
);
21+
const order = `${orderTitle} ${boxen(foodOrder + drinkOrder, {
22+
padding: 1,
23+
margin: 1,
24+
borderStyle: 'round'
25+
})}`;
26+
27+
console.log(order);
2828
}
2929

30-
module.exports = { order };
30+
module.exports = { placeOrder };

0 commit comments

Comments
 (0)