import {applyPatch, undoPatch,type Patch} from './patchutil'; import {PATCHES} from './patches'; function help() { console.log('Usage: appd-react-native '); } function install() { const undoStack: Patch[] = []; function undoTempChanges() { for (const patch of undoStack) { try { undoPatch(patch); } catch (error) { console.error(error); console.error( '[CRITICAL]: could not undo temporary modifications. You will have to fix your project files manually!', ); } } } try { for (const patch of PATCHES) { if (applyPatch(patch)) { undoStack.push(patch); } } console.log('Installation successful.'); } catch (error) { console.error(error); console.error( '[WARNING] Aborting automatic installation. Please refer to the documentation for manual instrumentation instructions.', ); undoTempChanges(); } } function uninstall() { for (const patch of PATCHES) { try { undoPatch(patch); console.log('Successfully uninstalled appdynamics agent.'); } catch (error: unknown) { if (error instanceof Error) { console.error(error.message); } } } } // `process.argv` is: [ 'path/to/node', 'path/to/script', 'command' ] const argv = [...process.argv]; switch (argv[2]) { case 'install': { install(); break; } case 'uninstall': { uninstall(); break; } case 'upgrade': { uninstall(); install(); break; } default: { help(); } }