File size: 1,355 Bytes
983be3b 71e8598 37b52e3 983be3b 71e8598 983be3b 71e8598 983be3b | 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 47 48 49 50 51 52 53 54 55 56 57 58 | import yargs from "yargs";
import inquirer from "inquirer";
const argv = yargs(process.argv.slice(2))
.option("provider", {
alias: "p",
type: "string",
description: "Provider name"
})
.help()
.argv;
async function selectProvider() {
if (argv.provider) return argv.provider;
const { provider } = await inquirer.prompt([
{
type: "list",
name: "provider",
message: "Seleziona editore:",
choices: [
"sanoma",
"hubscuola",
"dibooklaterza",
"zanichelli",
"bsmart"
// there'll be more providers in the future, but I currently don't have books to test em so if you want to contribute feel free to open a PR with your provider implementation
]
}
]);
return provider;
}
async function main() {
const provider = await selectProvider();
const providerOptions = { ...argv };
delete providerOptions._;
delete providerOptions.$0;
delete providerOptions.provider;
delete providerOptions.p;
try {
const module = await import(`./providers/${provider}.js`);
if (!module.run) {
console.error("Il provider non esporta una funzione run()");
process.exit(1);
}
await module.run(providerOptions);
} catch (err) {
console.error("Errore caricando il provider:", err.message);
process.exit(1);
}
}
main(); |