1
0
Fork 0

Moved blabber-cli functionality into core

This commit is contained in:
sharpshark28 2017-01-21 18:44:23 -06:00
parent eba27a607b
commit 1522a80831
4 changed files with 86 additions and 2 deletions

View file

@ -8,7 +8,30 @@
Powered by Node and a node-canvas a comic can automatically be generated from a json array of users/text and some characters/backgrounds to be chosen at random.
## How to use it
## How to use it from the CLI
### Installing
`npm install -g blabber`
### Using
```
$ blabber
$ Who?: Glen
$ Said What?: Test 1
$ Another? (y/n) y
$ Who?: Sarah
$ Said What?: Test 2
$ Another? (y/n) y
$ Who?: Glen
$ Said What?: Test 3
$ Another? (y/n) n
$ Generating Comic...
$ [ Comic Generated @ comics/1.png ]
```
## How to use it in other projects
### Generate base64Data

56
blabber.js Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const prompt = require('prompt');
const blabberComic = require('./');
prompt.start();
const promptMessage = [{
description: 'Who?',
name: 'user'
}, {
description: 'Said what?',
name: 'text'
}];
const promptMore = {
description: 'Another? y/n',
pattern: /y|n/i,
message: 'Please type y(es) or n(o) for More',
default: 'y',
};
function askForMessage(callback, conversation = []) {
prompt.get(promptMessage, (error, response) => {
conversation.push(response);
callback(conversation);
});
}
function askIfMore(conversation) {
prompt.get(promptMore, (error, response) => {
let shouldContinue = response.question.toLowerCase() === 'y';
if (shouldContinue) askForMessage(askIfMore, conversation);
else generate(conversation);
});
}
function generate(conversation) {
console.log('Generating Comic...');
blabberComic(conversation)
.then(rawBase64 => rawBase64.replace(/^data:image\/png;base64,/, ''))
.then(base64 => {
let filename = Math.floor(Date.now() + Math.random()) + '.png';
fs.writeFile(filename, base64, 'base64', error => {
if(error) throw error;
else console.log('[ Comic Generated @ ' + filename + ' ]');
});
})
.catch(error => { console.error('Uhoh... something went wrong.', error); });
}
askForMessage(askIfMore);

0
index.js Normal file → Executable file
View file

View file

@ -6,6 +6,9 @@
"scripts": {
"test": "node test.js"
},
"bin": {
"blabber": "./blabber.js"
},
"keywords": [
"comic",
"generate",
@ -18,6 +21,8 @@
"dependencies": {
"canvas": "^1.6.2",
"fs": "0.0.1-security",
"lodash": "^4.16.6"
"lodash": "^4.16.6",
"prompt": "^1.0.0",
"yargs": "^6.6.0"
}
}