ng-upgrade-orchestrator
Version:
Enterprise-grade Angular Multi-Version Upgrade Orchestrator with automatic npm installation, comprehensive dependency management, and seamless integration of all 9 official Angular migrations. Safely migrate Angular applications across multiple major vers
102 lines (83 loc) ⢠3.67 kB
JavaScript
/**
* Example: Basic Angular Upgrade
*
* This example demonstrates a basic upgrade from Angular 14 to Angular 17
* using the ng-upgrade orchestrator programmatically.
*/
const { UpgradeOrchestrator } = require('../dist/index.js');
const path = require('path');
async function basicUpgradeExample() {
console.log('š Basic Angular Upgrade Example\n');
const projectPath = process.argv[2] || process.cwd();
const orchestrator = new UpgradeOrchestrator(projectPath);
// Set up progress monitoring
orchestrator.on('progress', (report) => {
console.log(`š ${report.message}`);
});
orchestrator.on('step-start', (step) => {
console.log(`š Starting: Angular ${step.fromVersion} ā ${step.toVersion}`);
});
orchestrator.on('step-complete', (step) => {
console.log(`ā
Completed: Angular ${step.fromVersion} ā ${step.toVersion}`);
});
orchestrator.on('step-failed', ({ step, error }) => {
console.log(`ā Failed: Angular ${step.fromVersion} ā ${step.toVersion}`);
console.log(` Error: ${error.message}`);
});
// Configure upgrade options
const upgradeOptions = {
targetVersion: '17',
strategy: 'balanced',
checkpointFrequency: 'major-versions',
validationLevel: 'basic',
thirdPartyHandling: 'automatic',
rollbackPolicy: 'auto-on-failure',
parallelProcessing: false
};
try {
console.log(`Target Version: Angular ${upgradeOptions.targetVersion}`);
console.log(`Strategy: ${upgradeOptions.strategy}`);
console.log(`Project Path: ${projectPath}\n`);
// Execute the upgrade
const result = await orchestrator.orchestrateUpgrade(upgradeOptions);
if (result.success) {
console.log('\nš Upgrade completed successfully!');
console.log(`ā
Upgraded from ${result.fromVersion} to ${result.toVersion}`);
console.log(`ā±ļø Duration: ${Math.round(result.duration / 1000)} seconds`);
console.log(`š Completed steps: ${result.completedSteps.length}`);
console.log(`š Checkpoints created: ${result.checkpoints.length}`);
if (result.warnings && result.warnings.length > 0) {
console.log('\nā ļø Warnings:');
result.warnings.forEach(warning => {
console.log(` ⢠${warning}`);
});
}
console.log('\nš Next steps:');
console.log(' ⢠Run your test suite to verify everything works');
console.log(' ⢠Check for any console warnings in development');
console.log(' ⢠Review the upgrade report for detailed changes');
console.log(' ⢠Consider adopting new Angular features gradually');
} else {
console.log('\nā Upgrade failed');
console.log(`Error: ${result.error?.message || 'Unknown error'}`);
if (result.rollbackAvailable) {
console.log('\nš Rollback is available');
console.log('Run the following to rollback:');
console.log(` ng-upgrade checkpoints --rollback ${result.checkpoints[result.checkpoints.length - 1]?.id}`);
}
}
} catch (error) {
console.error('\nš„ Unexpected error during upgrade:', error.message);
console.log('\nš Troubleshooting tips:');
console.log(' ⢠Ensure you have a clean git working directory');
console.log(' ⢠Check that Node.js version meets requirements');
console.log(' ⢠Verify the project is a valid Angular application');
console.log(' ⢠Try running with --dry-run first to see the upgrade plan');
}
}
// Run the example
if (require.main === module) {
basicUpgradeExample().catch(console.error);
}
module.exports = { basicUpgradeExample };