Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/hooks/prerun/prerun.ts
Original file line number Diff line number Diff line change
@@ -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@<version>\n');

process.exit(0);
}
}
};

export default hook;