diff --git a/package.json b/package.json index 0d95665c..c077b810 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@types/indent-string": "^3.0.0", "@types/lodash": "^4.14.116", "@types/mocha": "^5.2.5", - "@types/node": "^10.9.2", + "@types/node": "^10.9.4", "@types/wrap-ansi": "^3.0.0", "chai": "^4.1.2", "fancy-test": "^1.3.0", @@ -26,7 +26,7 @@ "mocha": "^5.2.0", "ts-node": "^7.0.1", "tslint": "^5.11.0", - "typescript": "^3.0.1" + "typescript": "^3.0.3" }, "engines": { "node": ">=8.0.0" diff --git a/src/plugin.ts b/src/plugin.ts index 909eedad..f1796e0e 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -246,6 +246,7 @@ function topicsToArray(input: any, base?: string): Topic[] { return input.concat(flatMap(input, t => topicsToArray(t.subtopics, `${base}${t.name}`))) } return flatMap(Object.keys(input), k => { + input[k].name = k return [{...input[k], name: `${base}${k}`}].concat(topicsToArray(input[k].subtopics, `${base}${input[k].name}`)) }) } diff --git a/test/config.test.ts b/test/config.test.ts index 77aa92d8..7fc9a7ca 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -2,23 +2,28 @@ import * as os from 'os' import * as path from 'path' import {IConfig, load, PJSON} from '../src' +import * as util from '../src/util' import {expect, fancy} from './test' interface Options { + pjson?: any, homedir?: string, platform?: string, env?: {[k: string]: string}, } describe('Config', () => { - const testConfig = ({homedir = '/my/home', platform = 'darwin', env = {}}: Options = {}) => { - const test = fancy + const testConfig = ({pjson, homedir = '/my/home', platform = 'darwin', env = {}}: Options = {}) => { + let test = fancy .resetConfig() .env(env, {clear: true}) .stub(os, 'homedir', () => path.join(homedir)) .stub(os, 'platform', () => platform) - .add('config', () => load()) + + if (pjson) test = test.stub(util, 'loadJSON', () => Promise.resolve(pjson)) + + test = test.add('config', () => load()) return { hasS3Key(k: keyof PJSON.S3.Templates, expected: string, extra: any = {}) { @@ -108,4 +113,33 @@ describe('Config', () => { expect(config.s3Url('/b/c')).to.equal('https://bar.com/a/b/c') config.pjson.oclif.update.s3.host = orig }) + + testConfig({ + pjson: { + name: 'foo', + oclif: { + topics: { + t1: { + description: 'desc for t1', + subtopics: { + 't1-1': { + description: 'desc for t1-1', + subtopics: { + 't1-1-1': { + description: 'desc for t1-1-1' + }, + 't1-1-2': { + description: 'desc for t1-1-2' + } + } + } + } + } + } + } + } + }) + .it('has subtopics', config => { + expect(config.topics.map(t => t.name)).to.have.members(['t1', 't1:t1-1', 't1:t1-1:t1-1-1', 't1:t1-1:t1-1-2']) + }) }) diff --git a/yarn.lock b/yarn.lock index 83c9f6b7..6f8a8462 100644 --- a/yarn.lock +++ b/yarn.lock @@ -107,9 +107,9 @@ version "10.7.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.7.1.tgz#b704d7c259aa40ee052eec678758a68d07132a2e" -"@types/node@^10.9.2": - version "10.9.2" - resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.2.tgz#f0ab8dced5cd6c56b26765e1c0d9e4fdcc9f2a00" +"@types/node@^10.9.4": + version "10.9.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.4.tgz#0f4cb2dc7c1de6096055357f70179043c33e9897" "@types/sinon@^5.0.1": version "5.0.1" @@ -1229,9 +1229,9 @@ type-detect@^4.0.0: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" -typescript@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb" +typescript@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8" union-value@^1.0.0: version "1.0.0"