Browse Source

Make a nicer command-line interface

pull/6/head
Domenic Denicola 6 years ago
parent
commit
59b82e7ab4
8 changed files with 100 additions and 27 deletions
  1. +1
    -1
      .editorconfig
  2. +1
    -3
      .gitignore
  3. +2
    -0
      README.md
  4. +0
    -0
      lib/scaffold.js
  5. +86
    -23
      lib/worm-scraper.js
  6. +3
    -0
      package.json
  7. +6
    -0
      scaffolding/container.xml
  8. +1
    -0
      scaffolding/mimetype

+ 1
- 1
.editorconfig View File

@ -8,5 +8,5 @@ charset = utf-8
indent_style = space
indent_size = 2
[out/mimetype]
[scaffolding/mimetype]
insert_final_newline = false

+ 1
- 3
.gitignore View File

@ -2,6 +2,4 @@
/npm-debug.log
cache/
out/
!out/mimetime
!out/META-INF/
book/

+ 2
- 0
README.md View File

@ -1,3 +1,5 @@
# _Worm_ Scraper
Scrapes the web serial [_Worm_](https://parahumans.wordpress.com/) into an ebook format.
Install globally and run `worm-scraper --help` for usage.

lib/extras.js → lib/scaffold.js View File


+ 86
- 23
lib/worm-scraper.js View File

@ -2,37 +2,100 @@
const path = require("path");
const mkdirp = require("mkdirp-then");
const rimraf = require("rimraf-then");
const yargs = require("yargs");
const cpr = require("thenify")(require("cpr"));
const packageJson = require("../package.json");
const download = require("./download.js");
const convert = require("./convert.js");
const extras = require("./extras.js");
const scaffold = require("./scaffold.js");
require("./track-rejections.js");
const START_CHAPTER_URL = "https://parahumans.wordpress.com/2011/06/11/1-1/";
const argv = yargs
.usage(`${packageJson.description}\n\n${packageJson.name} [<command1> [<command2> [<command3> ...]]]\n\n` +
"Each command will fail if the previously-listed one has not yet been run (with matching options).")
.command("download", "download all chapters by crawling parahumans.wordpress.com")
.command("convert", "convert the raw chapter HTML files into cleaned-up ebook chapters")
.command("scaffold", "assemble the table of contents, etc. to complete the EPUB")
.command("zip", "zip up the EPUB files into a .epub output")
.option("s", {
alias: "start-url",
default: "https://parahumans.wordpress.com/2011/06/11/1-1/",
describe: "the URL from which to start crawling, for the download command",
requiresArg: true
})
.option("c", {
alias: "cache-directory",
default: "cache",
describe: "cache directory, for the download and convert commands",
requiresArg: true
})
.option("b", {
alias: "book-directory",
default: "book",
describe: "directory in which to assemble the EPUB files before zipping, for the convert, scaffold, and zip " +
"commands",
requiresArg: true
})
.option("o", {
alias: "out",
default: "Worm.epub",
describe: "output file destination, for the zip command",
requiresArg: true
})
.require(1) // TODO remove and allow all
.addHelpOpt("help")
.version(packageJson.version, "version")
.argv;
const cachePath = path.resolve("cache");
const outPath = path.resolve("out");
const cachePath = path.resolve(argv.cacheDirectory);
const manifestPath = path.resolve(cachePath, "manifest.json");
const scaffoldingPath = path.resolve(__dirname, "../scaffolding");
const outPath = path.resolve(argv.bookDirectory);
const contentPath = path.resolve(outPath, "OEBPS");
const chaptersPath = path.resolve(contentPath, "chapters");
const manifestPath = path.resolve(cachePath, "manifest.json");
Promise.resolve()
// .then(function () {
// return download(START_CHAPTER_URL, cachePath, manifestPath);
// })
// .then(function () {
// return rimraf(chaptersPath);
// })
// .then(function () {
// return mkdirp(chaptersPath);
// })
.then(function () {
return convert(cachePath, manifestPath, chaptersPath);
})
.then(function () {
return extras(contentPath, chaptersPath, manifestPath);
})
.then(function () {
console.log("All done!");
const commands = [];
if (argv._.indexOf("download") !== -1) {
commands.push(function () {
return download(argv.startUrl, cachePath, manifestPath);
});
}
if (argv._.indexOf("convert") !== -1) {
commands.push(function () {
return rimraf(chaptersPath).then(function () {
return mkdirp(chaptersPath);
})
.then(function () {
return convert(cachePath, manifestPath, chaptersPath);
});
});
}
if (argv._.indexOf("scaffold") !== -1) {
commands.push(function () {
return cpr(scaffoldingPath, outPath).then(function () {
return scaffold(contentPath, chaptersPath, manifestPath);
});
});
}
if (argv._.indexOf("zip") !== -1) {
commands.push(function () {
console.log("Not yet implemented!");
});
}
commands.reduce(function (previous, command) {
return previous.then(command);
}, Promise.resolve())
.then(function () {
console.log("All done!");
})
.catch(function (e) {
console.error(e.stack);
});

+ 3
- 0
package.json View File

@ -19,13 +19,16 @@
"lint": "eslint lib && jscs lib"
},
"dependencies": {
"cpr": "^0.4.0",
"jsdom": "^5.3.0",
"mkdirp-then": "^1.0.1",
"requisition": "^1.5.0",
"rimraf-then": "^1.0.0",
"thenify": "^3.1.0",
"throat": "^2.0.2",
"xmlserializer": "^0.3.3",
"xtend": "^4.0.0",
"yargs": "^3.9.1",
"zfill": "0.0.2"
},
"devDependencies": {


+ 6
- 0
scaffolding/container.xml View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>

+ 1
- 0
scaffolding/mimetype View File

@ -0,0 +1 @@
application/epub+zip

Loading…
Cancel
Save