diff --git a/src/generators/command.ts b/src/generators/command.ts index 459d8a0a..305c5139 100644 --- a/src/generators/command.ts +++ b/src/generators/command.ts @@ -24,7 +24,11 @@ export interface CommandGeneratorOptions extends Generator.GeneratorOptions { unit: boolean; } -export function addTopics(newCmd: string, commands: string[] = []): Record { +export function addTopics( + newCmd: string, + existingTopics: Record, + commands: string[] = [] +): Record { const updated: Record = {}; const paths: string[] = []; @@ -45,12 +49,14 @@ export function addTopics(newCmd: string, commands: string[] = []): Record>(); const commands = commandSnapshot.map((c) => c.command.replace(/:/g, '.')); - const newTopics = addTopics(this.options.name, commands); + const newTopics = addTopics(this.options.name, this.pjson.oclif.topics, commands); this.pjson.oclif.topics = { ...this.pjson.oclif.topics, ...newTopics }; this.internalPlugin = true; } else { - const newTopics = addTopics(this.options.name); + const newTopics = addTopics(this.options.name, this.pjson.oclif.topics); this.pjson.oclif.topics = { ...this.pjson.oclif.topics, ...newTopics }; } diff --git a/test/commands/dev/generate/command.nut.ts b/test/commands/dev/generate/command.nut.ts index c2bc618b..9077fef0 100644 --- a/test/commands/dev/generate/command.nut.ts +++ b/test/commands/dev/generate/command.nut.ts @@ -100,11 +100,30 @@ describe('dev generate command NUTs', () => { }); describe('generated command under existing topic', () => { - const name = 'deploy:awesome:stuff'; - const command = `dev generate command --name ${name} --force --nuts --unit`; - before(async () => { - execCmd(command, { ensureExitCode: 0, cli: 'sf', cwd: session.project.dir }); + execCmd('dev generate command --name deploy:awesome:stuff --force --nuts --unit', { + ensureExitCode: 0, + cli: 'sf', + cwd: session.project.dir, + }); + + execCmd('dev generate command --name hello:every:one --force --nuts --unit', { + ensureExitCode: 0, + cli: 'sf', + cwd: session.project.dir, + }); + }); + + it('should add new subtopics in package.json', async () => { + const packageJson = readJson(path.join(session.project.dir, 'package.json')); + expect(packageJson.oclif.topics.hello).to.deep.equal({ + description: 'Commands to say hello.', + subtopics: { + every: { + description: 'description for hello.every', + }, + }, + }); }); it('should add new topics in package.json', async () => {