X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/2f579cf4c0d8ff95af78103783c7ca8f951cc797..442ebaf901a8ca686ce769325054e1f393d43b7c:/bin/blog.js diff --git a/bin/blog.js b/bin/blog.js deleted file mode 100755 index 3f5db43..0000000 --- a/bin/blog.js +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env node -import Config from '../config/config.js'; -import Blog from '../lib/blog.js'; -import Minimist from 'minimist'; - -const internals = { - blog: new Blog(Config), - expectedKeys: [ - 'add', - 'generate', - 'update', - 'publish', - 'publish-archive', - 'add-remote', - 'remove-remote', - 'sync-up', - 'sync-down', - 'version'], - - // 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 === 'version') { - console.log('6.0.0'); - return; - } - - if (argument === 'add') { - await internals.blog.add(value); - return; - } - - if (argument === 'update') { - await internals.blog.update(value); - return; - } - - if (argument === 'generate') { - await internals.blog.generate(); - return; - } - - if (argument === 'publish') { - await internals.blog.publish(value); - return; - } - - if (argument === 'publish-archive') { - await internals.blog.publishArchive(value); - return; - } - - if (argument === 'add-remote') { - await internals.blog.addRemote(value); - return; - } - - if (argument === 'remove-remote') { - await internals.blog.removeRemote(); - return; - } - - if (argument === 'sync-up') { - await internals.blog.syncUp(); - return; - } - - if (argument === 'sync-down') { - await internals.blog.syncDown(); - 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 \t\t(creates new blog post)'); - console.error('blog --update \t\t(updates latest blog post)'); - console.error('blog --generate \t\t\t(generates the blog assets)'); - console.error('blog --publish \t\t(publishes the blog to an S3 bucket)'); - console.error('blog --publish-archive \t(publishes the archive to a remote host)'); - console.error('blog --add-remote \t\t(adds or updates a git remote to sync with)'); - console.error('blog --remove-remote \t\t\t(removes the git remote)'); - console.error('blog --sync-up \t\t\t\t(pushes to the git remote if configured)'); - console.error('blog --sync-down \t\t\t(pulls from the git remote if configured)'); - console.error('blog --version \t\t\t\t(print the version)'); - } -}; - -// 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();