diff --git a/src/commands/esbuild.ts b/src/commands/esbuild.ts new file mode 100644 index 0000000..9c00312 --- /dev/null +++ b/src/commands/esbuild.ts @@ -0,0 +1,36 @@ +import {Args, Command, Flags, Interfaces} from '@oclif/core' + +type Result = { + args: Interfaces.InferredArgs + flags: Interfaces.InferredFlags +} + +export default class ESBuild extends Command { + static args = { + defaultArg: Args.string({ + default: 'simple string default', + }), + defaultFnArg: Args.string({ + default: async () => 'async fn default', + }), + optionalArg: Args.string(), + } + + static enableJsonFlag = true + + static flags = { + defaultFnString: Flags.string({ + default: async () => 'async fn default', + }), + defaultString: Flags.string({ + default: 'simple string default', + }), + optionalString: Flags.string(), + } + + async run(): Promise { + const {args, flags} = await this.parse(ESBuild) + this.log(`hello I am a bundled (esbuild) plugin from ${this.config.root}!`) + return {args, flags} + } +} diff --git a/src/hooks/init/init.ts b/src/hooks/init/init.ts index d560936..7f85317 100644 --- a/src/hooks/init/init.ts +++ b/src/hooks/init/init.ts @@ -1,7 +1,7 @@ -import {Hook} from '@oclif/core' +import {Hook, ux} from '@oclif/core' -const hook: Hook<'init'> = async function (opts) { - process.stdout.write(`example hook running ${opts.id}\n`) +const hook: Hook<'init'> = async function () { + ux.log('Greetings! from plugin-test-esbuild init hook') } export default hook diff --git a/src/index.ts b/src/index.ts index 1229c12..1e243a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,10 @@ +import ESBuild from './commands/esbuild' import Hello from './commands/hello' import HelloWorld from './commands/hello/world' export {default as INIT_HOOK} from './hooks/init/init' export const COMMANDS = { + esbuild: ESBuild, hello: Hello, 'hello:alias': HelloWorld, 'hello:world': HelloWorld, diff --git a/test/commands/esbuild.test.ts b/test/commands/esbuild.test.ts new file mode 100644 index 0000000..c4b85f6 --- /dev/null +++ b/test/commands/esbuild.test.ts @@ -0,0 +1,10 @@ +import {expect, test} from '@oclif/test' + +describe('esbuild', () => { + test + .stdout() + .command(['esbuild']) + .it('runs esbuild cmd', (ctx) => { + expect(ctx.stdout).to.contain('hello I am a bundled (esbuild) plugin') + }) +}) diff --git a/test/commands/hello/world.test.ts b/test/commands/hello/world.test.ts index 8096cba..f11b33c 100644 --- a/test/commands/hello/world.test.ts +++ b/test/commands/hello/world.test.ts @@ -2,9 +2,18 @@ import {expect, test} from '@oclif/test' describe('hello world', () => { test - .stdout() - .command(['hello:world']) - .it('runs hello world cmd', ctx => { - expect(ctx.stdout).to.contain('hello world!') - }) + .stdout() + .command(['hello:world']) + .it('runs hello world cmd', (ctx) => { + expect(ctx.stdout).to.contain('hello world!') + }) +}) + +describe('hello alias', () => { + test + .stdout() + .command(['hello:alias']) + .it('runs hello alias cmd', (ctx) => { + expect(ctx.stdout).to.contain('hello world!') + }) }) diff --git a/test/hooks/init/init.test.ts b/test/hooks/init/init.test.ts index 28fb6c9..826b8e8 100644 --- a/test/hooks/init/init.test.ts +++ b/test/hooks/init/init.test.ts @@ -2,8 +2,8 @@ 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') + .stdout() + .hook('init', {id: 'mycommand'}) + .do((output) => expect(output.stdout).to.contain('Greetings! from plugin-test-esbuild init hook')) + .it('shows a message') })