adpa-enterprise-framework-automation
Version:
Modular, standards-compliant Node.js/TypeScript automation framework for enterprise requirements, project, and data management. Provides CLI and API for BABOK v3, PMBOK 7th Edition, and DMBOK 2.0 (in progress). Production-ready Express.js API with TypeSpe
160 lines âĸ 4.91 kB
JavaScript
/**
* VCS (Version Control System) Command Handler
* Handles version control system integration for generated documents
*/
// 1. Node.js built-ins
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { join } from 'path';
// 2. Third-party dependencies (none in this file)
// 3. Internal modules (none in this file)
// 4. Constants
import { DEFAULT_OUTPUT_DIR } from '../constants.js';
/**
* Handler for 'vcs init' command
*/
export async function handleVcsInitCommand(options = {}) {
const { outputDir = DEFAULT_OUTPUT_DIR, quiet } = options;
if (!quiet) {
console.log(`đ§ Initializing Git repository in ${outputDir}...`);
}
await ensureGitRepoInitialized(outputDir);
if (!quiet) {
console.log('â
Git repository initialized');
}
}
/**
* Handler for 'vcs status' command
*/
export async function handleVcsStatusCommand(options = {}) {
const { outputDir = DEFAULT_OUTPUT_DIR, quiet } = options;
const repoPath = join(process.cwd(), outputDir);
const gitDir = join(repoPath, '.git');
if (!existsSync(gitDir)) {
if (!quiet) {
console.log('â No Git repository found in output directory');
console.log('đĄ Run: rga vcs init');
}
return;
}
if (!quiet) {
console.log(`đ Git status for ${outputDir}:`);
}
try {
execSync('git status --porcelain', {
cwd: repoPath,
stdio: quiet ? 'ignore' : 'inherit'
});
}
catch (error) {
if (!quiet) {
console.error('â Failed to get Git status:', error);
}
throw error;
}
}
/**
* Handler for 'vcs commit' command
*/
export async function handleVcsCommitCommand(options = {}) {
const { outputDir = DEFAULT_OUTPUT_DIR, message = 'Update generated documents', quiet } = options;
const repoPath = join(process.cwd(), outputDir);
const gitDir = join(repoPath, '.git');
if (!existsSync(gitDir)) {
if (!quiet) {
console.log('â No Git repository found in output directory');
console.log('đĄ Run: rga vcs init');
}
return;
}
if (!quiet) {
console.log(`đ Committing changes in ${outputDir}...`);
}
try {
// Add all changes
execSync('git add .', {
cwd: repoPath,
stdio: quiet ? 'ignore' : 'inherit'
});
// Check if there are any changes to commit
try {
execSync('git diff --cached --exit-code', {
cwd: repoPath,
stdio: 'ignore'
});
if (!quiet) {
console.log('âšī¸ No changes to commit');
}
return;
}
catch {
// Changes exist, continue with commit
}
// Commit changes
execSync(`git commit -m "${message}"`, {
cwd: repoPath,
stdio: quiet ? 'ignore' : 'inherit'
});
if (!quiet) {
console.log('â
Changes committed successfully');
}
}
catch (error) {
if (!quiet) {
console.error('â Failed to commit changes:', error);
}
throw error;
}
}
/**
* Handler for 'vcs push' command
*/
export async function handleVcsPushCommand(options = {}) {
const { outputDir = DEFAULT_OUTPUT_DIR, remote = 'origin', branch = 'main', quiet } = options;
const repoPath = join(process.cwd(), outputDir);
const gitDir = join(repoPath, '.git');
if (!existsSync(gitDir)) {
if (!quiet) {
console.log('â No Git repository found in output directory');
console.log('đĄ Run: rga vcs init');
}
return;
}
if (!quiet) {
console.log(`đ Pushing changes to ${remote}/${branch}...`);
}
try {
execSync(`git push ${remote} ${branch}`, {
cwd: repoPath,
stdio: quiet ? 'ignore' : 'inherit'
});
if (!quiet) {
console.log('â
Changes pushed successfully');
}
}
catch (error) {
if (!quiet) {
console.error('â Failed to push changes:', error);
}
throw error;
}
}
/**
* Utility function to ensure Git repository is initialized
*/
async function ensureGitRepoInitialized(documentsDir = DEFAULT_OUTPUT_DIR) {
const repoPath = join(process.cwd(), documentsDir);
const gitDir = join(repoPath, '.git');
if (!existsSync(gitDir)) {
console.log(`Initializing git repository in ${documentsDir}/ ...`);
try {
execSync('git init', { cwd: repoPath, stdio: 'inherit' });
console.log('â
Git repository initialized.');
}
catch (e) {
console.error('â Failed to initialize git repository:', e);
throw e;
}
}
}
//# sourceMappingURL=vcs.js.map