Skip to content

Commit 1513a0f

Browse files
authored
Merge pull request #2 from forcedotcom/td/update
feat: support no long description
2 parents a89171b + 4b5dabc commit 1513a0f

File tree

8 files changed

+1370
-976
lines changed

8 files changed

+1370
-976
lines changed

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"@salesforce/prettier-config"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
"@oclif/plugin-help": "^2.2.3",
2020
"@oclif/test": "^1.2.5",
2121
"@salesforce/dev-scripts": "^0.4.2",
22+
"@salesforce/prettier-config": "^0.0.1",
2223
"@semantic-release/changelog": "^5.0.0",
2324
"@semantic-release/git": "^9.0.0",
2425
"husky": "^4.2.3",
25-
"salesforcedx": "^48.4.1",
26+
"salesforcedx": "48.4.1",
2627
"semantic-release": "^17.0.4"
2728
},
2829
"engines": {

src/ditamap/command.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
*/
77

88
import { asString, Dictionary, ensureJsonMap, ensureObject, ensureString, JsonMap } from '@salesforce/ts-types';
9-
import chalk = require('chalk');
109
import { join } from 'path';
11-
import { events } from '../utils';
10+
import { punctuate } from '../utils';
1211
import { Ditamap } from './ditamap';
1312

1413
export class Command extends Ditamap {
@@ -24,12 +23,7 @@ export class Command extends Ditamap {
2423
.filter(([, flag]) => !flag.hidden)
2524
.map(([flagName, flag]) => {
2625
if (!flag.longDescription) {
27-
events.emit(
28-
'warning',
29-
`No flag longDescription for command "${chalk.bold(command.id)}" on flag "${chalk.bold(
30-
flagName
31-
)}". That command owner must add the longDescription to the flag definition.`
32-
);
26+
flag.longDescription = punctuate(flag.description);
3327
}
3428
return Object.assign(flag, {
3529
name: flagName,
@@ -49,12 +43,7 @@ export class Command extends Ditamap {
4943
}
5044

5145
if (!command.longDescription) {
52-
events.emit(
53-
'warning',
54-
`No longDescription for command ${chalk.bold(
55-
command.id
56-
)}. That command owner must add the longDescription to the command definition.`
57-
);
46+
command.longDescription = punctuate(asString(command.description));
5847
}
5948

6049
let fullName: string;

src/ditamap/main-topic-intro.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { ensureJsonMap, JsonMap } from '@salesforce/ts-types';
9-
import chalk = require('chalk');
8+
import { asString, ensureJsonMap, JsonMap } from '@salesforce/ts-types';
109
import { join } from 'path';
11-
import { events } from '../utils';
10+
import { punctuate } from '../utils';
1211
import { Ditamap } from './ditamap';
1312

1413
export class MainTopicIntro extends Ditamap {
@@ -24,17 +23,12 @@ export class MainTopicIntro extends Ditamap {
2423
}
2524

2625
if (!subTopicMeta.longDescription && !subTopicMeta.external) {
27-
events.emit(
28-
'warning',
29-
`No long description for topic ${chalk.bold(
30-
topic + ':' + subtopic
31-
)}. That topic owner must add a longDescription to the topic metadata in the oclif section in the package.json file within their plugin.`
32-
);
26+
subTopicMeta.longDescription = punctuate(asString(subTopicMeta.description));
3327
}
3428

3529
super(filename, {
3630
topic: subtopic,
37-
longDescription: subTopicMeta.longDescription || subTopicMeta.description,
31+
longDescription: subTopicMeta.longDescription,
3832
isOpenPilotTopic: subTopicMeta.state === 'openPilot',
3933
isClosedPilotTopic: subTopicMeta.state === 'closedPilot',
4034
isBetaTopic: subTopicMeta.state === 'beta',

src/docs.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Command } from './ditamap/command';
2626
import { MainTopicIntro } from './ditamap/main-topic-intro';
2727
import { SubTopicDitamap } from './ditamap/subtopic-ditamap';
2828
import { TopicDitamap } from './ditamap/topic-ditamap';
29-
import { copyStaticFile, events } from './utils';
29+
import { copyStaticFile, events, punctuate } from './utils';
3030

3131
const templatesDir = join(__dirname, '..', 'templates');
3232

@@ -46,25 +46,23 @@ export class Docs {
4646
}
4747

4848
public async populateTopic(topic: string, subtopics: Dictionary<Dictionary | Dictionary[]>) {
49-
const topicMeta = ensureJsonMap(this.topicMeta[topic]);
49+
const topicMeta = ensureJsonMap(
50+
this.topicMeta[topic],
51+
`No topic meta for ${topic} - add this topic to the oclif section of the package.json.`
52+
);
5053
let description = asString(topicMeta.longDescription);
5154
if (!description && !topicMeta.external) {
52-
description = asString(topicMeta.description);
55+
// Punctuate the description in place of longDescription
56+
description = punctuate(asString(topicMeta.description));
5357
if (!description) {
5458
events.emit(
5559
'warning',
56-
`No longDescription for topic ${chalk.bold(
60+
`No description for topic ${chalk.bold(
5761
topic
5862
)}. Skipping until topic owner adds topic metadata, that includes longDescription, in the oclif section in the package.json file within their plugin.`
5963
);
6064
return;
6165
}
62-
events.emit(
63-
'warning',
64-
`No longDescription for topic ${chalk.bold(
65-
topic
66-
)} but found description. Still generating but topic owner must add topic metadata, that includes longDescription, in the oclif section in the package.json file within their plugin.`
67-
);
6866
}
6967
await new CLIReferenceTopic(topic, description).write();
7068

@@ -229,7 +227,7 @@ export class Docs {
229227
// Since there is no command meta, just use the command description since that is what oclif does.
230228
if (!commandMeta.description) {
231229
commandMeta.description = command.description;
232-
commandMeta.longDescription = command.longDescription;
230+
commandMeta.longDescription = command.longDescription || punctuate(command.description);
233231
}
234232
}
235233
}

src/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { fs } from '@salesforce/core';
99
import { Dictionary, isObject } from '@salesforce/ts-types';
1010
import { EventEmitter } from 'events';
1111
import { copyFileSync } from 'fs';
12+
import { EOL } from 'os';
1213
import { join } from 'path';
1314

1415
export const events = new EventEmitter();
@@ -30,3 +31,17 @@ export function mergeDeep(target: Dictionary, source: Dictionary) {
3031
});
3132
return target;
3233
}
34+
35+
export function punctuate(description: string): string {
36+
if (!description) return description;
37+
38+
const lines = description.split(EOL);
39+
let mainDescription = lines[0];
40+
41+
mainDescription = mainDescription.charAt(0).toUpperCase() + mainDescription.substring(1);
42+
43+
if (mainDescription.charAt(mainDescription.length - 1) !== '.') {
44+
mainDescription += '.';
45+
}
46+
return [mainDescription, ...lines.slice(1)].join(EOL);
47+
}

test/utils.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
import { expect } from 'chai';
9-
import { mergeDeep } from '../src/utils';
9+
import { EOL } from 'os';
10+
import { punctuate, mergeDeep } from '../src/utils';
1011

1112
it('merge two shallow objects', () => {
1213
expect(mergeDeep({ a: 1 }, { b: 2 })).to.deep.equal({ a: 1, b: 2 });
@@ -37,3 +38,19 @@ it('merge two deeply nested objects', () => {
3738
}
3839
});
3940
});
41+
42+
describe('punctuate', () => {
43+
it('description to longDescription', () => {
44+
expect(punctuate('lowercase oclif description')).to.equal('Lowercase oclif description.');
45+
});
46+
47+
it('multi line descriptions to longDescriptions', () => {
48+
expect(punctuate(`lowercase oclif description${EOL}${EOL}some other stuff`)).to.equal(
49+
`Lowercase oclif description.${EOL}${EOL}some other stuff`
50+
);
51+
});
52+
53+
it('does not add additional punctuation', () => {
54+
expect(punctuate('Uppercase longDescription.')).to.equal('Uppercase longDescription.');
55+
});
56+
});

0 commit comments

Comments
 (0)