From 29b2df3fc83008a9d223e33adff5655a962befe0 Mon Sep 17 00:00:00 2001 From: ayush-coder-hai Date: Sat, 14 Oct 2023 02:44:20 +0530 Subject: [PATCH] added the hook . --- bin/run | 1 - package.json | 10 ++++++---- src/hooks/command_not_found/myhook.ts | 8 ++++++++ test/hooks/command_not_found/myhook.test.ts | 9 +++++++++ test/tsconfig.json | 6 +----- 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 src/hooks/command_not_found/myhook.ts create mode 100644 test/hooks/command_not_found/myhook.test.ts diff --git a/bin/run b/bin/run index fcaebe51129..330b6c39987 100755 --- a/bin/run +++ b/bin/run @@ -6,7 +6,6 @@ oclif.run() .then(require('@oclif/core/flush')) .catch((err) => { const oclifHandler = require('@oclif/core/handle'); - console.error(err.message); return oclifHandler(err.message); }); diff --git a/package.json b/package.json index e4977822120..2301604cbe7 100644 --- a/package.json +++ b/package.json @@ -103,9 +103,9 @@ "oclif": { "commands": "./lib/commands", "bin": "asyncapi", - "plugins": [ - "@oclif/plugin-not-found" - ], + "plugins": [], + "hooks": { + "command_not_found": ["./lib/hooks/command_not_found/myhook"] }, "macos": { "identifier": "com.asyncapi.cli" }, @@ -151,7 +151,9 @@ "release": "semantic-release", "test": "npm run test:unit", "test:unit": "cross-env NODE_ENV=development TEST=1 CUSTOM_CONTEXT_FILENAME=\"test.asyncapi-cli\" CUSTOM_CONTEXT_FILE_LOCATION=\"\" nyc --extension .ts mocha --require ts-node/register --require test/helpers/init.js --reporter spec --timeout 100000 \"test/**/*.test.ts\"", - "get-version": "echo $npm_package_version" + "get-version": "echo $npm_package_version", + "createhook": "oclif generate hook myhook --event=command_not_found", + "createhookinit": "oclif generate hook inithook --event=init" }, "types": "lib/index.d.ts" } diff --git a/src/hooks/command_not_found/myhook.ts b/src/hooks/command_not_found/myhook.ts new file mode 100644 index 00000000000..3a1223e40c6 --- /dev/null +++ b/src/hooks/command_not_found/myhook.ts @@ -0,0 +1,8 @@ +import {Hook} from '@oclif/core' + +const hook: Hook<'command_not_found'> = async function (opts) { + if(opts.id === "help"){ process.stdout.write(`help hook running ${opts.id}\n`))} + +} + +export default hook diff --git a/test/hooks/command_not_found/myhook.test.ts b/test/hooks/command_not_found/myhook.test.ts new file mode 100644 index 00000000000..28fb6c936fd --- /dev/null +++ b/test/hooks/command_not_found/myhook.test.ts @@ -0,0 +1,9 @@ +import {expect, test} from '@oclif/test' + +describe('hooks', () => { + test + .stdout() + .hook('init', {id: 'mycommand'}) + .do(output => expect(output.stdout).to.contain('example hook running mycommand')) + .it('shows a message') +}) diff --git a/test/tsconfig.json b/test/tsconfig.json index 8c82b0a0459..fa355fb9797 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -3,9 +3,5 @@ "compilerOptions": { "noEmit": true, }, - "references": [ - { - "path": "../" - } - ] + }