From efa98b58563fc4b1696a256fa68304f6ca2930ed Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 27 Feb 2020 21:52:37 -0700 Subject: [PATCH] fix: minor issues --- src/commands/commandreference/generate.ts | 2 +- src/ditamap/command.ts | 11 +++--- src/ditamap/main-topic-intro.ts | 4 +-- src/docs.ts | 42 ++++++++++++++++++----- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/commands/commandreference/generate.ts b/src/commands/commandreference/generate.ts index d9f5ce5d..e4a0142f 100644 --- a/src/commands/commandreference/generate.ts +++ b/src/commands/commandreference/generate.ts @@ -76,7 +76,7 @@ export default class CommandReferenceGenerate extends SfdxCommand { const warnings = []; events.on('warning', msg => { - process.stderr.write(msg); + process.stderr.write(chalk.yellow(`> ${msg}\n`)); warnings.push(msg); }); diff --git a/src/ditamap/command.ts b/src/ditamap/command.ts index 3a2bb1c2..9a59da24 100644 --- a/src/ditamap/command.ts +++ b/src/ditamap/command.ts @@ -24,7 +24,7 @@ export class Command extends Ditamap { .filter(([, flag]) => !flag.hidden) .map(([flagName, flag]) => { if (!flag.longDescription) { - 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`)); + 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.`); } return Object.assign(flag, { name: flagName, @@ -44,7 +44,7 @@ export class Command extends Ditamap { } if (!command.longDescription) { - 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`)); + events.emit('warning', `No longDescription for command ${chalk.bold(command.id)}. That command owner must add the longDescription to the command definition.`); } let fullName: string; @@ -53,6 +53,7 @@ export class Command extends Ditamap { } else { fullName = commandWithUnderscores.replace(`${topic}_`, ''); } + const state = command.state || commandMeta.state; this.data = Object.assign(command, { binary: 'sfdx', // The old style didn't have the topic or subtopic in the reference ID. @@ -60,9 +61,9 @@ export class Command extends Ditamap { helpPs: this.formatParagraphs(asString(command.help)), longDescriptionPs: this.formatParagraphs(asString(command.longDescription)), parameters, - isClosedPilotCommand: commandMeta.state === 'closedPilot', - isOpenPilotCommand: commandMeta.state === 'openPilot', - isBetaCommand: commandMeta.state === 'beta', + isClosedPilotCommand: state === 'closedPilot', + isOpenPilotCommand: state === 'openPilot', + isBetaCommand: state === 'beta', trailblazerCommunityUrl, trailblazerCommunityName }) as JsonMap; diff --git a/src/ditamap/main-topic-intro.ts b/src/ditamap/main-topic-intro.ts index c3d1540c..6a2c179e 100644 --- a/src/ditamap/main-topic-intro.ts +++ b/src/ditamap/main-topic-intro.ts @@ -8,8 +8,8 @@ import {ensureJsonMap, JsonMap} from '@salesforce/ts-types'; import chalk = require('chalk'); import {join} from 'path'; -import {Ditamap} from './ditamap'; import { events } from '../utils'; +import {Ditamap} from './ditamap'; export class MainTopicIntro extends Ditamap { constructor(topic: string, subtopic: string, subTopicMeta: JsonMap) { @@ -24,7 +24,7 @@ export class MainTopicIntro extends Ditamap { } if (!subTopicMeta.longDescription) { - 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`)); + 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.`); } super(filename, { diff --git a/src/docs.ts b/src/docs.ts index b0352f1c..40f12c3d 100644 --- a/src/docs.ts +++ b/src/docs.ts @@ -7,7 +7,7 @@ import {Plugin} from '@oclif/config'; import {fs} from '@salesforce/core'; -import {asString, Dictionary, ensure, ensureJsonMap, ensureString, JsonMap, ensureArray, isArray} from '@salesforce/ts-types'; +import {asString, Dictionary, ensure, ensureArray, ensureJsonMap, ensureString, isArray, JsonMap} from '@salesforce/ts-types'; import * as chalk from 'chalk'; import {BaseDitamap} from './ditamap/base-ditamap'; import { CLIReference } from './ditamap/cli-reference'; @@ -47,10 +47,14 @@ export class Docs { */ public async populateTopic(topic: string, subtopics: Dictionary) { const topicMeta = ensureJsonMap(this.topicMeta[topic]); - const description = asString(topicMeta.longDescription); + let description = asString(topicMeta.longDescription); if (!description) { - 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`)); - return; + description = asString(topicMeta.description); + if (!description) { + 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.`); + return; + } + 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.`); } await (new CLIReferenceTopic(topic, description).write()); @@ -72,7 +76,7 @@ export class Docs { if (!subTopicsMeta[subtopic]) { const fullTopicPath = `${topic}:${subtopic}`; - 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`)); + 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.`); continue; } @@ -92,7 +96,7 @@ export class Docs { } await new SubTopicDitamap(topic, subtopic, filenames).write(); } catch (error) { - events.emit('warning', chalk.yellow(`> Can't create topic for ${topic}:${subtopic}: ${error.message}\n`)); + events.emit('warning', `Can't create topic for ${topic}:${subtopic}: ${error.message}\n`); } } @@ -115,7 +119,14 @@ export class Docs { const topLevelTopics: Dictionary> = {}; for (const command of commands) { + if (command.hidden && !this.hidden) { + continue; + } const commandParts = ensureString(command.id).split(':'); + if (commandParts.length === 1) { + continue; // Top level topic command. Just ignore for as it is usually help for the topic. + } + const topLevelTopic = commandParts[0]; const plugin = command.plugin as unknown as Plugin; @@ -130,6 +141,15 @@ export class Docs { topics[commandParts[1]] = command; } else { const subtopic = commandParts[1]; + + try { + const topicMeta = ensureJsonMap(this.topicMeta[topLevelTopic]); + const subTopicsMeta = ensureJsonMap(topicMeta.subtopics); + if (subTopicsMeta.hidden && !this.hidden) { + continue; + } + } catch (e) {} // It means no meta so it isn't hidden, although it should always fail before here with no meta found + command.subtopic = subtopic; const existingSubTopics = topics[subtopic]; @@ -176,10 +196,10 @@ export class Docs { const commandMeta: JsonMap = {}; // Remove top level topic, since the topic meta is already for that topic const commandParts = commandId.split(':'); - + let part; try { let currentMeta: JsonMap | undefined; - for (const part of commandParts) { + for (part of commandParts) { if (currentMeta) { const subtopics = ensureJsonMap(currentMeta.subtopics); currentMeta = ensureJsonMap(subtopics[part]); @@ -191,8 +211,12 @@ export class Docs { Object.assign(commandMeta, currentMeta); } } catch (error) { + if (commandId.endsWith(part)) { // This means there wasn't meta information going all the way down to the command, which is ok. - return commandMeta; + return commandMeta; + } else { + events.emit('warning', `subtopic "${part}" meta not found for command ${commandId}`) + } } return commandMeta; }