rkwyu
commited on
Commit
·
c9bbadf
1
Parent(s):
8c0e214
Add eslint and jest
Browse files- eslint.config.js +11 -0
- package-lock.json +0 -0
- package.json +15 -2
- run.js +1 -1
- src/service/ScribdDownloader.js +1 -2
- src/utils/io/ConfigLoader.js +5 -1
- src/utils/io/DirectoryIo.js +1 -2
- src/utils/io/PdfGenerator.js +2 -1
- src/utils/request/PuppeteerSg.js +1 -1
- test/ConfigLoader.test.js +18 -0
eslint.config.js
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import globals from "globals";
|
2 |
+
import pluginJs from "@eslint/js";
|
3 |
+
|
4 |
+
export default [
|
5 |
+
{
|
6 |
+
languageOptions: {
|
7 |
+
globals: globals.node
|
8 |
+
}
|
9 |
+
},
|
10 |
+
pluginJs.configs.recommended,
|
11 |
+
];
|
package-lock.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
package.json
CHANGED
@@ -4,7 +4,11 @@
|
|
4 |
"description": "Scribd Document Downloader",
|
5 |
"main": "index.js",
|
6 |
"scripts": {
|
7 |
-
"
|
|
|
|
|
|
|
|
|
8 |
},
|
9 |
"keywords": [],
|
10 |
"author": {
|
@@ -20,5 +24,14 @@
|
|
20 |
"sharp": "^0.33.3"
|
21 |
},
|
22 |
"type": "module",
|
23 |
-
"types": "module"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
|
|
4 |
"description": "Scribd Document Downloader",
|
5 |
"main": "index.js",
|
6 |
"scripts": {
|
7 |
+
"start": "node run.js",
|
8 |
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
9 |
+
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
|
10 |
+
"test:cov": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
11 |
+
"lint": "eslint --fix \"{src,apps,libs}/**/*.js\""
|
12 |
},
|
13 |
"keywords": [],
|
14 |
"author": {
|
|
|
24 |
"sharp": "^0.33.3"
|
25 |
},
|
26 |
"type": "module",
|
27 |
+
"types": "module",
|
28 |
+
"devDependencies": {
|
29 |
+
"@eslint/js": "^9.1.1",
|
30 |
+
"eslint": "^9.1.1",
|
31 |
+
"globals": "^15.0.0",
|
32 |
+
"jest": "^29.7.0"
|
33 |
+
},
|
34 |
+
"jest": {
|
35 |
+
"transform": {}
|
36 |
+
}
|
37 |
}
|
run.js
CHANGED
@@ -3,5 +3,5 @@ import { app } from './src/App.js'
|
|
3 |
if (process.argv.length == 3) {
|
4 |
await app.execute(process.argv[2])
|
5 |
} else {
|
6 |
-
console.error(`Usage:
|
7 |
}
|
|
|
3 |
if (process.argv.length == 3) {
|
4 |
await app.execute(process.argv[2])
|
5 |
} else {
|
6 |
+
console.error(`Usage: npm start [URL]`)
|
7 |
}
|
src/service/ScribdDownloader.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import cliProgress from "cli-progress"
|
2 |
-
import path from 'path'
|
3 |
import { puppeteerSg } from "../utils/request/PuppeteerSg.js";
|
4 |
import { pdfGenerator } from "../utils/io/PdfGenerator.js";
|
5 |
import { configLoader } from "../utils/io/ConfigLoader.js";
|
@@ -60,7 +59,7 @@ class ScribdDownloader {
|
|
60 |
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
61 |
bar.start(doc_pages.length, 0);
|
62 |
for (let i = 0; i < doc_pages.length; i++) {
|
63 |
-
await page.evaluate((i) => {
|
64 |
document.getElementById(`outer_page_${(i + 1)}`).scrollIntoView()
|
65 |
}, i)
|
66 |
|
|
|
1 |
import cliProgress from "cli-progress"
|
|
|
2 |
import { puppeteerSg } from "../utils/request/PuppeteerSg.js";
|
3 |
import { pdfGenerator } from "../utils/io/PdfGenerator.js";
|
4 |
import { configLoader } from "../utils/io/ConfigLoader.js";
|
|
|
59 |
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
60 |
bar.start(doc_pages.length, 0);
|
61 |
for (let i = 0; i < doc_pages.length; i++) {
|
62 |
+
await page.evaluate((i) => { // eslint-disable-next-line
|
63 |
document.getElementById(`outer_page_${(i + 1)}`).scrollIntoView()
|
64 |
}, i)
|
65 |
|
src/utils/io/ConfigLoader.js
CHANGED
@@ -20,7 +20,11 @@ class ConfigLoader {
|
|
20 |
* @returns {Promise<string>}
|
21 |
*/
|
22 |
load(section, key) {
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
}
|
26 |
|
|
|
20 |
* @returns {Promise<string>}
|
21 |
*/
|
22 |
load(section, key) {
|
23 |
+
if (Object.keys(config[section]).includes(key)) {
|
24 |
+
return config[section][key]
|
25 |
+
} else {
|
26 |
+
throw new TypeError(`Unknown key: ${key}`)
|
27 |
+
}
|
28 |
}
|
29 |
}
|
30 |
|
src/utils/io/DirectoryIo.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
-
import fs
|
2 |
-
import path from 'path'
|
3 |
|
4 |
class DirectoryIo {
|
5 |
constructor() {
|
|
|
1 |
+
import fs from 'fs'
|
|
|
2 |
|
3 |
class DirectoryIo {
|
4 |
constructor() {
|
src/utils/io/PdfGenerator.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import PDFDocument from 'pdfkit'
|
2 |
import fs from 'fs'
|
3 |
-
|
|
|
4 |
import { Image } from '../../object/Image.js'
|
5 |
|
6 |
class PdfGenerator {
|
|
|
1 |
import PDFDocument from 'pdfkit'
|
2 |
import fs from 'fs'
|
3 |
+
|
4 |
+
// eslint-disable-next-line
|
5 |
import { Image } from '../../object/Image.js'
|
6 |
|
7 |
class PdfGenerator {
|
src/utils/request/PuppeteerSg.js
CHANGED
@@ -41,7 +41,7 @@ class PuppeteerSg {
|
|
41 |
* Close the browser
|
42 |
*/
|
43 |
async close() {
|
44 |
-
if (
|
45 |
await this.browser.close();
|
46 |
this.browser = null;
|
47 |
}
|
|
|
41 |
* Close the browser
|
42 |
*/
|
43 |
async close() {
|
44 |
+
if (this.browser) {
|
45 |
await this.browser.close();
|
46 |
this.browser = null;
|
47 |
}
|
test/ConfigLoader.test.js
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { configLoader } from "../src/utils/io/ConfigLoader.js";
|
2 |
+
|
3 |
+
|
4 |
+
describe("load", () => {
|
5 |
+
test("return 'output' if load DIRECTORY.output", () => {
|
6 |
+
expect(configLoader.load("DIRECTORY", "output")).toBe("output");
|
7 |
+
})
|
8 |
+
test("throw an error if load unknown section", () => {
|
9 |
+
expect(() => {
|
10 |
+
configLoader.load("FOO", "output")
|
11 |
+
}).toThrow(TypeError)
|
12 |
+
})
|
13 |
+
test("throw an error if load unknown key", () => {
|
14 |
+
expect(() => {
|
15 |
+
configLoader.load("DIRECTORY", "FOO")
|
16 |
+
}).toThrow(TypeError)
|
17 |
+
})
|
18 |
+
})
|