From d5157f2c22801944242962c6536be3bda978df7a Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 2 Jan 2017 20:11:37 -0500 Subject: [PATCH] Update dev dependencies and use new JS features --- .eslintrc | 32 ------ .eslintrc.json | 259 ++++++++++++++++++++++++++++++++++++++++++++ .jscsrc | 24 ---- lib/convert.js | 44 ++++---- lib/download.js | 23 ++-- lib/jsdom.js | 13 ++- lib/scaffold.js | 23 ++-- lib/worm-scraper.js | 45 +++----- lib/zip.js | 6 +- package.json | 6 +- 10 files changed, 331 insertions(+), 144 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.json delete mode 100644 .jscsrc diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 5860cf9..0000000 --- a/.eslintrc +++ /dev/null @@ -1,32 +0,0 @@ -{ - "ecmaFeatures": { - "binaryLiterals": true, - "blockBindings": true, - "classes": true, - "forOf": true, - "generators": true, - "objectLiteralShorthandMethods": true, - "objectLiteralShorthandProperties": true, - "octalLiterals": true, - "templateStrings": true - }, - "env": { - "node": true - }, - "rules": { - "no-extra-parens": 2, - "no-inner-declarations": 0, - "consistent-return": 0, - "no-eq-null": 2, - "no-floating-decimal": 2, - "no-self-compare": 2, - "no-throw-literal": 2, - "no-void": 2, - "wrap-iife": [2, "outside"], - "strict": [2, "global"], - "no-use-before-define": [2, "nofunc"], - "no-var": 2, - "generator-star-spacing": [2, "after"], - "object-shorthand": [2, "always"] - } -} diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..205a94e --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,259 @@ +{ + "root": true, + "env": { + "node": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 2017 + }, + "rules": { + // Possible errors + "no-await-in-loop": "off", + "comma-dangle": ["error", "never"], + "no-cond-assign": ["error", "except-parens"], + "no-console": "off", + "no-constant-condition": "error", + "no-control-regex": "error", + "no-debugger": "error", + "no-dupe-args": "error", + "no-dupe-keys": "error", + "no-duplicate-case": "error", + "no-empty": "error", + "no-empty-character-class": "error", + "no-ex-assign": "error", + "no-extra-boolean-cast": "error", + "no-extra-parens": ["error", "all", { "conditionalAssign": false, "nestedBinaryExpressions": false }], + "no-extra-semi": "error", + "no-func-assign": "error", + "no-inner-declarations": "off", + "no-invalid-regexp": "error", + "no-irregular-whitespace": "error", + "no-obj-calls": "error", + "no-prototype-builtins": "error", + "no-regex-spaces": "error", + "no-sparse-arrays": "error", + "no-template-curly-in-string": "error", + "no-unexpected-multiline": "error", + "no-unreachable": "error", + "no-unsafe-finally": "off", + "no-unsafe-negation": "error", + "use-isnan": "error", + "valid-jsdoc": "off", + "valid-typeof": "error", + + // Best practices + "accessor-pairs": "error", + "array-callback-return": "error", + "block-scoped-var": "off", + "class-methods-use-this": "error", + "complexity": "off", + "consistent-return": "error", + "curly": ["error", "all"], + "default-case": "off", + "dot-location": ["error", "property"], + "dot-notation": "error", + "eqeqeq": "error", + "guard-for-in": "off", + "no-alert": "error", + "no-caller": "error", + "no-case-declarations": "error", + "no-div-regex": "off", + "no-else-return": "error", + "no-empty-function": "error", + "no-empty-pattern": "error", + "no-eq-null": "error", + "no-eval": "error", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-label": "error", + "no-fallthrough": "error", + "no-floating-decimal": "error", + "no-global-assign": "error", + "no-implicit-coercion": "error", + "no-implicit-globals": "error", + "no-implied-eval": "off", + "no-invalid-this": "error", + "no-iterator": "error", + "no-labels": ["error", { "allowLoop": true }], + "no-lone-blocks": "error", + "no-loop-func": "off", + "no-magic-numbers": "off", + "no-multi-spaces": "error", + "no-multi-str": "error", + "no-new": "error", + "no-new-func": "error", + "no-new-wrappers": "error", + "no-octal": "error", + "no-octal-escape": "error", + "no-param-reassign": "off", + "no-process-env": "error", + "no-proto": "error", + "no-redeclare": "error", + "no-restricted-properties": "off", + "no-return-assign": ["error", "except-parens"], + "no-return-await": "error", + "no-script-url": "off", + "no-self-assign": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-throw-literal": "error", + "no-unmodified-loop-condition": "error", + "no-unused-expressions": "error", + "no-unused-labels": "error", + "no-useless-call": "error", + "no-useless-concat": "error", + "no-useless-escape": "error", + "no-useless-return": "error", + "no-void": "error", + "no-warning-comments": "off", + "no-with": "error", + "radix": ["error", "as-needed"], + "require-await": "error", + "vars-on-top": "off", + "wrap-iife": ["error", "outside"], + "yoda": ["error", "never"], + + // Strict Mode + "strict": ["error", "global"], + + // Variables + "init-declarations": "off", + "no-catch-shadow": "error", + "no-delete-var": "error", + "no-label-var": "error", + "no-restricted-globals": "off", + "no-shadow": "error", + "no-shadow-restricted-names": "error", + "no-undef": "error", + "no-undef-init": "error", + "no-undefined": "off", + "no-unused-vars": "error", + "no-use-before-define": ["error", "nofunc"], + + // Node.js and CommonJS + "callback-return": "off", + "global-require": "error", + "handle-callback-err": "error", + "no-mixed-requires": ["error", true], + "no-new-require": "error", + "no-path-concat": "error", + "no-process-exit": "error", + "no-restricted-imports": "off", + "no-restricted-modules": "off", + "no-sync": "off", + + // Stylistic Issues + "array-bracket-spacing": ["error", "never"], + "block-spacing": ["error", "always"], + "brace-style": ["error", "1tbs", { "allowSingleLine": false }], + "camelcase": ["error", { "properties": "always" }], + "capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }], + "comma-spacing": ["error", { "before": false, "after": true }], + "comma-style": ["error", "last"], + "computed-property-spacing": ["error", "never"], + "consistent-this": "off", + "eol-last": "error", + "func-call-spacing": ["error", "never"], + "func-name-matching": ["error", "always"], + "func-names": ["error", "never"], + "func-style": ["error", "declaration"], + "id-blacklist": "off", + "id-length": "off", + "id-match": "off", + "indent": ["error", 2, { "SwitchCase": 1 }], + "jsx-quotes": "off", + "key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "strict" }], + "keyword-spacing": ["error", { "before": true, "after": true }], + "line-comment-position": "off", + "linebreak-style": ["error", "unix"], + "lines-around-comment": "off", + "lines-around-directive": "off", + "max-depth": "off", + "max-len": ["error", 120, { "ignoreUrls": true }], + "max-lines": "off", + "max-nested-callbacks": "off", + "max-params": "off", + "max-statements": "off", + "max-statements-per-line": ["error", { "max": 1 }], + "multiline-ternary": "off", + "new-cap": "error", + "new-parens": "error", + "newline-after-var": "off", + "newline-before-return": "off", + "newline-per-chained-call": "off", + "no-array-constructor": "error", + "no-bitwise": "off", + "no-continue": "off", + "no-inline-comments": "off", + "no-lonely-if": "error", + "no-mixed-operators": "error", + "no-mixed-spaces-and-tabs": "error", + "no-multiple-empty-lines": "error", + "no-negated-condition": "off", + "no-nested-ternary": "error", + "no-new-object": "error", + "no-plusplus": "off", + "no-restricted-syntax": "off", + "no-tabs": "error", + "no-ternary": "off", + "no-trailing-spaces": "error", + "no-underscore-dangle": "off", + "no-unneeded-ternary": "error", + "no-whitespace-before-property": "error", + "object-curly-newline": ["error", { "multiline": true }], + "object-curly-spacing": ["error", "always"], + "object-property-newline": "off", + "one-var": ["error", "never"], + "one-var-declaration-per-line": ["error", "initializations"], + "operator-assignment": ["error", "always"], + "operator-linebreak": ["error", "after"], + "padded-blocks": ["error", "never"], + "quote-props": ["error", "as-needed"], + "quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }], + "require-jsdoc": "off", + "semi": ["error", "always"], + "semi-spacing": "error", + "sort-keys": "off", + "sort-vars": "off", + "space-before-blocks": ["error", "always"], + "space-before-function-paren": ["error", { "anonymous": "always", "named": "never" }], + "space-in-parens": ["error", "never"], + "space-infix-ops": "error", + "space-unary-ops": ["error", { "words": true, "nonwords": false }], + "spaced-comment": ["error", "always", { "markers": ["///"] }], + "unicode-bom": ["error", "never"], + "wrap-regex": "off", + + // ECMAScript 6 + "arrow-body-style": "off", // meh + "arrow-parens": ["error", "as-needed"], + "arrow-spacing": "error", + "constructor-super": "error", + "generator-star-spacing": ["error", "after"], + "no-class-assign": "error", + "no-confusing-arrow": "off", + "no-const-assign": "error", + "no-dupe-class-members": "error", + "no-duplicate-imports": "error", + "no-new-symbol": "error", + "no-this-before-super": "error", + "no-useless-computed-key": "error", + "no-useless-constructor": "error", + "no-useless-rename": "error", + "no-var": "error", + "object-shorthand": "error", + "prefer-arrow-callback": "error", + "prefer-const": "error", + "prefer-numeric-literals": "error", + "prefer-rest-params": "error", + "prefer-spread": "error", + "prefer-template": "off", + "require-yield": "error", + "rest-spread-spacing": ["error", "never"], + "sort-imports": "off", + "symbol-description": "error", + "template-curly-spacing": ["error", "never"], + "yield-star-spacing": ["error", "after"] + } +} diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 869be5b..0000000 --- a/.jscsrc +++ /dev/null @@ -1,24 +0,0 @@ -{ - "esnext": true, - "preset": "crockford", - "requireMultipleVarDecl": null, - "disallowDanglingUnderscores": null, - "disallowKeywords": [ - "with" - ], - "disallowMultipleVarDecl": "strict", - "validateQuoteMarks": "\"", - "validateIndentation": 2, - "disallowSpaceAfterObjectKeys": true, - "disallowSpacesInCallExpression": true, - "disallowYodaConditions": true, - "maximumLineLength": { - "value": 120, - "allowUrlComments": true - }, - "requireFunctionDeclarations": true, - "requireSemicolons": true, - "validateLineBreaks": "LF", - "validateParameterSeparator": ", ", - "requireBlocksOnNewline": 1 -} diff --git a/lib/convert.js b/lib/convert.js index 6bc9dba..1f15ab1 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -2,23 +2,21 @@ const path = require("path"); const fs = require("mz/fs"); const throat = require("throat"); -const serializeToXml = require("xmlserializer").serializeToString; +const serializeToXML = require("xmlserializer").serializeToString; const jsdom = require("./jsdom.js"); const substitutions = require("./substitutions.json"); -module.exports = function (cachePath, manifestPath, contentPath) { - return fs.readFile(manifestPath, { encoding: "utf-8" }).then(function (manifestContents) { +module.exports = (cachePath, manifestPath, contentPath) => { + return fs.readFile(manifestPath, { encoding: "utf-8" }).then(manifestContents => { const chapters = JSON.parse(manifestContents); console.log("All chapters downloaded; beginning conversion to EPUB chapters"); - const mapper = throat(10, function (chapter) { + const mapper = throat(10, chapter => { return convertChapter(chapter, cachePath, contentPath); }); return Promise.all(chapters.map(mapper)); }) - .then(function () { - console.log("All chapters converted"); - }); + .then(() => console.log("All chapters converted")); }; function convertChapter(chapter, cachePath, contentPath) { @@ -26,7 +24,7 @@ function convertChapter(chapter, cachePath, contentPath) { const filePath = path.resolve(cachePath, filename); console.log(`- Reading ${filename}`); - return fs.readFile(filePath, { encoding: "utf-8" }).then(function (contents) { + return fs.readFile(filePath, { encoding: "utf-8" }).then(contents => { console.log(`- Read ${filename}`); const rawChapterDoc = jsdom(contents); const output = getChapterString(chapter, rawChapterDoc); @@ -38,13 +36,11 @@ function convertChapter(chapter, cachePath, contentPath) { const destFilePath = path.resolve(contentPath, destFileName); return fs.writeFile(destFilePath, output); }) - .then(function () { - console.log(`- Finished converting ${filename}`); - }); + .then(() => console.log(`- Finished converting ${filename}`)); } function getChapterString(chapter, rawChapterDoc) { - const body = getBodyXml(chapter, rawChapterDoc.querySelector(".entry-content")); + const body = getBodyXML(chapter, rawChapterDoc.querySelector(".entry-content")); return ` @@ -57,7 +53,7 @@ ${body} `; } -function getBodyXml(chapter, contentEl) { +function getBodyXML(chapter, contentEl) { // Remove initial Next Chapter and Previous Chapter

contentEl.removeChild(contentEl.firstElementChild); @@ -73,7 +69,7 @@ function getBodyXml(chapter, contentEl) { } // Remove redundant attributes - Array.prototype.forEach.call(contentEl.children, function (child) { + Array.prototype.forEach.call(contentEl.children, child => { if (child.getAttribute("dir") === "ltr") { child.removeAttribute("dir"); } @@ -90,7 +86,7 @@ function getBodyXml(chapter, contentEl) { // Remove empty s and s // Remove style attributes from them, as they're always messed up. const ems = contentEl.querySelectorAll("em, i"); - Array.prototype.forEach.call(ems, function (em) { + Array.prototype.forEach.call(ems, em => { if (em.textContent.trim() === "") { const replacement = contentEl.ownerDocument.createTextNode(" "); em.parentNode.replaceChild(replacement, em); @@ -101,7 +97,7 @@ function getBodyXml(chapter, contentEl) { // In https://parahumans.wordpress.com/2013/01/05/monarch-16-13/ there are some

s that should be

s O_o const addresses = contentEl.querySelectorAll("address"); - Array.prototype.forEach.call(addresses, function (address) { + Array.prototype.forEach.call(addresses, address => { const p = contentEl.ownerDocument.createElement("p"); p.innerHTML = address.innerHTML; address.parentNode.replaceChild(p, address); @@ -110,7 +106,7 @@ function getBodyXml(chapter, contentEl) { // Every except underline ones is pointless at best and frequently messed up. (Weird font size, line spacing, // etc.) const spans = contentEl.querySelectorAll("span"); - Array.prototype.forEach.call(spans, function (span) { + Array.prototype.forEach.call(spans, span => { if (span.getAttribute("style") === "text-decoration:underline;") { return; } @@ -137,7 +133,7 @@ function getBodyXml(chapter, contentEl) { bodyEl.appendChild(contentEl.firstChild); } - let xml = serializeToXml(bodyEl); + let xml = serializeToXML(bodyEl); // Fix recurring strange pattern of extra
in

......
\n

xml = xml.replace(/\s*<\/em><\/p>/g, "

"); @@ -151,8 +147,8 @@ function getBodyXml(chapter, contentEl) { xml = xml.replace(/<\/em>/g, ""); xml = xml.replace(/(\s?\s?[^A-Za-z]\s?\s?)<\/em>/g, "$1"); xml = xml.replace(/<\/em>(\s?\s?[^A-Za-z]\s?\s?)/g, "$1"); - xml = xml.replace(/“([^>]+)<\/em>(!|\?|\.)”/g, "“$1$2<\/em>”"); - xml = xml.replace(/

([^>]+)<\/em>(!|\?|\.)<\/p>/g, "

$1$2<\/em>

"); + xml = xml.replace(/“([^>]+)<\/em>(!|\?|\.)”/g, "“$1$2”"); + xml = xml.replace(/

([^>]+)<\/em>(!|\?|\.)<\/p>/g, "

$1$2

"); xml = xml.replace(/(!|\?|\.)\s{2}<\/em><\/p>/g, "$1

"); xml = xml.replace(/([a-z]+)\?<\/em>/g, "$1?"); @@ -173,9 +169,9 @@ function getBodyXml(chapter, contentEl) { // Fixes dashes xml = xml.replace(/ – /g, "—"); xml = xml.replace(/“-/g, "“—"); - xml = xml.replace(/-[,\.]?”/g, "—”"); + xml = xml.replace(/-[,.]?”/g, "—”"); xml = xml.replace(/-(!|\?)”/g, "—$1”"); - xml = xml.replace(/-[,\.]?<\/em>”/g, "—”"); + xml = xml.replace(/-[,.]?<\/em>”/g, "—
”"); xml = xml.replace(/-“/g, "—”"); xml = xml.replace(/

-/g, "

—"); xml = xml.replace(/-<\/p>/g, "—

"); @@ -199,7 +195,7 @@ function getBodyXml(chapter, contentEl) { xml = xml.replace(/the clairvoyant/g, "the Clairvoyant"); // One-off fixes - (substitutions[chapter.url] || []).forEach(function (substitution) { + (substitutions[chapter.url] || []).forEach(substitution => { const indexOf = xml.indexOf(substitution.before); if (indexOf === -1) { console.warn(`Could not find text "${substitution.before}" in ${chapter.url}. The chapter may have been ` + @@ -225,5 +221,5 @@ function isEmptyOrGarbage(el) { } function escapeRegExp(str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + return str.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&"); } diff --git a/lib/download.js b/lib/download.js index 1b2f49b..20c3420 100644 --- a/lib/download.js +++ b/lib/download.js @@ -8,19 +8,18 @@ const jsdom = require("./jsdom.js"); const FILENAME_PREFIX = "chapter"; -module.exports = function (startChapterUrl, cachePath, manifestPath) { +module.exports = (startChapterUrl, cachePath, manifestPath) => { return fs.readFile(manifestPath, { encoding: "utf-8" }).then( - function (manifestContents) { + manifestContents => { const manifest = JSON.parse(manifestContents); return downloadAllChapters(manifest, startChapterUrl, cachePath, manifestPath); }, - function (e) { + e => { if (e.code === "ENOENT") { return downloadAllChapters(null, startChapterUrl, cachePath, manifestPath); - } else { - throw e; } + throw e; } ); }; @@ -45,11 +44,11 @@ function downloadAllChapters(manifest, startChapterUrl, cachePath, manifestPath) console.log(`Downloading ${currentChapter}`); - return downloadChapter(currentChapter).then(function (response) { + return downloadChapter(currentChapter).then(response => { console.log("- Response received"); return response.text(); }) - .then(function (contents) { + .then(contents => { console.log("- Response body received"); const rawChapterDoc = jsdom(contents, { url: currentChapter }); console.log("- Response body parsed into DOM"); @@ -69,16 +68,16 @@ function downloadAllChapters(manifest, startChapterUrl, cachePath, manifestPath) fs.writeFile(path.resolve(cachePath, filename), contents); }) - .then(function () { + .then(() => { console.log("- Response text saved to cache file"); // Incrementally update the manifest after every successful download, instead of waiting until the end. return writeManifest(); }) - .then(function () { + .then(() => { console.log("- Manifest updated"); if (currentChapter === null) { - return; + return undefined; } ++chapterIndex; @@ -94,7 +93,7 @@ function downloadAllChapters(manifest, startChapterUrl, cachePath, manifestPath) } function getNextChapterUrl(rawChapterDoc) { - // a[title="Next Chapter"] doesn"t always work. Two different pathologies: + // `a[title="Next Chapter"]` doesn"t always work. Two different pathologies: // - https://parahumans.wordpress.com/2011/09/27/shell-4-2/ // - https://parahumans.wordpress.com/2012/04/21/sentinel-9-6/ // So instead search for the first within the main content area starting with "Next", trimmed. @@ -118,7 +117,7 @@ function retry(times, fn) { return fn(); } - return fn().catch(function () { + return fn().catch(() => { return retry(times - 1, fn); }); } diff --git a/lib/jsdom.js b/lib/jsdom.js index 1b0090c..2b98589 100644 --- a/lib/jsdom.js +++ b/lib/jsdom.js @@ -1,13 +1,14 @@ "use strict"; const jsdom = require("jsdom"); -const xtend = require("xtend"); // No need to fetch or execute JavaScript -module.exports = function (contents, options) { - options = xtend(options, { features: { - FetchExternalResources: false, - ProcessExternalResources: false - }}); +module.exports = (contents, options) => { + options = Object.assign({}, options, { + features: { + FetchExternalResources: false, + ProcessExternalResources: false + } + }); return jsdom.jsdom(contents, options); }; diff --git a/lib/scaffold.js b/lib/scaffold.js index 8204950..2613ea5 100644 --- a/lib/scaffold.js +++ b/lib/scaffold.js @@ -21,17 +21,17 @@ const COVER_IMG_FILENAME = "cover.png"; const COVER_XHTML_FILENAME = "cover.xhtml"; const COVER_MIMETYPE = "image/png"; -module.exports = function (scaffoldingPath, bookPath, contentPath, chaptersPath, manifestPath) { +module.exports = (scaffoldingPath, bookPath, contentPath, chaptersPath, manifestPath) => { return Promise.all([ - getChapters(contentPath, chaptersPath, manifestPath).then(function (chapters) { cpr(scaffoldingPath, bookPath, { overwrite: true, confirm: true, filter: noThumbs }), + getChapters(contentPath, chaptersPath, manifestPath).then(chapters => { return Promise.all([ writeOpf(chapters, contentPath), writeNcx(chapters, contentPath) ]); }) ]) - .then(function () { }); + .then(() => undefined); }; function noThumbs(filePath) { @@ -40,11 +40,11 @@ function noThumbs(filePath) { } function writeOpf(chapters, contentPath) { - const manifestChapters = chapters.map(function (c) { + const manifestChapters = chapters.map(c => { return ``; }).join("\n"); - const spineChapters = chapters.map(function (c) { + const spineChapters = chapters.map(c => { return ``; }).join("\n"); @@ -82,7 +82,7 @@ ${spineChapters} } function writeNcx(chapters, contentPath) { - const navPoints = chapters.map(function (c, i) { + const navPoints = chapters.map((c, i) => { return ` ${c.title} @@ -118,15 +118,14 @@ ${navPoints} function getChapters(contentPath, chaptersPath, manifestPath) { const hrefPrefix = `${path.relative(contentPath, chaptersPath)}/`; - return fs.readFile(manifestPath, { encoding: "utf-8" }).then(function (manifestContents) { + return fs.readFile(manifestPath, { encoding: "utf-8" }).then(manifestContents => { const manifestChapters = JSON.parse(manifestContents); - return fs.readdir(chaptersPath).then(function (filenames) { - return filenames.filter(function (f) { - return path.extname(f) === ".xhtml"; - }) + return fs.readdir(chaptersPath).then(filenames => { + return filenames + .filter(f => path.extname(f) === ".xhtml") .sort() - .map(function (f, i) { + .map((f, i) => { return { id: path.basename(f), title: manifestChapters[i].title, diff --git a/lib/worm-scraper.js b/lib/worm-scraper.js index fdc1731..73624de 100644 --- a/lib/worm-scraper.js +++ b/lib/worm-scraper.js @@ -1,4 +1,5 @@ "use strict"; +/* eslint-disable no-process-exit */ const path = require("path"); const mkdirp = require("mkdirp-then"); const rimraf = require("rimraf-then"); @@ -62,41 +63,31 @@ const chaptersPath = path.resolve(contentPath, "chapters"); const commands = []; -if (argv._.indexOf("download") !== -1) { - commands.push(function () { - return download(argv.startUrl, cachePath, manifestPath); +if (argv._.includes("download")) { + commands.push(() => download(argv.startUrl, cachePath, manifestPath)); +} + +if (argv._.includes("convert")) { + commands.push(() => { + return rimraf(chaptersPath) + .then(() => mkdirp(chaptersPath)) + .then(() => convert(cachePath, manifestPath, chaptersPath)); }); } -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._.includes("scaffold")) { + commands.push(() => scaffold(scaffoldingPath, bookPath, contentPath, chaptersPath, manifestPath)); } -if (argv._.indexOf("scaffold") !== -1) { - commands.push(function () { - return scaffold(scaffoldingPath, bookPath, contentPath, chaptersPath, manifestPath); - }); +if (argv._.includes("zip")) { + commands.push(() => zip(bookPath, contentPath, path.resolve(argv.out))); } -if (argv._.indexOf("zip") !== -1) { - commands.push(function () { - return zip(bookPath, contentPath, path.resolve(argv.out)); - }); -} - -commands.reduce(function (previous, command) { +commands.reduce((previous, command) => { return previous.then(command); }, Promise.resolve()) -.then(function () { - console.log("All done!"); -}) -.catch(function (e) { +.then(() => console.log("All done!")) +.catch(e => { console.error(e.stack); + process.exit(1); }); diff --git a/lib/zip.js b/lib/zip.js index 929b229..3e7d20c 100644 --- a/lib/zip.js +++ b/lib/zip.js @@ -3,14 +3,14 @@ const fs = require("fs"); const path = require("path"); const archiver = require("archiver"); -module.exports = function (bookPath, contentPath, outPath) { - return new Promise(function (resolve, reject) { +module.exports = (bookPath, contentPath, outPath) => { + return new Promise((resolve, reject) => { console.log(`Zipping up ${bookPath} into an EPUB`); const archive = archiver("zip"); const destStream = fs.createWriteStream(outPath); - destStream.on("close", function () { + destStream.on("close", () => { console.log(`EPUB written to ${outPath} (${archive.pointer()} bytes)`); resolve(); }); diff --git a/package.json b/package.json index 9f130a8..20043ee 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "scaffolding/" ], "scripts": { - "lint": "eslint lib && jscs lib" + "lint": "eslint lib" }, "dependencies": { "archiver": "^1.3.0", @@ -29,12 +29,10 @@ "thenify": "^3.1.0", "throat": "^3.0.0", "xmlserializer": "^0.6.0", - "xtend": "^4.0.0", "yargs": "^6.6.0", "zfill": "0.0.2" }, "devDependencies": { - "eslint": "0.20.0", - "jscs": "^1.13.1" + "eslint": "3.12.2" } }