Skip to content

Commit

Permalink
added the hook .
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushNautiyalDeveloper committed Oct 13, 2023
1 parent 84162fc commit 29b2df3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
1 change: 0 additions & 1 deletion bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
}
8 changes: 8 additions & 0 deletions src/hooks/command_not_found/myhook.ts
Original file line number Diff line number Diff line change
@@ -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`))}

Check failure on line 4 in src/hooks/command_not_found/myhook.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

';' expected.

}

export default hook
9 changes: 9 additions & 0 deletions test/hooks/command_not_found/myhook.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
6 changes: 1 addition & 5 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
"compilerOptions": {
"noEmit": true,
},
"references": [
{
"path": "../"
}
]

}

0 comments on commit 29b2df3

Please sign in to comment.