epub-to-pdf-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { convertEpubToPdf } from '../src/index.js';
4
+
5
+ const args = process.argv.slice(2);
6
+
7
+ if (args.length === 0) {
8
+ console.log(`
9
+ Usage:
10
+ epub2pdf <input.epub> [output.pdf]
11
+
12
+ Example:
13
+ epub2pdf book.epub
14
+ epub2pdf book.epub mybook.pdf
15
+ `);
16
+ process.exit(1);
17
+ }
18
+
19
+ const input = args[0];
20
+ const output = args[1];
21
+
22
+ convertEpubToPdf(input, output)
23
+ .then(out => {
24
+ console.log(`✅ PDF created: ${out}`);
25
+ })
26
+ .catch(err => {
27
+ console.error('❌ Conversion failed:', err.message);
28
+ process.exit(1);
29
+ });
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "epub-to-pdf-cli",
3
+ "version": "1.0.0",
4
+ "description": "Convert EPUB files to PDF using Calibre",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "bin": {
8
+ "epub2pdf": "./bin/cli.js"
9
+ },
10
+ "keywords": [
11
+ "epub",
12
+ "pdf",
13
+ "ebook",
14
+ "converter",
15
+ "calibre"
16
+ ],
17
+ "author": "Suraj Sutar",
18
+ "license": "MIT"
19
+ }
package/src/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import { exec } from 'child_process';
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+
5
+ export function convertEpubToPdf(inputPath, outputPath) {
6
+ return new Promise((resolve, reject) => {
7
+ if (!fs.existsSync(inputPath)) {
8
+ return reject(new Error('Input EPUB file does not exist'));
9
+ }
10
+
11
+ const inFile = path.resolve(inputPath);
12
+ const outFile = path.resolve(
13
+ outputPath || inFile.replace(/\.epub$/i, '.pdf')
14
+ );
15
+
16
+ const cmd = `ebook-convert "${inFile}" "${outFile}"`;
17
+
18
+ exec(cmd, (error, stdout, stderr) => {
19
+ if (error) {
20
+ return reject(new Error(stderr || error.message));
21
+ }
22
+ resolve(outFile);
23
+ });
24
+ });
25
+ }
package/test.js ADDED
@@ -0,0 +1,3 @@
1
+ import { convertEpubToPdf } from './src/index.js';
2
+
3
+ convertEpubToPdf('sample.epub');