Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit faefeb3

Browse files
committed
fix: default subtopic names
Fixes #48
1 parent c084703 commit faefeb3

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@types/indent-string": "^3.0.0",
1818
"@types/lodash": "^4.14.116",
1919
"@types/mocha": "^5.2.5",
20-
"@types/node": "^10.9.2",
20+
"@types/node": "^10.9.4",
2121
"@types/wrap-ansi": "^3.0.0",
2222
"chai": "^4.1.2",
2323
"fancy-test": "^1.3.0",
@@ -26,7 +26,7 @@
2626
"mocha": "^5.2.0",
2727
"ts-node": "^7.0.1",
2828
"tslint": "^5.11.0",
29-
"typescript": "^3.0.1"
29+
"typescript": "^3.0.3"
3030
},
3131
"engines": {
3232
"node": ">=8.0.0"

src/plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ function topicsToArray(input: any, base?: string): Topic[] {
246246
return input.concat(flatMap(input, t => topicsToArray(t.subtopics, `${base}${t.name}`)))
247247
}
248248
return flatMap(Object.keys(input), k => {
249+
input[k].name = k
249250
return [{...input[k], name: `${base}${k}`}].concat(topicsToArray(input[k].subtopics, `${base}${input[k].name}`))
250251
})
251252
}

test/config.test.ts

+37-3
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@ import * as os from 'os'
22
import * as path from 'path'
33

44
import {IConfig, load, PJSON} from '../src'
5+
import * as util from '../src/util'
56

67
import {expect, fancy} from './test'
78

89
interface Options {
10+
pjson?: any,
911
homedir?: string,
1012
platform?: string,
1113
env?: {[k: string]: string},
1214
}
1315

1416
describe('Config', () => {
15-
const testConfig = ({homedir = '/my/home', platform = 'darwin', env = {}}: Options = {}) => {
16-
const test = fancy
17+
const testConfig = ({pjson, homedir = '/my/home', platform = 'darwin', env = {}}: Options = {}) => {
18+
let test = fancy
1719
.resetConfig()
1820
.env(env, {clear: true})
1921
.stub(os, 'homedir', () => path.join(homedir))
2022
.stub(os, 'platform', () => platform)
21-
.add('config', () => load())
23+
24+
if (pjson) test = test.stub(util, 'loadJSON', () => Promise.resolve(pjson))
25+
26+
test = test.add('config', () => load())
2227

2328
return {
2429
hasS3Key(k: keyof PJSON.S3.Templates, expected: string, extra: any = {}) {
@@ -108,4 +113,33 @@ describe('Config', () => {
108113
expect(config.s3Url('/b/c')).to.equal('https://bar.com/a/b/c')
109114
config.pjson.oclif.update.s3.host = orig
110115
})
116+
117+
testConfig({
118+
pjson: {
119+
name: 'foo',
120+
oclif: {
121+
topics: {
122+
t1: {
123+
description: 'desc for t1',
124+
subtopics: {
125+
't1-1': {
126+
description: 'desc for t1-1',
127+
subtopics: {
128+
't1-1-1': {
129+
description: 'desc for t1-1-1'
130+
},
131+
't1-1-2': {
132+
description: 'desc for t1-1-2'
133+
}
134+
}
135+
}
136+
}
137+
}
138+
}
139+
}
140+
}
141+
})
142+
.it('has subtopics', config => {
143+
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'])
144+
})
111145
})

yarn.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@
107107
version "10.7.1"
108108
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.7.1.tgz#b704d7c259aa40ee052eec678758a68d07132a2e"
109109

110-
"@types/node@^10.9.2":
111-
version "10.9.2"
112-
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.2.tgz#f0ab8dced5cd6c56b26765e1c0d9e4fdcc9f2a00"
110+
"@types/node@^10.9.4":
111+
version "10.9.4"
112+
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.4.tgz#0f4cb2dc7c1de6096055357f70179043c33e9897"
113113

114114
"@types/sinon@^5.0.1":
115115
version "5.0.1"
@@ -1229,9 +1229,9 @@ type-detect@^4.0.0:
12291229
version "4.0.8"
12301230
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
12311231

1232-
typescript@^3.0.1:
1233-
version "3.0.1"
1234-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb"
1232+
typescript@^3.0.3:
1233+
version "3.0.3"
1234+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8"
12351235

12361236
union-value@^1.0.0:
12371237
version "1.0.0"

0 commit comments

Comments
 (0)