@diagramers/cli
Version:
Diagramers CLI - Command-line tools for managing Diagramers projects
115 lines • 5.61 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateCommand = updateCommand;
const template_updater_1 = require("../services/template-updater");
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
function updateCommand(program) {
program
.command('update')
.description('Update existing project with latest template features')
.option('-v, --version <version>', 'Specific version to update to (e.g., 1.1.17, latest)', 'latest')
.option('-f, --force', 'Force update even if conflicts detected')
.option('-b, --backup', 'Create backup before updating')
.option('--dry-run', 'Show what would be updated without making changes')
.option('--check-only', 'Only check for available updates without updating')
.action(async (options) => {
try {
// Validate we're in a diagramers API project
if (!isDiagramersApiProject()) {
console.error(chalk_1.default.red('❌ This command must be run from a diagramers API project'));
console.log(chalk_1.default.yellow('💡 Navigate to your API project directory or run: diagramers init api <project-name>'));
process.exit(1);
}
console.log(chalk_1.default.blue('🔄 Checking for template updates...'));
if (options.version && options.version !== 'latest') {
console.log(chalk_1.default.yellow(`📌 Target version: ${options.version}`));
}
else {
console.log(chalk_1.default.yellow('📌 Target version: latest'));
}
if (options.dryRun) {
console.log(chalk_1.default.gray(' Mode: Dry run (no changes will be made)'));
}
if (options.backup) {
console.log(chalk_1.default.gray(' Backup: Enabled'));
}
if (options.force) {
console.log(chalk_1.default.gray(' Force: Enabled'));
}
const updater = new template_updater_1.TemplateUpdater();
if (options.checkOnly) {
await updater.checkForUpdates(options);
console.log(chalk_1.default.green('✅ Update check completed!'));
console.log(chalk_1.default.yellow('💡 Run without --check-only to perform the update'));
}
else if (options.dryRun) {
await updater.dryRunUpdate(options);
console.log(chalk_1.default.green('✅ Dry run completed!'));
console.log(chalk_1.default.yellow('💡 Run without --dry-run to perform the actual update'));
}
else {
await updater.update(options);
console.log(chalk_1.default.green('✅ Project updated successfully!'));
console.log(chalk_1.default.yellow('📝 Review the changes and test your application'));
}
}
catch (error) {
console.error(chalk_1.default.red(`❌ Failed to update project: ${error.message}`));
if (error.code === 'CONFLICT_DETECTED') {
console.log(chalk_1.default.yellow('💡 Use --force to override conflicts or resolve them manually'));
}
else if (error.code === 'VERSION_NOT_FOUND') {
console.log(chalk_1.default.yellow('💡 Check available versions with: diagramers api version --all'));
}
else if (error.code === 'BACKUP_FAILED') {
console.log(chalk_1.default.yellow('💡 Ensure you have write permissions or try without --backup'));
}
process.exit(1);
}
});
}
// Helper function to validate diagramers API project
function isDiagramersApiProject() {
const currentDir = process.cwd();
const requiredDirs = ['src/modules', 'src/core', 'src/shared'];
return requiredDirs.every(dir => fs.existsSync(path.join(currentDir, dir)));
}
//# sourceMappingURL=update.js.map