kist
Version:
Lightweight Package Pipeline Processor with Plugin Architecture
46 lines • 2.22 kB
JavaScript
import { __awaiter } from "tslib";
import { execFile } from "child_process";
import path from "path";
import util from "util";
import { Action } from "../../core/pipeline/Action.js";
const execFileAsync = util.promisify(execFile);
export class DocumentationAction extends Action {
execute(options) {
return __awaiter(this, void 0, void 0, function* () {
const { generatorCommand = "jsdoc", sourcePath = "./src", outputPath = "./docs", configPath = "", } = options;
if (!generatorCommand) {
throw new Error("Invalid options: 'generatorCommand' must be specified.");
}
const resolvedSourcePath = path.resolve(sourcePath);
const resolvedOutputPath = path.resolve(outputPath);
const resolvedConfigPath = configPath
? path.resolve(configPath)
: null;
this.logInfo(`Generating documentation with ${generatorCommand}...`);
this.logDebug(`Source Path: ${resolvedSourcePath}`);
this.logDebug(`Output Path: ${resolvedOutputPath}`);
if (resolvedConfigPath)
this.logDebug(`Config Path: ${resolvedConfigPath}`);
try {
const args = resolvedConfigPath
? ["-c", resolvedConfigPath, "-d", resolvedOutputPath]
: [resolvedSourcePath, "-d", resolvedOutputPath];
const { stdout, stderr } = yield execFileAsync(generatorCommand, args);
if (stderr) {
this.logError(`Documentation generation failed: ${stderr}`);
throw new Error(stderr);
}
this.logInfo(stdout);
this.logInfo(`Documentation successfully generated at: ${resolvedOutputPath}`);
}
catch (error) {
this.logError("Error occurred while generating documentation.", error);
throw new Error(`Documentation generation failed: ${error.message}`);
}
});
}
describe() {
return "Generates project documentation using a specified tool (e.g., JSDoc, TypeDoc).";
}
}
//# sourceMappingURL=DocumentationAction.js.map