diff --git a/package.json b/package.json index d250355..464403c 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -56,11 +61,18 @@ "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", @@ -68,11 +80,5 @@ "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" + } } diff --git a/src/hooks/init/init.ts b/src/hooks/init/init.ts new file mode 100644 index 0000000..d560936 --- /dev/null +++ b/src/hooks/init/init.ts @@ -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 diff --git a/src/index.ts b/src/index.ts index ef86fd7..1229c12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, } diff --git a/test/hooks/init/init.test.ts b/test/hooks/init/init.test.ts new file mode 100644 index 0000000..28fb6c9 --- /dev/null +++ b/test/hooks/init/init.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/yarn.lock b/yarn.lock index 419c4dd..ceed657 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1251,10 +1251,10 @@ read-package-json-fast "^3.0.0" which "^4.0.0" -"@oclif/core@3.19.2-qa.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/core@3.19.2-qa.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"