-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.js
More file actions
46 lines (38 loc) · 1.24 KB
/
Copy pathconvert.js
File metadata and controls
46 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const { convertToPdf } = require('./lib/pdf-converter');
const Spinner = require('./lib/spinner');
async function main() {
const spinner = new Spinner('Converting to PDF...');
try {
// Get input and output paths from command line arguments
const args = process.argv.slice(2);
if (args.length < 1) {
console.error('Usage: node convert.js <input.md> [output.pdf]');
process.exit(1);
}
const inputPath = args[0];
const outputPath = args[1] || inputPath.replace(/\.md$/, '.pdf');
// Validate input file exists
if (!fs.existsSync(inputPath)) {
console.error(`Error: Input file '${inputPath}' does not exist`);
process.exit(1);
}
// Validate input file extension
if (!inputPath.endsWith('.md')) {
console.error('Error: Input file must have .md extension');
process.exit(1);
}
// Start the spinner and convert the file
spinner.start();
await convertToPdf(inputPath, outputPath);
spinner.stop();
console.log(`Successfully converted ${inputPath} to ${outputPath}`);
} catch (error) {
spinner.stop();
console.error('Error:', error.message);
process.exit(1);
}
}
main();