diff --git a/src/hooks/prerun/prerun.ts b/src/hooks/prerun/prerun.ts index f6d90b2a..9c949816 100644 --- a/src/hooks/prerun/prerun.ts +++ b/src/hooks/prerun/prerun.ts @@ -1,11 +1,25 @@ +import * as path from 'node:path'; import type { Hook } from '@oclif/core'; import debug from 'debug'; -const hook: Hook<'prerun'> = async (opts) => { - // If JSON flag is enabled, silence debug logging - if (opts.Command.prototype.jsonEnabled()) { +const hook: Hook<'prerun'> = async function (this: Hook.Context, { Command }) { + if (Command.prototype.jsonEnabled()) { debug.disable(); } + + if (Command.id === 'update') { + const isNpm = this.config.root.split(path.sep).includes('node_modules'); + + if (isNpm) { + this.warn('The update command is not supported for npm installations.'); + this.log('\nTo update to the latest, run:\n'); + this.log(' npm install -g @herodevs/cli@latest\n'); + this.log('\nTo update to a specific version, run:\n'); + this.log(' npm install -g @herodevs/cli@\n'); + + process.exit(0); + } + } }; export default hook;