mirror of
https://github.com/StepanovPlaton/SSAUGenerator.git
synced 2026-10-31 10:18:29 +04:00
add pptx
This commit is contained in:
96
pptx/src/cli.js
Normal file
96
pptx/src/cli.js
Normal file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const { build } = require("./build");
|
||||
|
||||
function parseArgs(argv) {
|
||||
const options = { config: "config.yaml" };
|
||||
for (let i = 0; i < argv.length; i += 1) {
|
||||
const arg = argv[i];
|
||||
switch (arg) {
|
||||
case "--config":
|
||||
case "-c":
|
||||
options.config = argv[++i];
|
||||
break;
|
||||
case "--output":
|
||||
case "-o":
|
||||
options.output = argv[++i];
|
||||
break;
|
||||
case "--check":
|
||||
options.check = true;
|
||||
break;
|
||||
case "--verbose":
|
||||
case "-v":
|
||||
options.verbose = true;
|
||||
break;
|
||||
case "--help":
|
||||
case "-h":
|
||||
options.help = true;
|
||||
break;
|
||||
case "--version":
|
||||
options.version = true;
|
||||
break;
|
||||
default:
|
||||
if (!arg.startsWith("-")) {
|
||||
options.config = arg;
|
||||
} else {
|
||||
console.warn(`Неизвестный аргумент: ${arg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function printHelp() {
|
||||
console.log(`lab-gen-pptx — генератор презентаций PPTX из Markdown
|
||||
|
||||
Использование:
|
||||
lab-gen-pptx [config.yaml] [опции]
|
||||
|
||||
Опции:
|
||||
-c, --config <file> путь к config.yaml (по умолчанию config.yaml)
|
||||
-o, --output <file> переопределить имя выходного файла
|
||||
--check только проверить конфигурацию и ссылки
|
||||
-v, --verbose подробный вывод
|
||||
-h, --help показать справку
|
||||
--version показать версию
|
||||
`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
if (options.help) return printHelp();
|
||||
if (options.version) {
|
||||
const pkg = require("../package.json");
|
||||
console.log(pkg.version);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const configPath = path.resolve(options.config);
|
||||
try {
|
||||
const result = await build({ config: configPath, check: options.check, output: options.output });
|
||||
const { config, issues } = result;
|
||||
|
||||
if (issues.length) {
|
||||
console.log("Проверка конфигурации:");
|
||||
issues.forEach((issue) => console.log(` - ${issue}`));
|
||||
} else {
|
||||
console.log("Проверка конфигурации: ошибок нет.");
|
||||
}
|
||||
|
||||
if (options.check) {
|
||||
console.log(`Слайдов в конфигурации: ${(config.slides || []).length}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (issues.length) process.exitCode = 1;
|
||||
else console.log(`Готово: ${result.output}`);
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user