This commit is contained in:
√(noham)²
2026-06-19 15:48:32 +02:00
parent 58c210ec45
commit 13c9bcbcd2
8 changed files with 325 additions and 321 deletions

View File

@@ -1,52 +1,52 @@
import { Command } from "commander";
import { Command } from 'commander'
export const VALID_THEMES = [
"light",
"dark",
"sepia",
"groove-dark",
"solarized-light",
"solarized-dark",
"nord-light",
"nord-dark",
];
'light',
'dark',
'sepia',
'groove-dark',
'solarized-light',
'solarized-dark',
'nord-light',
'nord-dark'
]
const program = new Command();
const program = new Command()
program
.name("pdfy")
.description("Convert web articles to PDF using Reader View and Puppeteer")
.argument("<url>", "URL of the article to convert")
.name('pdfy')
.description('Convert web articles to PDF using Reader View and Puppeteer')
.argument('<url>', 'URL of the article to convert')
.option(
"-t, --theme <theme>",
`Reader View theme (${VALID_THEMES.join(", ")})`,
'-t, --theme <theme>',
`Reader View theme (${VALID_THEMES.join(', ')})`
)
.option("-c, --css <path>", "path to custom CSS file")
.option("-p, --prefs <path>", "path to extension preferences JSON")
.option('-c, --css <path>', 'path to custom CSS file')
.option('-p, --prefs <path>', 'path to extension preferences JSON')
.option(
"-o, --output <path>",
"output file path (default: ./output/<title>.pdf)",
'-o, --output <path>',
'output file path (default: ./output/<title>.pdf)'
)
.addHelpText(
"after",
'after',
`
Examples:
node src/index.js <URL>
node src/index.js <URL> --theme dark --css config/rules.css
npm start -- <URL> --theme dark --css config/rules.css
`,
);
`
)
export function parseArgs() {
program.parse(process.argv);
const opts = program.opts();
export function parseArgs () {
program.parse(process.argv)
const opts = program.opts()
return {
url: program.args[0],
opts: {
theme: opts.theme || null,
css: opts.css || null,
prefs: opts.prefs || null,
output: opts.output || null,
},
};
output: opts.output || null
}
}
}