Files
SSAUGenerator/pptx/src/cli.js
StepanovPlaton bf7816ab7c Rename project to SSAU Generator and restructure content
- Move projects into content/<project>/{docx,pptx} with shared assets/
- Flatten config paths; output = project name in project folder
- Add pptx --init scaffold; remove docx exe build
- Add feature-complete content/example; ignore content/* except example
- Rewrite README and AGENTS.md
2026-10-11 23:25:22 +04:00

123 lines
3.6 KiB
JavaScript

#!/usr/bin/env node
"use strict";
const fs = require("fs");
const path = require("path");
const { build } = require("./build");
const { ensureScaffold } = require("./scaffold");
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 "--init":
options.init = 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(`SSAU Generator PPTX — генератор презентаций PPTX из Markdown
Использование:
node pptx/src/cli.js [config.yaml] [опции]
Опции:
-c, --config <file> путь к config.yaml (по умолчанию config.yaml)
-o, --output <file> переопределить имя выходного файла
--check только проверить конфигурацию и ссылки
--init создать шаблон config.yaml/slides/assets и выйти
-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);
if (options.init || !fs.existsSync(configPath)) {
const targetDir = path.dirname(configPath);
try {
const created = await ensureScaffold(targetDir);
if (created.length) {
console.log("Создан шаблон генератора:");
created.forEach((file) => console.log(" " + path.relative(targetDir, file)));
} else {
console.log("Файлы уже существуют, ничего не создано.");
}
console.log("");
console.log("Отредактируйте config.yaml и файлы в slides/, затем запустите генератор снова.");
} catch (error) {
console.error(error.message);
process.exitCode = 1;
}
return undefined;
}
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();