kist
Version:
Package Pipeline Processor
89 lines (88 loc) • 4.56 kB
JavaScript
;
// ============================================================================
// Imports
// ============================================================================
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentationAction = void 0;
const child_process_1 = require("child_process");
const path_1 = __importDefault(require("path"));
const util_1 = __importDefault(require("util"));
const Action_1 = require("../../core/pipeline/Action");
// ============================================================================
// Constants
// ============================================================================
const execFileAsync = util_1.default.promisify(child_process_1.execFile);
// ============================================================================
// Classes
// ============================================================================
/**
* DocumentationAction automates the generation of documentation for software
* projects. This action allows specifying a documentation generator, source
* paths, and output locations.
*/
class DocumentationAction extends Action_1.Action {
/**
* Executes the documentation generation process using the specified command-line tool.
*
* @param options - The options specifying the generator tool, source path, and output path.
* @returns A Promise that resolves when documentation generation completes successfully.
* @throws {Error} Throws an error if the documentation process fails.
*/
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_1.default.resolve(sourcePath);
const resolvedOutputPath = path_1.default.resolve(outputPath);
const resolvedConfigPath = configPath
? path_1.default.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 {
// Construct command arguments
const args = resolvedConfigPath
? ["-c", resolvedConfigPath, "-d", resolvedOutputPath]
: [resolvedSourcePath, "-d", resolvedOutputPath];
// Execute documentation generation command safely
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}`);
}
});
}
/**
* Provides a description of the action.
*
* @returns A string description of the action.
*/
describe() {
return "Generates project documentation using a specified tool (e.g., JSDoc, TypeDoc).";
}
}
exports.DocumentationAction = DocumentationAction;