Skip to content

Commit 6fe9aa5

Browse files
committed
refactor: get rid of json map
1 parent a28ed71 commit 6fe9aa5

6 files changed

Lines changed: 17 additions & 18 deletions

File tree

src/commands/commandreference/generate.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as path from 'path';
1212
import { SfCommand } from '@salesforce/sf-plugins-core';
1313
import { Command, Flags, Interfaces } from '@oclif/core';
1414
import { Messages, SfError } from '@salesforce/core';
15-
import { AnyJson, ensure, ensureString, JsonMap } from '@salesforce/ts-types';
15+
import { AnyJson, ensure, ensureString } from '@salesforce/ts-types';
1616
import chalk = require('chalk');
1717
import { parseJsonMap } from '@salesforce/kit';
1818
import { Ditamap } from '../../ditamap/ditamap';
@@ -167,9 +167,9 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
167167
return this.config.plugins.find((info) => info.name === pluginName);
168168
}
169169

170-
private async loadTopicMetadata(): Promise<JsonMap> {
171-
const plugins: JsonMap = {};
172-
const topicsMeta: JsonMap = {};
170+
private async loadTopicMetadata(): Promise<Record<string, unknown>> {
171+
const plugins: Record<string, unknown> = {};
172+
const topicsMeta: Record<string, unknown> = {};
173173

174174
for (const cmd of this.config.commands) {
175175
// Only load topics for each plugin once
@@ -224,7 +224,7 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
224224
return command.load.constructor.name === 'AsyncFunction' ? await command.load() : command.load();
225225
}
226226

227-
private loadCliMeta(): JsonMap {
227+
private loadCliMeta(): Record<string, unknown> {
228228
return {
229229
binary: this.config.pjson.oclif.bin ?? 'sfdx',
230230
topicSeparator: this.config.pjson.oclif.topicSeparator,

src/ditamap/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { join } from 'path';
9-
import { asString, Dictionary, ensureObject, ensureString, JsonMap } from '@salesforce/ts-types';
9+
import { asString, Dictionary, ensureObject, ensureString } from '@salesforce/ts-types';
1010
import { CommandClass, punctuate } from '../utils';
1111
import { Ditamap } from './ditamap';
1212

@@ -110,7 +110,7 @@ export class Command extends Ditamap {
110110
isBetaCommand: state === 'beta',
111111
trailblazerCommunityUrl,
112112
trailblazerCommunityName,
113-
}) as JsonMap;
113+
}) as Record<string, unknown>;
114114

115115
this.destination = join(Ditamap.outputDir, topic, filename);
116116
}

src/ditamap/ditamap.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import { dirname, join } from 'path';
99
import * as fs from 'fs/promises';
10-
import { JsonMap } from '@salesforce/ts-types';
1110
import * as debugCreator from 'debug';
1211
import * as hb from 'handlebars';
1312
import { HelperOptions } from 'handlebars';
@@ -59,7 +58,7 @@ export abstract class Ditamap {
5958

6059
private readonly source: string;
6160

62-
public constructor(private filename: string, protected data: JsonMap) {
61+
public constructor(private filename: string, protected data: Record<string, unknown>) {
6362
this.source = join(Ditamap.templatesDir, this.getTemplateFileName());
6463
this.destination = join(Ditamap.outputDir, filename);
6564
}

src/ditamap/main-topic-intro.ts

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

88
import { join } from 'path';
9-
import { asString, ensureJsonMap, JsonMap } from '@salesforce/ts-types';
9+
import { asString, ensureObject } from '@salesforce/ts-types';
1010
import { punctuate } from '../utils';
1111
import { Ditamap } from './ditamap';
1212

1313
export class MainTopicIntro extends Ditamap {
14-
public constructor(topic: string, subtopic: string, subTopicMeta: JsonMap) {
14+
public constructor(topic: string, subtopic: string, subTopicMeta: Record<string, unknown>) {
1515
const filename = Ditamap.file(`cli_reference_${topic}_${subtopic}`, 'xml');
1616

1717
let trailblazerCommunityUrl: string | undefined;
1818
let trailblazerCommunityName: string | undefined;
1919
if (subTopicMeta.trailblazerCommunityLink) {
20-
const community = ensureJsonMap(subTopicMeta.trailblazerCommunityLink) as { url: string; name: string };
20+
const community = ensureObject<Record<string, unknown>>(subTopicMeta.trailblazerCommunityLink) as {
21+
url: string;
22+
name: string;
23+
};
2124
trailblazerCommunityUrl = community.url ?? 'unknown';
2225
trailblazerCommunityName = community.name ?? 'unknown';
2326
}

src/ditamap/topic-commands.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
*/
77

88
import { join } from 'path';
9-
import { JsonMap } from '@salesforce/ts-types';
109
import { Ditamap } from './ditamap';
1110

1211
export class TopicCommands extends Ditamap {
13-
public constructor(topic: string, topicMeta: JsonMap) {
12+
public constructor(topic: string, topicMeta: Record<string, unknown>) {
1413
const filename = Ditamap.file(`cli_reference_${topic}_commands`, 'xml');
1514
// Set the data of topic and filenames
1615
super(filename, topicMeta);

src/docs.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import {
1212
Dictionary,
1313
ensure,
1414
ensureArray,
15-
ensureJsonMap,
1615
ensureObject,
1716
ensureString,
1817
isArray,
19-
JsonMap,
2018
} from '@salesforce/ts-types';
2119
import * as chalk from 'chalk';
2220
import { BaseDitamap } from './ditamap/base-ditamap';
@@ -57,7 +55,7 @@ export class Docs {
5755
throw new Error(`No topic meta for ${topic} - add this topic to the oclif section of the package.json.`);
5856
}
5957

60-
const topicMeta: JsonMap = (this.topicMeta[topic] ?? {}) as JsonMap;
58+
const topicMeta: Record<string, unknown> = (this.topicMeta[topic] ?? {}) as Record<string, unknown>;
6159

6260
let description = asString(topicMeta.description);
6361
if (!description && !topicMeta.external) {
@@ -93,7 +91,7 @@ export class Docs {
9391
continue;
9492
}
9593

96-
const subTopicsMeta = ensureJsonMap(topicMeta.subtopics);
94+
const subTopicsMeta = ensureObject<Record<string, unknown>>(topicMeta.subtopics);
9795

9896
if (!subTopicsMeta[subtopic]) {
9997
emitNoTopicMetadataWarning(`${topic}:${subtopic}`);

0 commit comments

Comments
 (0)