From ae23ac7b5b4e50dd8b8e10e649d1413790a25930 Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Tue, 28 Jul 2020 15:52:25 -0700 Subject: [PATCH 1/5] feat: support src/command/index cmd --- src/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.ts b/src/plugin.ts index 4aef4eed..c4449962 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -231,7 +231,7 @@ export class Plugin implements IPlugin { .map(file => { const p = path.parse(file) const topics = p.dir.split('/') - const command = p.name !== 'index' && p.name + const command = (p.name !== 'index' && p.name) || (p.dir.length === 0 && p.name === 'index' && '') return [...topics, command].filter(f => f).join(':') }) this._debug('found commands', ids) From 41a4df7fc708970dce5188b6164663082018983a Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Wed, 29 Jul 2020 11:51:44 -0700 Subject: [PATCH 2/5] only allow for core plugins --- src/plugin.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugin.ts b/src/plugin.ts index c4449962..2d8de652 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -231,8 +231,14 @@ export class Plugin implements IPlugin { .map(file => { const p = path.parse(file) const topics = p.dir.split('/') - const command = (p.name !== 'index' && p.name) || (p.dir.length === 0 && p.name === 'index' && '') + const command = (p.name !== 'index' && p.name) || + (this.type === 'core' && p.dir.length === 0 && p.name === 'index' && '') return [...topics, command].filter(f => f).join(':') + // Note: if a cli "root" command is present, this works b/c + // empty strings are falsey + // but an empty array join'd returns an empty string + // which is the ID of a cli "root" command + // ['', ''] => [] then [].join(':') => '' }) this._debug('found commands', ids) return ids From 94c2a6d5418f7f1bfd37946ac6f82028a8bd1d75 Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Thu, 30 Jul 2020 14:43:51 -0700 Subject: [PATCH 3/5] chad suggestion, much easier to read --- src/plugin.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index 2d8de652..db76e508 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -11,6 +11,7 @@ import {Topic} from './topic' import {tsPath} from './ts-node' import {compact, exists, flatMap, loadJSON, mapValues} from './util' +const ROOT_INDEX_CMD_ID = '' export interface Options { root: string; name?: string; @@ -231,14 +232,10 @@ export class Plugin implements IPlugin { .map(file => { const p = path.parse(file) const topics = p.dir.split('/') - const command = (p.name !== 'index' && p.name) || - (this.type === 'core' && p.dir.length === 0 && p.name === 'index' && '') + const command = (p.name !== 'index' && p.name) + // support src/commands/index as a "root" command + if (!command && this.type === 'core' && p.dir.length === 0 && p.name === 'index') return ROOT_INDEX_CMD_ID return [...topics, command].filter(f => f).join(':') - // Note: if a cli "root" command is present, this works b/c - // empty strings are falsey - // but an empty array join'd returns an empty string - // which is the ID of a cli "root" command - // ['', ''] => [] then [].join(':') => '' }) this._debug('found commands', ids) return ids From d34b56cbab8cf0cbe58348553ace882216b783b2 Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Thu, 30 Jul 2020 14:45:37 -0700 Subject: [PATCH 4/5] less diff --- src/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.ts b/src/plugin.ts index db76e508..ee6f6f90 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -232,7 +232,7 @@ export class Plugin implements IPlugin { .map(file => { const p = path.parse(file) const topics = p.dir.split('/') - const command = (p.name !== 'index' && p.name) + const command = p.name !== 'index' && p.name // support src/commands/index as a "root" command if (!command && this.type === 'core' && p.dir.length === 0 && p.name === 'index') return ROOT_INDEX_CMD_ID return [...topics, command].filter(f => f).join(':') From d61f236ac9607c68fb9d77a27f555bc68ccfd430 Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Thu, 30 Jul 2020 14:46:12 -0700 Subject: [PATCH 5/5] ws linting --- src/plugin.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugin.ts b/src/plugin.ts index ee6f6f90..5dc82363 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -12,6 +12,7 @@ import {tsPath} from './ts-node' import {compact, exists, flatMap, loadJSON, mapValues} from './util' const ROOT_INDEX_CMD_ID = '' + export interface Options { root: string; name?: string;