Skip to content

Commit

Permalink
feat: add hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Feb 15, 2024
1 parent d2a95b5 commit 18b9082
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
26 changes: 16 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
{
"name": "@oclif/plugin-test-bundle",
"version": "0.0.0",
"description": "Bundled plugin for testing",
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-test-bundle/issues",
"keywords": [
"oclif"
],
"bin": {
"bundle": "./bin/run.js"
},
"dependencies": {
"@oclif/core": "3.19.2-qa.1",
"@oclif/core": "3.19.2-qa.2",
"@oclif/plugin-help": "^6",
"@oclif/plugin-plugins": "^4"
},
"description": "Bundled plugin for testing",
"devDependencies": {
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^3",
Expand Down Expand Up @@ -38,7 +44,6 @@
"homepage": "https://github.com/oclif/plugin-test-bundle",
"license": "MIT",
"main": "dist/index.js",
"name": "@oclif/plugin-test-bundle",
"oclif": {
"bin": "bundle",
"dirname": "bundle",
Expand All @@ -56,23 +61,24 @@
"hello": {
"description": "Say hello to the world and others"
}
},
"hooks": {
"init": {
"target": "./dist/index.js",
"identifier": "INIT_HOOK"
}
}
},
"repository": "oclif/plugin-test-bundle",
"scripts": {
"build": "shx rm -rf dist && tsc -b",
"bundle": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js",
"lint": "eslint . --ext .ts",
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "yarn lint",
"prepack": "yarn build && oclif manifest && oclif readme",
"prepare": "yarn build",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md"
},
"version": "0.0.0",
"bugs": "https://github.com/oclif/plugin-test-bundle/issues",
"keywords": [
"oclif"
],
"types": "dist/index.d.ts"
}
}
7 changes: 7 additions & 0 deletions src/hooks/init/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Hook} from '@oclif/core'

const hook: Hook<'init'> = async function (opts) {
process.stdout.write(`example hook running ${opts.id}\n`)
}

export default hook
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Hello from './commands/hello'
import HelloWorld from './commands/hello/world'
export {default as INIT_HOOK} from './hooks/init/init'

export const COMMANDS = {
hello: Hello,
'hello:alias': HelloWorld,
'hello:world': HelloWorld,
}
9 changes: 9 additions & 0 deletions test/hooks/init/init.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')
})
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1251,10 +1251,10 @@
read-package-json-fast "^3.0.0"
which "^4.0.0"

"@oclif/[email protected].1":
version "3.19.2-qa.1"
resolved "http://localhost:4873/@oclif/core/-/core-3.19.2-qa.1.tgz#dec424bccda87253f43396892c26c190a38b2a98"
integrity sha512-91hyRj0/wkEJd8gZddypD/dXKD9WdmEd83B0wpoL8iDefP05GBzO1L6YdJoE6FmUSzjrUp1khI/ZUiw5x/E2tw==
"@oclif/[email protected].2":
version "3.19.2-qa.2"
resolved "http://localhost:4873/@oclif/core/-/core-3.19.2-qa.2.tgz#b228dd9494aed7ac53b33f1e9173e4db16237bb6"
integrity sha512-Ect2uhoTpZ3Vx8lDPrPoda4gSKWzftQaTkct6vk+OQSYeWtjhELqKflRu4lUXU1a9r9E0Hb3ay9Zv28sSgKHaA==
dependencies:
"@types/cli-progress" "^3.11.5"
ansi-escapes "^4.3.2"
Expand Down

0 comments on commit 18b9082

Please sign in to comment.