Make a nicer command-line interface
This commit is contained in:
parent
46e38a2859
commit
59b82e7ab4
8 changed files with 101 additions and 28 deletions
|
|
@ -8,5 +8,5 @@ charset = utf-8
|
|||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[out/mimetype]
|
||||
[scaffolding/mimetype]
|
||||
insert_final_newline = false
|
||||
|
|
|
|||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -2,6 +2,4 @@
|
|||
/npm-debug.log
|
||||
|
||||
cache/
|
||||
out/
|
||||
!out/mimetime
|
||||
!out/META-INF/
|
||||
book/
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 contentPath = path.resolve(outPath, "OEBPS");
|
||||
const chaptersPath = path.resolve(contentPath, "chapters");
|
||||
const cachePath = path.resolve(argv.cacheDirectory);
|
||||
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 scaffoldingPath = path.resolve(__dirname, "../scaffolding");
|
||||
const outPath = path.resolve(argv.bookDirectory);
|
||||
const contentPath = path.resolve(outPath, "OEBPS");
|
||||
const chaptersPath = path.resolve(contentPath, "chapters");
|
||||
|
||||
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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
scaffolding/container.xml
Normal file
6
scaffolding/container.xml
Normal 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
scaffolding/mimetype
Normal file
1
scaffolding/mimetype
Normal file
|
|
@ -0,0 +1 @@
|
|||
application/epub+zip
|
||||
Loading…
Add table
Add a link
Reference in a new issue