Skip to content

Commit 99c3aa6

Browse files
authored
fix: improve types (#99)
* fix: improve types * chore: regenerate yarn.lock
1 parent 6887f0b commit 99c3aa6

7 files changed

Lines changed: 1353 additions & 2156 deletions

File tree

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
"@typescript-eslint/eslint-plugin": "^4.2.0",
2929
"@typescript-eslint/parser": "^4.2.0",
3030
"chai": "^4.2.0",
31-
"eslint": "^6.8.0",
31+
"eslint": "^7.27.0",
3232
"eslint-config-prettier": "^6.11.0",
3333
"eslint-config-salesforce": "^0.1.6",
3434
"eslint-config-salesforce-license": "^0.1.6",
3535
"eslint-config-salesforce-typescript": "^0.2.7",
3636
"eslint-plugin-header": "^3.0.0",
37-
"eslint-plugin-import": "^2.20.2",
38-
"eslint-plugin-jsdoc": "^27.0.3",
37+
"eslint-plugin-import": "2.24.2",
38+
"eslint-plugin-jsdoc": "^35.1.2",
3939
"eslint-plugin-prettier": "^3.1.3",
4040
"husky": "^7.0.4",
4141
"mocha": "^9.1.3",
@@ -49,7 +49,7 @@
4949
"typescript": "^4.1.3"
5050
},
5151
"engines": {
52-
"node": ">=12.0.0"
52+
"node": ">=14.0.0"
5353
},
5454
"files": [
5555
"/lib",

src/commands/commandreference/generate.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import * as os from 'os';
99
import * as path from 'path';
1010
import { readJSON, pathExists } from 'fs-extra';
1111
import { SfCommand } from '@salesforce/sf-plugins-core';
12-
import { Flags } from '@oclif/core';
13-
import { Plugin } from '@oclif/core/lib/interfaces/plugin';
12+
import { Flags, Interfaces } from '@oclif/core';
1413
import { Messages, SfError } from '@salesforce/core';
1514
import { AnyJson, Dictionary, ensure, getString, JsonMap } from '@salesforce/ts-types';
1615
import chalk = require('chalk');
1716
import { Ditamap } from '../../ditamap/ditamap';
1817
import { Docs } from '../../docs';
19-
import { events, mergeDeep } from '../../utils';
18+
import { events, mergeDeep, CommandClass } from '../../utils';
2019

2120
// eslint-disable-next-line @typescript-eslint/no-var-requires
2221
const uniqBy = require('lodash.uniqby');
@@ -74,6 +73,7 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
7473
const ignore = [
7574
/@oclif/,
7675
/@salesforce\/cli/,
76+
/@salesforce\/plugin-dev/,
7777
/@salesforce\/plugin-telemetry/,
7878
/@salesforce\/plugin-command-reference/,
7979
];
@@ -144,7 +144,7 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
144144
private pluginMap(plugins: string[]) {
145145
const pluginToParentPlugin: JsonMap = {};
146146

147-
const resolveChildPlugins = (parentPlugin: Plugin) => {
147+
const resolveChildPlugins = (parentPlugin: Interfaces.Plugin) => {
148148
for (const childPlugin of parentPlugin.pjson.oclif.plugins || []) {
149149
pluginToParentPlugin[childPlugin] = parentPlugin.name;
150150
resolveChildPlugins(ensure(this.getPlugin(childPlugin)));
@@ -184,7 +184,7 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
184184
return topicsMeta;
185185
}
186186

187-
private async loadCommands() {
187+
private async loadCommands(): Promise<CommandClass[]> {
188188
const promises = this.config.commands.map(async (cmd) => {
189189
try {
190190
let commandClass = await this.loadCommand(cmd);
@@ -202,14 +202,14 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
202202

203203
return obj;
204204
} catch (error) {
205-
return Object.assign({} as JsonMap, cmd);
205+
return Object.assign({}, cmd);
206206
}
207207
});
208208
const commands = await Promise.all(promises);
209209
return uniqBy(commands, 'id');
210210
}
211211

212-
private async loadCommand(command) {
212+
private async loadCommand(command: Interfaces.Command.Loadable): Promise<Interfaces.Command.Class> {
213213
return command.load.constructor.name === 'AsyncFunction' ? await command.load() : command.load();
214214
}
215215

src/ditamap/command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
ensureString,
1616
JsonMap,
1717
} from '@salesforce/ts-types';
18-
import { events, punctuate } from '../utils';
18+
import { CommandClass, events, punctuate } from '../utils';
1919
import { Ditamap } from './ditamap';
2020

2121
export type CommandHelpInfo = {
@@ -47,7 +47,7 @@ const getDefault = async (flag: CommandHelpInfo): Promise<string> => {
4747
export class Command extends Ditamap {
4848
private flags: Dictionary<CommandHelpInfo>;
4949

50-
public constructor(topic: string, subtopic: string, command: Dictionary, commandMeta: JsonMap = {}) {
50+
public constructor(topic: string, subtopic: string, command: CommandClass, commandMeta: JsonMap = {}) {
5151
const commandWithUnderscores = ensureString(command.id).replace(/:/g, '_');
5252
const filename = Ditamap.file(`cli_reference_${commandWithUnderscores}`, 'xml');
5353

@@ -109,7 +109,7 @@ export class Command extends Ditamap {
109109
isBetaCommand: state === 'beta',
110110
trailblazerCommunityUrl,
111111
trailblazerCommunityName,
112-
}) as JsonMap;
112+
});
113113

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

src/ditamap/main-topic-intro.ts

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

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

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

17-
let trailblazerCommunityUrl;
18-
let trailblazerCommunityName;
17+
let trailblazerCommunityUrl: AnyJson;
18+
let trailblazerCommunityName: AnyJson;
1919
if (subTopicMeta.trailblazerCommunityLink) {
2020
const community = ensureJsonMap(subTopicMeta.trailblazerCommunityLink);
2121
trailblazerCommunityUrl = community.url;

src/docs.ts

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

88
import * as mkdirp from 'mkdirp';
9-
import { Plugin } from '@oclif/config';
109
import {
1110
asString,
1211
Dictionary,
@@ -23,7 +22,7 @@ import { CLIReference } from './ditamap/cli-reference';
2322
import { Command } from './ditamap/command';
2423
import { TopicCommands } from './ditamap/topic-commands';
2524
import { TopicDitamap } from './ditamap/topic-ditamap';
26-
import { events, punctuate } from './utils';
25+
import { CommandClass, events, punctuate } from './utils';
2726
import { HelpReference } from './ditamap/help-reference';
2827

2928
function emitNoTopicMetadataWarning(topic: string): void {
@@ -44,14 +43,14 @@ export class Docs {
4443
private cliMeta: JsonMap
4544
) {}
4645

47-
public async build(commands: JsonMap[]): Promise<void> {
46+
public async build(commands: CommandClass[]): Promise<void> {
4847
// Create if doesn't exist
4948
await mkdirp(this.outputDir);
5049

5150
await this.populateTemplate(commands);
5251
}
5352

54-
public async populateTopic(topic: string, subtopics: Dictionary<Dictionary | Dictionary[]>): Promise<any[]> {
53+
public async populateTopic(topic: string, subtopics: Dictionary<CommandClass | CommandClass[]>): Promise<any[]> {
5554
const topicMeta = ensureJsonMap(
5655
this.topicMeta[topic],
5756
`No topic meta for ${topic} - add this topic to the oclif section of the package.json.`
@@ -127,8 +126,8 @@ export class Docs {
127126
* @param commands - The entire set of command data.
128127
* @returns The commands grouped by topics/subtopic/commands.
129128
*/
130-
private groupTopicsAndSubtopics(commands: JsonMap[]) {
131-
const topLevelTopics: Dictionary<Dictionary<Dictionary | Dictionary[]>> = {};
129+
private groupTopicsAndSubtopics(commands: CommandClass[]): Dictionary<Dictionary<CommandClass | CommandClass[]>> {
130+
const topLevelTopics: Dictionary<Dictionary<CommandClass | CommandClass[]>> = {};
132131

133132
for (const command of commands) {
134133
if (command.hidden && !this.hidden) {
@@ -137,7 +136,7 @@ export class Docs {
137136
const commandParts = ensureString(command.id).split(':');
138137
const topLevelTopic = commandParts[0];
139138

140-
const plugin = command.plugin as unknown as Plugin;
139+
const plugin = command.plugin;
141140
if (this.plugins[plugin.name]) {
142141
// Also include the namespace on the commands so we don't need to do the split at other times in the code.
143142
command.topic = topLevelTopic;
@@ -179,7 +178,7 @@ export class Docs {
179178
return topLevelTopics;
180179
}
181180

182-
private async populateTemplate(commands: JsonMap[]) {
181+
private async populateTemplate(commands: CommandClass[]) {
183182
const topicsAndSubtopics = this.groupTopicsAndSubtopics(commands);
184183

185184
await new CLIReference().write();
@@ -234,7 +233,7 @@ export class Docs {
234233
return commandMeta;
235234
}
236235

237-
private async populateCommand(topic: string, subtopic: string, command: Dictionary, commandMeta: JsonMap) {
236+
private async populateCommand(topic: string, subtopic: string, command: CommandClass, commandMeta: JsonMap) {
238237
// If it is a hidden command - abort
239238
if (command.hidden && !this.hidden) {
240239
return '';

src/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
import { EventEmitter } from 'events';
99
import { EOL } from 'os';
10-
import { Dictionary, isObject } from '@salesforce/ts-types';
10+
import { Dictionary, isObject, JsonMap } from '@salesforce/ts-types';
11+
import { Interfaces } from '@oclif/core';
12+
13+
export type CommandClass = Interfaces.Command.Class & { topic: string; subtopic: string } & JsonMap;
1114

1215
export const events = new EventEmitter();
1316

0 commit comments

Comments
 (0)