Skip to content

Commit efa98b5

Browse files
committed
fix: minor issues
1 parent a572fbf commit efa98b5

4 files changed

Lines changed: 42 additions & 17 deletions

File tree

src/commands/commandreference/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
7676

7777
const warnings = [];
7878
events.on('warning', msg => {
79-
process.stderr.write(msg);
79+
process.stderr.write(chalk.yellow(`> ${msg}\n`));
8080
warnings.push(msg);
8181
});
8282

src/ditamap/command.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Command extends Ditamap {
2424
.filter(([, flag]) => !flag.hidden)
2525
.map(([flagName, flag]) => {
2626
if (!flag.longDescription) {
27-
events.emit('warning', chalk.yellow(`> No flag longDescription for command ${chalk.bold(command.id)} on flag ${flagName}. That command owner must add the longDescription to the flag definition.\n`));
27+
events.emit('warning', `No flag longDescription for command ${chalk.bold(command.id)} on flag ${flagName}. That command owner must add the longDescription to the flag definition.`);
2828
}
2929
return Object.assign(flag, {
3030
name: flagName,
@@ -44,7 +44,7 @@ export class Command extends Ditamap {
4444
}
4545

4646
if (!command.longDescription) {
47-
events.emit('warning', chalk.yellow(`> No longDescription for command ${chalk.bold(command.id)}. That command owner must add the longDescription to the command definition.\n`));
47+
events.emit('warning', `No longDescription for command ${chalk.bold(command.id)}. That command owner must add the longDescription to the command definition.`);
4848
}
4949

5050
let fullName: string;
@@ -53,16 +53,17 @@ export class Command extends Ditamap {
5353
} else {
5454
fullName = commandWithUnderscores.replace(`${topic}_`, '');
5555
}
56+
const state = command.state || commandMeta.state;
5657
this.data = Object.assign(command, {
5758
binary: 'sfdx',
5859
// The old style didn't have the topic or subtopic in the reference ID.
5960
full_name_with_underscores: fullName,
6061
helpPs: this.formatParagraphs(asString(command.help)),
6162
longDescriptionPs: this.formatParagraphs(asString(command.longDescription)),
6263
parameters,
63-
isClosedPilotCommand: commandMeta.state === 'closedPilot',
64-
isOpenPilotCommand: commandMeta.state === 'openPilot',
65-
isBetaCommand: commandMeta.state === 'beta',
64+
isClosedPilotCommand: state === 'closedPilot',
65+
isOpenPilotCommand: state === 'openPilot',
66+
isBetaCommand: state === 'beta',
6667
trailblazerCommunityUrl,
6768
trailblazerCommunityName
6869
}) as JsonMap;

src/ditamap/main-topic-intro.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import {ensureJsonMap, JsonMap} from '@salesforce/ts-types';
99
import chalk = require('chalk');
1010
import {join} from 'path';
11-
import {Ditamap} from './ditamap';
1211
import { events } from '../utils';
12+
import {Ditamap} from './ditamap';
1313

1414
export class MainTopicIntro extends Ditamap {
1515
constructor(topic: string, subtopic: string, subTopicMeta: JsonMap) {
@@ -24,7 +24,7 @@ export class MainTopicIntro extends Ditamap {
2424
}
2525

2626
if (!subTopicMeta.longDescription) {
27-
events.emit('warning', chalk.yellow(`> No long description for topic ${chalk.bold(topic + ':' + subtopic)}. That topic owner must add a longDescription to the topic metadata in the oclif section in the package.json file within their plugin.\n`));
27+
events.emit('warning', `No long description for topic ${chalk.bold(topic + ':' + subtopic)}. That topic owner must add a longDescription to the topic metadata in the oclif section in the package.json file within their plugin.`);
2828
}
2929

3030
super(filename, {

src/docs.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import {Plugin} from '@oclif/config';
99
import {fs} from '@salesforce/core';
10-
import {asString, Dictionary, ensure, ensureJsonMap, ensureString, JsonMap, ensureArray, isArray} from '@salesforce/ts-types';
10+
import {asString, Dictionary, ensure, ensureArray, ensureJsonMap, ensureString, isArray, JsonMap} from '@salesforce/ts-types';
1111
import * as chalk from 'chalk';
1212
import {BaseDitamap} from './ditamap/base-ditamap';
1313
import { CLIReference } from './ditamap/cli-reference';
@@ -47,10 +47,14 @@ export class Docs {
4747
*/
4848
public async populateTopic(topic: string, subtopics: Dictionary<Dictionary | Dictionary[]>) {
4949
const topicMeta = ensureJsonMap(this.topicMeta[topic]);
50-
const description = asString(topicMeta.longDescription);
50+
let description = asString(topicMeta.longDescription);
5151
if (!description) {
52-
events.emit('warning', chalk.yellow(`> No longDescription for topic ${chalk.bold(topic)}. That topic owner must add topic metadata, that includes longDescription, in the oclif section in the package.json file within their plugin.\n`));
53-
return;
52+
description = asString(topicMeta.description);
53+
if (!description) {
54+
events.emit('warning', `No longDescription for topic ${chalk.bold(topic)}. Skipping until topic owner adds topic metadata, that includes longDescription, in the oclif section in the package.json file within their plugin.`);
55+
return;
56+
}
57+
events.emit('warning', `No longDescription for topic ${chalk.bold(topic)} 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.`);
5458
}
5559
await (new CLIReferenceTopic(topic, description).write());
5660

@@ -72,7 +76,7 @@ export class Docs {
7276

7377
if (!subTopicsMeta[subtopic]) {
7478
const fullTopicPath = `${topic}:${subtopic}`;
75-
events.emit('warning', chalk.yellow(`> No metadata for topic ${chalk.bold(fullTopicPath)}. That topic owner must add topic metadata in the oclif section in the package.json file within their plugin.\n`));
79+
events.emit('warning', `No metadata for topic ${chalk.bold(fullTopicPath)}. That topic owner must add topic metadata in the oclif section in the package.json file within their plugin.`);
7680
continue;
7781
}
7882

@@ -92,7 +96,7 @@ export class Docs {
9296
}
9397
await new SubTopicDitamap(topic, subtopic, filenames).write();
9498
} catch (error) {
95-
events.emit('warning', chalk.yellow(`> Can't create topic for ${topic}:${subtopic}: ${error.message}\n`));
99+
events.emit('warning', `Can't create topic for ${topic}:${subtopic}: ${error.message}\n`);
96100
}
97101
}
98102

@@ -115,7 +119,14 @@ export class Docs {
115119
const topLevelTopics: Dictionary<Dictionary<Dictionary | Dictionary[]>> = {};
116120

117121
for (const command of commands) {
122+
if (command.hidden && !this.hidden) {
123+
continue;
124+
}
118125
const commandParts = ensureString(command.id).split(':');
126+
if (commandParts.length === 1) {
127+
continue; // Top level topic command. Just ignore for as it is usually help for the topic.
128+
}
129+
119130
const topLevelTopic = commandParts[0];
120131

121132
const plugin = command.plugin as unknown as Plugin;
@@ -130,6 +141,15 @@ export class Docs {
130141
topics[commandParts[1]] = command;
131142
} else {
132143
const subtopic = commandParts[1];
144+
145+
try {
146+
const topicMeta = ensureJsonMap(this.topicMeta[topLevelTopic]);
147+
const subTopicsMeta = ensureJsonMap(topicMeta.subtopics);
148+
if (subTopicsMeta.hidden && !this.hidden) {
149+
continue;
150+
}
151+
} catch (e) {} // It means no meta so it isn't hidden, although it should always fail before here with no meta found
152+
133153
command.subtopic = subtopic;
134154

135155
const existingSubTopics = topics[subtopic];
@@ -176,10 +196,10 @@ export class Docs {
176196
const commandMeta: JsonMap = {};
177197
// Remove top level topic, since the topic meta is already for that topic
178198
const commandParts = commandId.split(':');
179-
199+
let part;
180200
try {
181201
let currentMeta: JsonMap | undefined;
182-
for (const part of commandParts) {
202+
for (part of commandParts) {
183203
if (currentMeta) {
184204
const subtopics = ensureJsonMap(currentMeta.subtopics);
185205
currentMeta = ensureJsonMap(subtopics[part]);
@@ -191,8 +211,12 @@ export class Docs {
191211
Object.assign(commandMeta, currentMeta);
192212
}
193213
} catch (error) {
214+
if (commandId.endsWith(part)) {
194215
// This means there wasn't meta information going all the way down to the command, which is ok.
195-
return commandMeta;
216+
return commandMeta;
217+
} else {
218+
events.emit('warning', `subtopic "${part}" meta not found for command ${commandId}`)
219+
}
196220
}
197221
return commandMeta;
198222
}

0 commit comments

Comments
 (0)