-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from stanislavt/refactor/cli
Add bin script and do code refactoring
- Loading branch information
Showing
11 changed files
with
344 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
#ATB Plastic bag | ||
# ATB Plastic bag | ||
|
||
<img src="http://www.comserv.com.ua/images/stories/klienty/12.jpg" /> | ||
![Plastic bag](http://www.comserv.com.ua/images/stories/klienty/12.jpg) | ||
|
||
ATB Plastic Bag likes to travel around the world and take a lot of photos. The next photo will be taken in your project. So, how to do it: | ||
## Installation: | ||
|
||
ATB Plactic Bag likes to travel around the world. | ||
And we bring it to your project | ||
just run | ||
``` | ||
npm install atbmarket --save | ||
``` | ||
and add to your entry JS script: | ||
``` | ||
require('atbmarket')(); | ||
npm install atbmarket -g | ||
``` | ||
|
||
ATB has solutions for all situations: | ||
## Add to your entry JS script: | ||
|
||
``` | ||
require('atbmarket')('big'); | ||
require('atbmarket')('little'); | ||
require('atbmarket')(); //render default size bag | ||
const Provision = require('atbmarket'); | ||
const bag = new Provision(); | ||
bag.draw() // Draw the bag in terminal | ||
bag.caption() // Show a caption in terminal | ||
bag.chalk() // Show both bag and caption in terminal | ||
``` | ||
|
||
## Or just run it in terminal: | ||
|
||
`atbmarket` draws plastic bag in terminal. | ||
|
||
`atbmarket --help` shows more details. | ||
|
||
### Options: | ||
|
||
``` | ||
-V, --version output the version number | ||
-S, --size <size> Choose size (default: medium) | ||
--no-colorized [value] Is supposed to be not colorized? | ||
-h, --help output usage information | ||
``` | ||
|
||
Enjoy and show ATB the world of your production! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env node | ||
|
||
const program = require('commander'); | ||
const Provision = require('../lib/bags/provision'); | ||
const { version } = require('../package'); | ||
|
||
program | ||
.version(version) | ||
.option('-S, --size <size>', 'Choose size', /^(large|medium|small)$/i, 'medium') | ||
.option('--no-colorized [value]', 'Is supposed to be not colorized?') | ||
.parse(process.argv); | ||
|
||
const { size, colorized } = program; | ||
|
||
const factory = new Provision({ size, colorized }); | ||
factory.chalk() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const chalk = require('chalk'); | ||
|
||
module.exports = class Bag { | ||
/** | ||
* @param {object} options | ||
* @param {boolean=true} options.colorized | ||
*/ | ||
constructor({ colorized = true }) { | ||
this.colorized = colorized; | ||
} | ||
|
||
/** | ||
* Print the bag with capture | ||
*/ | ||
chalk(){ | ||
this.draw().caption(); | ||
} | ||
|
||
/** | ||
* Set colors of the bag | ||
*/ | ||
get colors() { | ||
if (this.colorized) { | ||
const { bgWhite, bgBlue, white: tWhite, blue: tBlue, magenta: tRed } = chalk; | ||
|
||
return { bgWhite, bgBlue, tWhite, tBlue, tRed }; | ||
} else { | ||
const { bgWhite, bgBlackBright: bgBlue, white: tWhite, black: tBlue, black: tRed } = chalk; | ||
|
||
return { bgWhite, bgBlue, tWhite, tBlue, tRed }; | ||
} | ||
} | ||
|
||
set colorized(value) { | ||
this._colorized = Boolean(value); | ||
} | ||
|
||
get colorized() { | ||
return this._colorized; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const Bag = require('./bag') | ||
|
||
module.exports = class MediumBag extends Bag { | ||
/** | ||
* @param {object} options | ||
* @param {boolean=true} options.colorized | ||
*/ | ||
constructor({ colorized = true }) { | ||
super({ colorized }) | ||
} | ||
|
||
/** | ||
* Draw the package in console | ||
*/ | ||
draw() { | ||
const { bgWhite, bgBlue, tWhite, tBlue, tRed } = this.colors; | ||
|
||
console.log(` | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} | ||
${bgWhite(' ' + tBlue('▥▥▥') + ' ')} | ||
${bgWhite(' ')} | ||
${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('᛫¯¯᨞') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('⁄ ') + tRed('АТБ') + tWhite(' ⁄') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('᨞__᛫') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')} | ||
${bgWhite(' ')} | ||
`); | ||
|
||
return this; | ||
} | ||
|
||
caption() { | ||
console.log('Even an ATB market plastic bag (L size) was there... What about you?!') | ||
|
||
return this; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const Bag = require('./bag') | ||
|
||
module.exports = class MediumBag extends Bag { | ||
/** | ||
* @param {object} options | ||
* @param {boolean=true} options.colorized | ||
*/ | ||
constructor({ colorized = true }) { | ||
super({ colorized }) | ||
} | ||
|
||
/** | ||
* Draw the package in console | ||
*/ | ||
draw() { | ||
const { bgWhite, bgBlue, tWhite, tBlue, tRed } = this.colors; | ||
|
||
console.log(` | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ' + tBlue('▥▥') + ' ')} | ||
${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('᛫¯¯᨞') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('⁄ ') + tRed('АТБ') + tWhite(' ⁄') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('᨞__᛫') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')} | ||
`); | ||
|
||
return this; | ||
} | ||
|
||
caption() { | ||
console.log('Even an ATB market plastic bag (M size) was there... What about you?!') | ||
|
||
return this; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const SIZE = require('./size'); | ||
|
||
module.exports = class Provision { | ||
/** | ||
* Create a new instance of plastic bag | ||
* @param {object} options | ||
* @param {string='middle'} options.size | ||
* @param {boolean=true} options.colorized | ||
*/ | ||
constructor({ size = SIZE.MIDDLE, colorized = true } = {}) { | ||
this.registerBags(); | ||
this.size = size; | ||
this.colorized = colorized; | ||
|
||
return new this.currentBag({ colorized: this.colorized }); | ||
} | ||
|
||
registerBags() { | ||
const sizes = [ | ||
[SIZE.SMALL, require('./small')], | ||
[SIZE.MEDIUM, require('./medium')], | ||
[SIZE.LARGE, require('./large')], | ||
]; | ||
|
||
this._bags = new Map(sizes); | ||
} | ||
|
||
set colorized(value) { | ||
this._colorized = Boolean(value); | ||
} | ||
|
||
get colorized() { | ||
return this._colorized; | ||
} | ||
|
||
set size(value) { | ||
this._size = value; | ||
} | ||
|
||
get size() { | ||
return this._size; | ||
} | ||
|
||
get currentBag() { | ||
if (this._bags.has(this.size)) { | ||
return this._bags.get(this.size); | ||
} | ||
|
||
return this._bags.get(SIZE.MEDIUM); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
SMALL: 'small', | ||
MEDIUM: 'medium', | ||
LARGE: 'large' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const Bag = require('./bag') | ||
|
||
module.exports = class SmallBag extends Bag { | ||
/** | ||
* @param {object} options | ||
* @param {boolean=true} options.colorized | ||
*/ | ||
constructor({ colorized = true }) { | ||
super({ colorized }) | ||
} | ||
|
||
/** | ||
* Draw the package in console | ||
*/ | ||
draw() { | ||
const { bgWhite, bgBlue, tWhite, tBlue, tRed } = this.colors; | ||
|
||
console.log(` | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ')} ${bgWhite(' ')} | ||
${bgWhite(' ' + tBlue('▥') + ' ')} | ||
${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('᛫¯¯᨞') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('⁄ ') + tRed('АТБ') + tWhite(' ⁄') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ' + tWhite('᨞__᛫') + ' ')}${bgWhite(' ')} | ||
${bgWhite(' ')}${bgBlue(' ')}${bgWhite(' ')} | ||
${bgWhite(' ')} | ||
`); | ||
|
||
return this; | ||
} | ||
|
||
caption() { | ||
console.log('Even an ATB market plastic bag (S size) was there... What about you?!'); | ||
|
||
return this; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1 @@ | ||
'use strict'; | ||
|
||
const chalk = require('chalk'); | ||
|
||
let init = function (size) { | ||
switch (size) { | ||
case 'little': | ||
littleSize(); | ||
break; | ||
case 'big': | ||
bigSize(); | ||
break; | ||
default: | ||
middleSize(); | ||
break; | ||
} | ||
}; | ||
|
||
function littleSize() { | ||
console.info(` | ||
${chalk.bgWhite(' ')} ${chalk.bgWhite(' ')} | ||
${chalk.bgWhite(' ')} ${chalk.bgWhite(' ' + chalk.black('▥') + ' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('-') + ' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('(') + chalk.red('ATB') + chalk.blue(')') + ' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('-') + ' ')} | ||
${chalk.bgWhite(' ')} | ||
${chalk.blue('Even an ATB market plastic bag (L) was there... What about you?!')} | ||
`); | ||
} | ||
|
||
function middleSize() { | ||
console.info(` | ||
${chalk.bgWhite(' ')} ${chalk.bgWhite(' ')} | ||
${chalk.bgWhite(' ')} ${chalk.bgWhite(' ')} | ||
${chalk.bgWhite(' ')} ${chalk.bgWhite(' ' + chalk.black('▥▥') + ' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('-') + ' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('(') + chalk.red('ATB') + chalk.blue(')') + ' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('-') + ' ')} | ||
${chalk.bgWhite(' ')} | ||
${chalk.blue('Even an ATB market plastic bag (M) was there... What about you?! ')} | ||
`); | ||
} | ||
|
||
function bigSize() { | ||
console.info(` | ||
${chalk.bgWhite(' ')} ${chalk.bgWhite(' ')} | ||
${chalk.bgWhite(' ')} ${chalk.bgWhite(' ')} | ||
${chalk.bgWhite(' ')} ${chalk.bgWhite(' ' + chalk.black('▥▥▥') + ' ')} | ||
${chalk.bgWhite(' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('-') + ' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('(') + chalk.red('ATB') + chalk.blue(')') + ' ')} | ||
${chalk.bgWhite(' ' + chalk.blue('-') + ' ')} | ||
${chalk.bgWhite(' ')} | ||
${chalk.blue('Even an ATB market plastic bag (XL) was there... What about you?!')} | ||
`); | ||
} | ||
|
||
module.exports = init; | ||
module.exports = require('./bags/provision'); |
Oops, something went wrong.