Add command line arguments

This commit is contained in:
Daniel Jönsson 2018-03-13 14:01:18 +01:00
parent 273b752cf4
commit f8f1870c71
3 changed files with 53 additions and 13 deletions

View file

@ -5,7 +5,7 @@ fimfic2epub
This is a tool to generate better EPUB ebooks from [fimfiction](https://fimfiction.net/) stories. It's also a Chrome/Firefox extension, replacing the default EPUB download option with this tool.
[Screenshot](http://i.imgbox.com/MalEBiuC.png) of Chrome extension
[Screenshot](http://i.imgbox.com/MalEBiuC.png) of the Chrome extension
Demo
----
@ -14,18 +14,17 @@ You can have a look at what a generated EPUB looks like [here](http://books.djaz
Usage (browser extension)
-----------------
You can download the Chome extension from [Chrome Web Store](https://chrome.google.com/webstore/detail/fimfic2epub/fiijkoniocipeemlflajmmaecfhfcand) and [Firefox Add-ons](https://addons.mozilla.org/firefox/addon/fimfic2epub/)
Installation & usage (command line)
-------------------
You can install the tool by running `npm install -g fimfic2epub`. You can then run it like this:
`$ fimfic2epub <story id/url> [<optional filename>]`
By default the EPUB will be saved in the current working directory with the filename `Title by Author.epub`. You can set filename to `-` and the epub will be emitted to stdout instead.
By default the EPUB will be saved in the current working directory with the filename `Title by Author.epub`. Run `fimfic2epub --help` to see a list of all flags.
Examples
--------
@ -42,13 +41,11 @@ $ fimfic2epub 180690 - > path/to/file.epub
Building
--------
Make sure [Node.js](https://nodejs.org) is installed. After you've cloned this repository, run `npm install` and `npm run build` to build it. This project uses [gulp](http://gulpjs.com/). Run `npm run dev` for a quicker development build. You can add `watch` to both for automatic rebuilding.
Development
-----------
Make sure [gulp is installed](https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md).
When working on the code and testing it in a web browser as an extension, you can run gulp in watch mode: `gulp watch`. This will lint code and build it when you save. To build, just run `gulp` or `npm run build`. To lint, run `gulp lint` and to clean, run `gulp clean`.

View file

@ -1,34 +1,76 @@
#!/usr/bin/env node
const args = require('commander')
.command('fimfic2epub <story id|url> [filename]')
.description(require('../package.json').description)
.version(require('../package.json').version)
.option('-t, --title <value>', 'Set the title of the story')
.option('-a, --author <value>', 'Set the author of the story')
.option('-c, --no-comments-link', 'Don\'t add link to online comments')
.option('-h, --no-headings', 'Don\'t add headings to chapters')
.option('-e, --no-external', 'Don\'t embed external resources, such as images (breaks EPUB spec)')
.option('-n, --no-notes', 'Don\'t include author notes')
.option('-i, --notes-index', 'Create an index with all author notes at the end of the ebook')
.option('-p, --paragraphs <style>', 'Select a paragraph style [spaced|indented|indentedall|both]', 'spaced')
.option('-j, --join-subjects', 'Join subjects to a single value')
.option('-r, --reading-ease', 'Calculate Flesch reading ease (slow for long stories)')
.option('-C, --cover <url>', 'Set cover image url')
.parse(process.argv)
if (args.args.length < 1) {
console.error('Error: No story id/url provided')
process.exit(1)
}
// use a mock DOM so we can run mithril on the server
require('mithril/test-utils/browserMock')(global)
const FimFic2Epub = require('../dist/fimfic2epub')
const fs = require('fs')
const STORY_ID = process.argv[2]
const STORY_ID = args.args[0]
const ffc = new FimFic2Epub(STORY_ID)
const ffc = new FimFic2Epub(STORY_ID, {
addCommentsLink: !!args.commentsLink,
includeAuthorNotes: !!args.notes,
useAuthorNotesIndex: !!args.notesIndex,
addChapterHeadings: !!args.headings,
includeExternal: !!args.external,
paragraphStyle: args.paragraphs,
joinSubjects: !!args.joinSubjects,
calculateReadingEase: !!args.readingEase
})
ffc.coverUrl = args.cover
const outputStdout = process.argv[3] === '-' || process.argv[3] === '/dev/stdout'
const outputStdout = args.args[1] === '-' || args.args[1] === '/dev/stdout'
if (outputStdout) {
console.log = console.error
console.log('Outputting to stdout')
}
/*
ffc.on('progress', (percent, status) => {
/*
if (status) {
console.log('fimfic2epub: ' + status)
}
*/
})
*/
ffc.fetchAll()
ffc.fetchMetadata()
.then(() => {
if (args.title) {
ffc.setTitle(args.title)
}
if (args.author) {
ffc.setAuthorName(args.author)
}
})
.then(ffc.fetchAll.bind(ffc))
.then(ffc.build.bind(ffc))
.then(() => {
let filename = process.argv[3] || ffc.filename
let filename = (args.args[1] || '').replace('%id%', ffc.storyInfo.id) || ffc.filename
let stream
if (outputStdout) {

View file

@ -20,6 +20,7 @@
"bin/"
],
"dependencies": {
"commander": "^2.15.0",
"detect-node": "^2.0.3",
"escape-string-regexp": "^1.0.5",
"file-type": "^7.2.0",