Skip to content

Commit ec4efd5

Browse files
SF-CLI-BOTmshanemc
andauthored
fix: new TS requires handlebars import change
* chore: updates from devScripts * chore: linter updates * test: only linux * chore: bump ts * refactor: change handlebars import for bug with newer TS * chore: oclif/core not needed Co-authored-by: mshanemc <[email protected]>
1 parent 0b12641 commit ec4efd5

File tree

16 files changed

+539
-509
lines changed

16 files changed

+539
-509
lines changed

.github/workflows/notify-slack-on-pr-open.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: Notify Slack on PR open
12-
env:
13-
WEBHOOK_URL : ${{ secrets.CLI_TEAM_SLACK_WEBHOOK_URL }}
14-
PULL_REQUEST_AUTHOR_ICON_URL : ${{ github.event.pull_request.user.avatar_url }}
15-
PULL_REQUEST_AUTHOR_NAME : ${{ github.event.pull_request.user.login }}
16-
PULL_REQUEST_AUTHOR_PROFILE_URL: ${{ github.event.pull_request.user.html_url }}
17-
PULL_REQUEST_BASE_BRANCH_NAME : ${{ github.event.pull_request.base.ref }}
18-
PULL_REQUEST_COMPARE_BRANCH_NAME : ${{ github.event.pull_request.head.ref }}
19-
PULL_REQUEST_NUMBER : ${{ github.event.pull_request.number }}
20-
PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.name }}
21-
PULL_REQUEST_TITLE : ${{ github.event.pull_request.title }}
22-
PULL_REQUEST_URL : ${{ github.event.pull_request.html_url }}
23-
uses: salesforcecli/github-workflows/.github/actions/prNotification@main
11+
- name: Notify Slack on PR open
12+
env:
13+
WEBHOOK_URL: ${{ secrets.CLI_TEAM_SLACK_WEBHOOK_URL }}
14+
PULL_REQUEST_AUTHOR_ICON_URL: ${{ github.event.pull_request.user.avatar_url }}
15+
PULL_REQUEST_AUTHOR_NAME: ${{ github.event.pull_request.user.login }}
16+
PULL_REQUEST_AUTHOR_PROFILE_URL: ${{ github.event.pull_request.user.html_url }}
17+
PULL_REQUEST_BASE_BRANCH_NAME: ${{ github.event.pull_request.base.ref }}
18+
PULL_REQUEST_COMPARE_BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
19+
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
20+
PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.name }}
21+
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
22+
PULL_REQUEST_URL: ${{ github.event.pull_request.html_url }}
23+
uses: salesforcecli/github-workflows/.github/actions/prNotification@main

.github/workflows/test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ on:
66

77
jobs:
88
unit-tests:
9-
uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: lts/*
15+
cache: yarn
16+
- run: yarn install --network-timeout 600000
17+
- run: yarn build
18+
- run: yarn test

package.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,35 @@
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/plugin-command-reference/issues",
77
"dependencies": {
8-
"@salesforce/command": "^5.2.6",
9-
"@salesforce/core": "^3.25.0",
8+
"@salesforce/command": "^5.2.11",
9+
"@salesforce/core": "^3.30.10",
1010
"@types/lodash.uniqby": "^4.7.7",
1111
"chalk": "^3.0.0",
1212
"handlebars": "4.7.7",
1313
"lodash.uniqby": "^4.7.0",
1414
"shelljs": "^0.8.5",
15-
"tslib": "^1"
15+
"tslib": "^2"
1616
},
1717
"devDependencies": {
1818
"@salesforce/dev-config": "^3.1.0",
19-
"@salesforce/dev-scripts": "^2.0.4",
19+
"@salesforce/dev-scripts": "^3.1.0",
2020
"@salesforce/plugin-alias": "^2.1.0",
2121
"@salesforce/plugin-signups": "^1.2.0",
2222
"@salesforce/prettier-config": "^0.0.2",
2323
"@semantic-release/changelog": "^5.0.0",
2424
"@semantic-release/git": "^9.0.1",
2525
"@types/shelljs": "^0.8.11",
26-
"@typescript-eslint/eslint-plugin": "^4.2.0",
27-
"@typescript-eslint/parser": "^4.2.0",
26+
"@typescript-eslint/eslint-plugin": "^5.33.0",
27+
"@typescript-eslint/parser": "^5.33.0",
2828
"chai": "^4.3.6",
29-
"eslint": "^7.27.0",
30-
"eslint-config-prettier": "^6.11.0",
31-
"eslint-config-salesforce": "^0.1.6",
29+
"eslint": "^8.21.0",
30+
"eslint-config-prettier": "^8.5.0",
31+
"eslint-config-salesforce": "^1.1.0",
3232
"eslint-config-salesforce-license": "^0.1.6",
33-
"eslint-config-salesforce-typescript": "^0.2.7",
33+
"eslint-config-salesforce-typescript": "^1.1.1",
3434
"eslint-plugin-header": "^3.0.0",
3535
"eslint-plugin-import": "2.26.0",
36-
"eslint-plugin-jsdoc": "^35.1.2",
37-
"eslint-plugin-prettier": "^3.1.3",
36+
"eslint-plugin-jsdoc": "^39.3.6",
3837
"husky": "^7.0.4",
3938
"mocha": "^9.1.3",
4039
"nyc": "^15.1.0",
@@ -45,7 +44,7 @@
4544
"semantic-release": "^17.4.7",
4645
"sinon": "10.0.0",
4746
"ts-node": "^10.9.1",
48-
"typescript": "4.3"
47+
"typescript": "^4.8.4"
4948
},
5049
"engines": {
5150
"node": ">=14.0.0"
@@ -98,4 +97,4 @@
9897
"publishConfig": {
9998
"access": "public"
10099
}
101-
}
100+
}

src/commands/commandreference/generate.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import * as os from 'os';
99
import * as fs from 'fs';
1010
import * as path from 'path';
11-
import { Plugin } from '@oclif/core/lib/interfaces';
11+
import { Plugin, Command } from '@oclif/core/lib/interfaces';
1212
import { flags, SfdxCommand } from '@salesforce/command';
13-
import { Messages, SfdxError } from '@salesforce/core';
13+
import { Messages, SfError } from '@salesforce/core';
1414
import { AnyJson, Dictionary, ensure, getString, JsonMap } from '@salesforce/ts-types';
1515
import chalk = require('chalk');
1616
import { Ditamap } from '../../ditamap/ditamap';
@@ -54,7 +54,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
5454
const packageJson = JSON.parse(await fs.promises.readFile(pJsonPath, 'utf8'));
5555
pluginNames = [getString(packageJson, 'name')];
5656
} else {
57-
throw new SfdxError(
57+
throw new SfError(
5858
"No plugins provided. Provide the '--plugins' flag or cd into a directory that contains a valid oclif plugin."
5959
);
6060
}
@@ -72,7 +72,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
7272
pluginName = `@salesforce/plugin-${pluginName}`;
7373
plugin = this.getPlugin(pluginName);
7474
if (!plugin) {
75-
throw new SfdxError(`Plugin ${name} or ${pluginName} not found. Is it installed?`);
75+
throw new SfError(`Plugin ${name} or ${pluginName} not found. Is it installed?`);
7676
}
7777
}
7878
return pluginName;
@@ -82,18 +82,23 @@ export default class CommandReferenceGenerate extends SfdxCommand {
8282
.map((name) => `${os.EOL} - ${name}`)
8383
.join(', ')}`
8484
);
85-
Ditamap.outputDir = this.flags.outputdir;
85+
Ditamap.outputDir = this.flags.outputdir as string;
8686

8787
Ditamap.cliVersion = this.config.version.replace(/-[0-9a-zA-Z]+$/, '');
8888
Ditamap.plugins = this.pluginMap(plugins);
8989
Ditamap.pluginVersions = plugins.map((name) => {
9090
const plugin = this.getPlugin(name);
91-
const version = plugin && plugin.version;
91+
const version = plugin?.version;
9292
if (!version) throw new Error(`No version found for plugin ${name}`);
9393
return { name, version };
9494
});
9595

96-
const docs = new Docs(Ditamap.outputDir, Ditamap.plugins, this.flags.hidden, await this.loadTopicMetadata());
96+
const docs = new Docs(
97+
Ditamap.outputDir,
98+
Ditamap.plugins,
99+
this.flags.hidden as boolean,
100+
await this.loadTopicMetadata()
101+
);
97102

98103
events.on('topic', ({ topic }) => {
99104
this.log(chalk.green(`Generating topic '${topic}'`));
@@ -105,11 +110,12 @@ export default class CommandReferenceGenerate extends SfdxCommand {
105110
warnings.push(msg);
106111
});
107112

113+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
108114
await docs.build(await this.loadCommands());
109115
this.log(`\nWrote generated doc to ${Ditamap.outputDir}`);
110116

111117
if (this.flags.erroronwarnings && warnings.length > 0) {
112-
throw new SfdxError(`Found ${warnings.length} warnings.`);
118+
throw new SfError(`Found ${warnings.length} warnings.`);
113119
}
114120

115121
return { warnings };
@@ -119,7 +125,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
119125
const pluginToParentPlugin: JsonMap = {};
120126

121127
const resolveChildPlugins = (parentPlugin: Plugin) => {
122-
for (const childPlugin of parentPlugin.pjson.oclif.plugins || []) {
128+
for (const childPlugin of parentPlugin.pjson.oclif.plugins ?? []) {
123129
pluginToParentPlugin[childPlugin] = parentPlugin.name;
124130
resolveChildPlugins(ensure(this.getPlugin(childPlugin)));
125131
}
@@ -128,15 +134,15 @@ export default class CommandReferenceGenerate extends SfdxCommand {
128134
for (const plugin of plugins) {
129135
const masterPlugin = this.getPlugin(plugin);
130136
if (!masterPlugin) {
131-
throw new SfdxError(`Plugin ${plugin} not found. Is it installed?`);
137+
throw new SfError(`Plugin ${plugin} not found. Is it installed?`);
132138
}
133139
pluginToParentPlugin[masterPlugin.name] = masterPlugin.name;
134140
resolveChildPlugins(masterPlugin);
135141
}
136142
return pluginToParentPlugin;
137143
}
138144

139-
private getPlugin(pluginName: string) {
145+
private getPlugin(pluginName: string): Plugin | undefined {
140146
return this.config.plugins.find((info) => info.name === pluginName);
141147
}
142148

@@ -147,9 +153,10 @@ export default class CommandReferenceGenerate extends SfdxCommand {
147153
for (const cmd of this.config.commands) {
148154
// Only load topics for each plugin once
149155
if (cmd.pluginName && !plugins[cmd.pluginName]) {
150-
const commandClass = await this.loadCommand(cmd);
156+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, no-await-in-loop
157+
const commandClass = await loadCommand(cmd);
151158

152-
if (commandClass.plugin && commandClass.plugin.pjson.oclif.topics) {
159+
if (commandClass.plugin?.pjson.oclif.topics) {
153160
mergeDeep(topicsMeta, commandClass.plugin.pjson.oclif.topics as Dictionary);
154161
plugins[commandClass.plugin.name] = true;
155162
}
@@ -161,7 +168,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
161168
private async loadCommands() {
162169
const promises = this.config.commands.map(async (cmd) => {
163170
try {
164-
let commandClass = await this.loadCommand(cmd);
171+
let commandClass = await loadCommand(cmd);
165172
let obj = Object.assign({} as JsonMap, cmd, commandClass, {
166173
flags: Object.assign({}, cmd.flags, commandClass.flags),
167174
});
@@ -170,7 +177,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
170177
while (commandClass !== undefined) {
171178
commandClass = Object.getPrototypeOf(commandClass) || undefined;
172179
obj = Object.assign({}, commandClass, obj, {
173-
flags: Object.assign({}, commandClass && commandClass.flags, obj.flags),
180+
flags: Object.assign({}, commandClass?.flags, obj.flags),
174181
});
175182
}
176183

@@ -182,8 +189,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
182189
const commands = await Promise.all(promises);
183190
return uniqBy(commands, 'id');
184191
}
185-
186-
private async loadCommand(command) {
187-
return command.load.constructor.name === 'AsyncFunction' ? await command.load() : command.load();
188-
}
189192
}
193+
194+
const loadCommand = async (command: Command.Loadable): Promise<Command.Class> =>
195+
command.load.constructor.name === 'AsyncFunction' ? command.load() : command.load();

src/ditamap/base-ditamap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class BaseDitamap extends Ditamap {
1515
});
1616
}
1717

18+
// eslint-disable-next-line class-methods-use-this
1819
public getTemplateFileName(): string {
1920
return 'base_ditamap.hbs';
2021
}

src/ditamap/cli-reference-topic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class CLIReferenceTopic extends Ditamap {
2121
this.destination = join(Ditamap.outputDir, topic, filename);
2222
}
2323

24+
// eslint-disable-next-line class-methods-use-this
2425
public getTemplateFileName(): string {
2526
return 'cli_reference_topic.hbs';
2627
}

src/ditamap/cli-reference.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class CLIReference extends Ditamap {
1717
});
1818
}
1919

20+
// eslint-disable-next-line class-methods-use-this
2021
public getTemplateFileName(): string {
2122
return 'cli_reference_xml.hbs';
2223
}

src/ditamap/command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class Command extends Ditamap {
5252
if (Array.isArray(command.examples)) {
5353
if (
5454
help.includes('Examples:') &&
55+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
5556
command.examples.map((example, foundAll) => foundAll && help.includes(example), true)
5657
) {
5758
// Examples are already in the help, so don't duplicate.
@@ -112,6 +113,7 @@ export class Command extends Ditamap {
112113
});
113114
}
114115

116+
// eslint-disable-next-line class-methods-use-this
115117
public getTemplateFileName(): string {
116118
return 'command.hbs';
117119
}

src/ditamap/ditamap.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import * as fs from 'fs';
88
import { dirname, join } from 'path';
99
import { JsonMap } from '@salesforce/ts-types';
1010
import * as debugCreator from 'debug';
11-
import { compile, registerHelper } from 'handlebars';
11+
// import { compile, registerHelper } from 'handlebars';
12+
import * as handlebars from 'handlebars';
1213

1314
const debug = debugCreator('commandreference');
1415

@@ -31,22 +32,24 @@ export abstract class Ditamap {
3132
private source: string;
3233

3334
public constructor(private filename: string, protected data: JsonMap) {
34-
registerHelper('toUpperCase', (str) => str.toUpperCase());
35-
registerHelper('join', (array) => array.join(', '));
35+
handlebars.registerHelper('toUpperCase', (str) => str.toUpperCase());
36+
handlebars.registerHelper('join', (array) => array.join(', '));
3637

3738
/*
3839
* Returns true if the string should be formatted as code block in docs
3940
*/
4041
// tslint:disable-next-line: no-any
41-
registerHelper('isCodeBlock', function (this: any, val, options) {
42+
handlebars.registerHelper('isCodeBlock', function (this: any, val, options) {
4243
return val.indexOf('$ sfdx') >= 0 || val.indexOf('>>') >= 0 ? options.fn(this) : options.inverse(this);
4344
});
4445

4546
/*
4647
* Remove OS prompt in codeblocks, as per CCX style guidelines in our published docs
4748
*/
48-
registerHelper('removePrompt', (codeblock) => codeblock.substring((codeblock.indexOf('$') as number) + 1));
49-
registerHelper('nextVersion', (value) => parseInt(value, 2) + 1);
49+
handlebars.registerHelper('removePrompt', (codeblock) =>
50+
codeblock.substring((codeblock.indexOf('$') as number) + 1)
51+
);
52+
handlebars.registerHelper('nextVersion', (value) => parseInt(value as string, 2) + 1);
5053
this.source = join(Ditamap.templatesDir, this.getTemplateFileName());
5154
this.destination = join(Ditamap.outputDir, filename);
5255
}
@@ -66,7 +69,8 @@ export abstract class Ditamap {
6669
await fs.promises.writeFile(this.destination, output);
6770
}
6871

69-
protected formatParagraphs(textToFormat?: string) {
72+
// eslint-disable-next-line class-methods-use-this
73+
protected formatParagraphs(textToFormat?: string): string[] {
7074
return textToFormat ? textToFormat.split('\n').filter((n) => n !== '') : [];
7175
}
7276

@@ -80,7 +84,7 @@ export abstract class Ditamap {
8084
private async transformToDitamap() {
8185
debug(`Generating ${this.destination} from ${this.getTemplateFileName()}`);
8286
const src = await fs.promises.readFile(this.source, 'utf8');
83-
const template = compile(src);
87+
const template = handlebars.compile(src);
8488
return template(this.data);
8589
}
8690

src/ditamap/main-topic-intro.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class MainTopicIntro extends Ditamap {
4141
this.destination = join(Ditamap.outputDir, topic, subtopic, filename);
4242
}
4343

44+
// eslint-disable-next-line class-methods-use-this
4445
public getTemplateFileName(): string {
4546
return 'main_topic_intro.hbs';
4647
}

0 commit comments

Comments
 (0)