diff options
| author | Ben Beltran <ben@nsovocal.com> | 2017-07-03 00:26:08 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2017-07-03 00:26:08 -0500 |
| commit | cf6302904d61ead65e6294e7f1be406eb68ef5f9 (patch) | |
| tree | 2d034809bbf8db2db79e413ace9cab44a7044ae6 /bin | |
| parent | 7a5a585ead8c4e967980adc2ab9c7502e47694fd (diff) | |
✨📝🔧 Add generator bin and files
Includes config for eslint, and jsdoc, plus the executable
Squashed commit of the following:
commit 7726a2743994800f5c0afbc23e5b529107b79450
Author: Ben Beltran <ben@nsovocal.com>
Date: Mon Jul 3 00:25:43 2017 -0500
Update changelog
commit 78ad8ab788020c09848a852e48827781aa17341a
Author: Ben Beltran <ben@nsovocal.com>
Date: Mon Jul 3 00:25:38 2017 -0500
Remove unused image
commit 1cd659307a39669cf0fc8d0f676b25625fd16ba2
Author: Ben Beltran <ben@nsovocal.com>
Date: Mon Jul 3 00:23:53 2017 -0500
Remove trailing slash on index
commit 944160fcbc364e4a829be91e6ad32521b4f94987
Author: Ben Beltran <ben@nsovocal.com>
Date: Mon Jul 3 00:21:50 2017 -0500
Add example blog post
commit 70645d0214d5d363accfedc3e2583e97232c930e
Author: Ben Beltran <ben@nsovocal.com>
Date: Mon Jul 3 00:20:44 2017 -0500
✨ Add binary / generator to lib
commit bb8f8bb6e12c89bc4b9b3766fd2ef8e924422005
Author: Ben Beltran <ben@nsovocal.com>
Date: Mon Jul 3 00:20:29 2017 -0500
🔧 Add package.json
commit 7e9b6f52c1c91bf963319ddeb1696bfac4130b95
Author: Ben Beltran <ben@nsovocal.com>
Date: Mon Jul 3 00:19:57 2017 -0500
🔧 Add eslint config
commit 26ee06bbf1c2f20620c81fa94c4a9b40460bd401
Author: Ben Beltran <ben@nsovocal.com>
Date: Mon Jul 3 00:19:31 2017 -0500
Move static files to template / static
commit db84351cbb8e8c4729123650d1cb3a6150da0502
Author: Ben Beltran <ben@nsovocal.com>
Date: Sun Jul 2 21:39:20 2017 -0500
Use a hidden name for posts directory
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/blog.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/bin/blog.js b/bin/blog.js new file mode 100755 index 0000000..c88a8aa --- /dev/null +++ b/bin/blog.js @@ -0,0 +1,92 @@ +#!/usr/bin/env node +'use strict'; + +const Config = require('../config/config'); +const Blog = require('..'); +const Minimist = require('minimist'); + +const internals = { + blog: new Blog(Config), + expectedKeys: ['add', 'update', 'publish'], + + // Application entry point. Reads arguments and calls the + // corresponding method from the blog lib + + async main() { + + try { + const parsedArguments = this._parseArguments(); + + for (const argument in parsedArguments) { + if (parsedArguments.hasOwnProperty(argument)) { + + const value = parsedArguments[argument]; + + if (argument === 'add') { + await internals.blog.add(value); + return; + } + + if (argument === 'update') { + await internals.blog.update(value); + return; + } + + if (argument === 'publish') { + await internals.blog.update(value); + return; + } + } + } + console.log('Not yet implemented'); + } + catch (err) { + console.error(err.message || err); + this._printUsage(); + process.exit(1); + } + }, + + // Parses arguments and returns them if valid. otherwise Throws + + _parseArguments() { + + const parsedArguments = Minimist(process.argv.slice(2)); + + if (!this._areArgumentsValid(parsedArguments)) { + throw new Error(internals.strings.invalidArguments); + } + + return parsedArguments; + }, + + // Checks if the arguments are valid, returns a boolean value. + + _areArgumentsValid(parsedArguments) { + + const argumentKeys = Object.keys(parsedArguments); + + return argumentKeys.some((key) => internals.expectedKeys.indexOf(key) >= 0); + }, + + // Prints the usage to stderr + + _printUsage() { + + console.error('\nUsage:\n'); + console.error('blog --add path/to/blog_post\t\t(creates new blog post)'); + console.error('blog --update path/to/blog_post\t(updates latest blog post)'); + console.error('blog --publish \t\t\t(publishes the blog)'); + } +}; + +// Add the strings, added after declaration so they can consume the +// internals object. + +internals.strings = { + invalidArguments: `Invalid Arguments, expecting one of: ${internals.expectedKeys.join(', ')}` +}; + + + +internals.main(); |