#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const contextPath = path.join(__dirname, '../templates/DEVELOPMENT_CONTEXT.json');
function loadContext() {
if (!fs.existsSync(contextPath)) {
const defaultContext = JSON.parse(fs.readFileSync(
path.join(__dirname, '../templates/DEVELOPMENT_CONTEXT.json'), 'utf8'
));
fs.writeFileSync(contextPath, JSON.stringify(defaultContext, null, 2));
return defaultContext;
}
return JSON.parse(fs.readFileSync(contextPath, 'utf8'));
}
function saveContext(context) {
fs.writeFileSync(contextPath, JSON.stringify(context, null, 2));
}
function developerStatus(developerId, status, currentFile = '', progress = 0) {
const context = loadContext();
context.developers[developerId] = {
...context.developers[developerId],
status,
currentFile,
lastUpdate: new Date().toISOString(),
progress
};
saveContext(context);
console.log(`✅ Developer ${developerId}: ${status}${currentFile ? ` (${currentFile})` : ''}`);
}
function lockFile(developerId, filePath) {
const context = loadContext();
if (context.fileLocks[filePath]) {
console.log(`❌ File ${filePath} already locked by ${context.fileLocks[filePath]}`);
process.exit(1);
}
context.fileLocks[filePath] = developerId;
saveContext(context);
console.log(`✅ Developer ${developerId} locked ${filePath}`);
}
function unlockFile(developerId, filePath) {
const context = loadContext();
if (context.fileLocks[filePath] !== developerId) {
console.log(`❌ Developer ${developerId} doesn't own lock for ${filePath}`);
process.exit(1);
}
delete context.fileLocks[filePath];
saveContext(context);
console.log(`✅ Developer ${developerId} released ${filePath}`);
}
const args = process.argv.slice(2);
const command = args[0];
switch (command) {
case 'status':
const developerId = args[1];
const status = args[2];
const currentFile = args[3] || '';
const progress = parseInt(args[4]) || 0;
developerStatus(developerId, status, currentFile, progress);
break;
case 'lock':
const lockDeveloperId = args[1];
const lockFilePath = args[2];
lockFile(lockDeveloperId, lockFilePath);
break;
case 'unlock':
const unlocksDeveloperId = args[1];
const unlocksFilePath = args[2];
unlockFile(unlocksDeveloperId, unlocksFilePath);
break;
case 'show':
console.log(JSON.stringify(loadContext(), null, 2));
break;
default:
console.log('Usage:');
console.log(' node manage-context.js status <developer-id> <status> [file] [progress]');
console.log(' node manage-context.js lock <developer-id> <file-path>');
console.log(' node manage-context.js unlock <developer-id> <file-path>');
console.log(' node manage-context.js show');
}