Skip to content

Commit

Permalink
fix: new TS requires handlebars import change
Browse files Browse the repository at this point in the history
* 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 <shane.mclaughlin@salesforce.com>
  • Loading branch information
SF-CLI-BOT and mshanemc authored Oct 7, 2022
1 parent 0b12641 commit ec4efd5
Show file tree
Hide file tree
Showing 16 changed files with 539 additions and 509 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/notify-slack-on-pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Notify Slack on PR open
env:
WEBHOOK_URL : ${{ secrets.CLI_TEAM_SLACK_WEBHOOK_URL }}
PULL_REQUEST_AUTHOR_ICON_URL : ${{ github.event.pull_request.user.avatar_url }}
PULL_REQUEST_AUTHOR_NAME : ${{ github.event.pull_request.user.login }}
PULL_REQUEST_AUTHOR_PROFILE_URL: ${{ github.event.pull_request.user.html_url }}
PULL_REQUEST_BASE_BRANCH_NAME : ${{ github.event.pull_request.base.ref }}
PULL_REQUEST_COMPARE_BRANCH_NAME : ${{ github.event.pull_request.head.ref }}
PULL_REQUEST_NUMBER : ${{ github.event.pull_request.number }}
PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.name }}
PULL_REQUEST_TITLE : ${{ github.event.pull_request.title }}
PULL_REQUEST_URL : ${{ github.event.pull_request.html_url }}
uses: salesforcecli/github-workflows/.github/actions/prNotification@main
- name: Notify Slack on PR open
env:
WEBHOOK_URL: ${{ secrets.CLI_TEAM_SLACK_WEBHOOK_URL }}
PULL_REQUEST_AUTHOR_ICON_URL: ${{ github.event.pull_request.user.avatar_url }}
PULL_REQUEST_AUTHOR_NAME: ${{ github.event.pull_request.user.login }}
PULL_REQUEST_AUTHOR_PROFILE_URL: ${{ github.event.pull_request.user.html_url }}
PULL_REQUEST_BASE_BRANCH_NAME: ${{ github.event.pull_request.base.ref }}
PULL_REQUEST_COMPARE_BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.name }}
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
PULL_REQUEST_URL: ${{ github.event.pull_request.html_url }}
uses: salesforcecli/github-workflows/.github/actions/prNotification@main
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ on:

jobs:
unit-tests:
uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
cache: yarn
- run: yarn install --network-timeout 600000
- run: yarn build
- run: yarn test
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,35 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/plugin-command-reference/issues",
"dependencies": {
"@salesforce/command": "^5.2.6",
"@salesforce/core": "^3.25.0",
"@salesforce/command": "^5.2.11",
"@salesforce/core": "^3.30.10",
"@types/lodash.uniqby": "^4.7.7",
"chalk": "^3.0.0",
"handlebars": "4.7.7",
"lodash.uniqby": "^4.7.0",
"shelljs": "^0.8.5",
"tslib": "^1"
"tslib": "^2"
},
"devDependencies": {
"@salesforce/dev-config": "^3.1.0",
"@salesforce/dev-scripts": "^2.0.4",
"@salesforce/dev-scripts": "^3.1.0",
"@salesforce/plugin-alias": "^2.1.0",
"@salesforce/plugin-signups": "^1.2.0",
"@salesforce/prettier-config": "^0.0.2",
"@semantic-release/changelog": "^5.0.0",
"@semantic-release/git": "^9.0.1",
"@types/shelljs": "^0.8.11",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"chai": "^4.3.6",
"eslint": "^7.27.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-salesforce": "^0.1.6",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-salesforce": "^1.1.0",
"eslint-config-salesforce-license": "^0.1.6",
"eslint-config-salesforce-typescript": "^0.2.7",
"eslint-config-salesforce-typescript": "^1.1.1",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-jsdoc": "^39.3.6",
"husky": "^7.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
Expand All @@ -45,7 +44,7 @@
"semantic-release": "^17.4.7",
"sinon": "10.0.0",
"ts-node": "^10.9.1",
"typescript": "4.3"
"typescript": "^4.8.4"
},
"engines": {
"node": ">=14.0.0"
Expand Down Expand Up @@ -98,4 +97,4 @@
"publishConfig": {
"access": "public"
}
}
}
44 changes: 25 additions & 19 deletions src/commands/commandreference/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import * as os from 'os';
import * as fs from 'fs';
import * as path from 'path';
import { Plugin } from '@oclif/core/lib/interfaces';
import { Plugin, Command } from '@oclif/core/lib/interfaces';
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';
import { Messages, SfError } from '@salesforce/core';
import { AnyJson, Dictionary, ensure, getString, JsonMap } from '@salesforce/ts-types';
import chalk = require('chalk');
import { Ditamap } from '../../ditamap/ditamap';
Expand Down Expand Up @@ -54,7 +54,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
const packageJson = JSON.parse(await fs.promises.readFile(pJsonPath, 'utf8'));
pluginNames = [getString(packageJson, 'name')];
} else {
throw new SfdxError(
throw new SfError(
"No plugins provided. Provide the '--plugins' flag or cd into a directory that contains a valid oclif plugin."
);
}
Expand All @@ -72,7 +72,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
pluginName = `@salesforce/plugin-${pluginName}`;
plugin = this.getPlugin(pluginName);
if (!plugin) {
throw new SfdxError(`Plugin ${name} or ${pluginName} not found. Is it installed?`);
throw new SfError(`Plugin ${name} or ${pluginName} not found. Is it installed?`);
}
}
return pluginName;
Expand All @@ -82,18 +82,23 @@ export default class CommandReferenceGenerate extends SfdxCommand {
.map((name) => `${os.EOL} - ${name}`)
.join(', ')}`
);
Ditamap.outputDir = this.flags.outputdir;
Ditamap.outputDir = this.flags.outputdir as string;

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

const docs = new Docs(Ditamap.outputDir, Ditamap.plugins, this.flags.hidden, await this.loadTopicMetadata());
const docs = new Docs(
Ditamap.outputDir,
Ditamap.plugins,
this.flags.hidden as boolean,
await this.loadTopicMetadata()
);

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

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

if (this.flags.erroronwarnings && warnings.length > 0) {
throw new SfdxError(`Found ${warnings.length} warnings.`);
throw new SfError(`Found ${warnings.length} warnings.`);
}

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

const resolveChildPlugins = (parentPlugin: Plugin) => {
for (const childPlugin of parentPlugin.pjson.oclif.plugins || []) {
for (const childPlugin of parentPlugin.pjson.oclif.plugins ?? []) {
pluginToParentPlugin[childPlugin] = parentPlugin.name;
resolveChildPlugins(ensure(this.getPlugin(childPlugin)));
}
Expand All @@ -128,15 +134,15 @@ export default class CommandReferenceGenerate extends SfdxCommand {
for (const plugin of plugins) {
const masterPlugin = this.getPlugin(plugin);
if (!masterPlugin) {
throw new SfdxError(`Plugin ${plugin} not found. Is it installed?`);
throw new SfError(`Plugin ${plugin} not found. Is it installed?`);
}
pluginToParentPlugin[masterPlugin.name] = masterPlugin.name;
resolveChildPlugins(masterPlugin);
}
return pluginToParentPlugin;
}

private getPlugin(pluginName: string) {
private getPlugin(pluginName: string): Plugin | undefined {
return this.config.plugins.find((info) => info.name === pluginName);
}

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

if (commandClass.plugin && commandClass.plugin.pjson.oclif.topics) {
if (commandClass.plugin?.pjson.oclif.topics) {
mergeDeep(topicsMeta, commandClass.plugin.pjson.oclif.topics as Dictionary);
plugins[commandClass.plugin.name] = true;
}
Expand All @@ -161,7 +168,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
private async loadCommands() {
const promises = this.config.commands.map(async (cmd) => {
try {
let commandClass = await this.loadCommand(cmd);
let commandClass = await loadCommand(cmd);
let obj = Object.assign({} as JsonMap, cmd, commandClass, {
flags: Object.assign({}, cmd.flags, commandClass.flags),
});
Expand All @@ -170,7 +177,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
while (commandClass !== undefined) {
commandClass = Object.getPrototypeOf(commandClass) || undefined;
obj = Object.assign({}, commandClass, obj, {
flags: Object.assign({}, commandClass && commandClass.flags, obj.flags),
flags: Object.assign({}, commandClass?.flags, obj.flags),
});
}

Expand All @@ -182,8 +189,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
const commands = await Promise.all(promises);
return uniqBy(commands, 'id');
}

private async loadCommand(command) {
return command.load.constructor.name === 'AsyncFunction' ? await command.load() : command.load();
}
}

const loadCommand = async (command: Command.Loadable): Promise<Command.Class> =>
command.load.constructor.name === 'AsyncFunction' ? command.load() : command.load();
1 change: 1 addition & 0 deletions src/ditamap/base-ditamap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class BaseDitamap extends Ditamap {
});
}

// eslint-disable-next-line class-methods-use-this
public getTemplateFileName(): string {
return 'base_ditamap.hbs';
}
Expand Down
1 change: 1 addition & 0 deletions src/ditamap/cli-reference-topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class CLIReferenceTopic extends Ditamap {
this.destination = join(Ditamap.outputDir, topic, filename);
}

// eslint-disable-next-line class-methods-use-this
public getTemplateFileName(): string {
return 'cli_reference_topic.hbs';
}
Expand Down
1 change: 1 addition & 0 deletions src/ditamap/cli-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class CLIReference extends Ditamap {
});
}

// eslint-disable-next-line class-methods-use-this
public getTemplateFileName(): string {
return 'cli_reference_xml.hbs';
}
Expand Down
2 changes: 2 additions & 0 deletions src/ditamap/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class Command extends Ditamap {
if (Array.isArray(command.examples)) {
if (
help.includes('Examples:') &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
command.examples.map((example, foundAll) => foundAll && help.includes(example), true)
) {
// Examples are already in the help, so don't duplicate.
Expand Down Expand Up @@ -112,6 +113,7 @@ export class Command extends Ditamap {
});
}

// eslint-disable-next-line class-methods-use-this
public getTemplateFileName(): string {
return 'command.hbs';
}
Expand Down
20 changes: 12 additions & 8 deletions src/ditamap/ditamap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import * as fs from 'fs';
import { dirname, join } from 'path';
import { JsonMap } from '@salesforce/ts-types';
import * as debugCreator from 'debug';
import { compile, registerHelper } from 'handlebars';
// import { compile, registerHelper } from 'handlebars';
import * as handlebars from 'handlebars';

const debug = debugCreator('commandreference');

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

public constructor(private filename: string, protected data: JsonMap) {
registerHelper('toUpperCase', (str) => str.toUpperCase());
registerHelper('join', (array) => array.join(', '));
handlebars.registerHelper('toUpperCase', (str) => str.toUpperCase());
handlebars.registerHelper('join', (array) => array.join(', '));

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

/*
* Remove OS prompt in codeblocks, as per CCX style guidelines in our published docs
*/
registerHelper('removePrompt', (codeblock) => codeblock.substring((codeblock.indexOf('$') as number) + 1));
registerHelper('nextVersion', (value) => parseInt(value, 2) + 1);
handlebars.registerHelper('removePrompt', (codeblock) =>
codeblock.substring((codeblock.indexOf('$') as number) + 1)
);
handlebars.registerHelper('nextVersion', (value) => parseInt(value as string, 2) + 1);
this.source = join(Ditamap.templatesDir, this.getTemplateFileName());
this.destination = join(Ditamap.outputDir, filename);
}
Expand All @@ -66,7 +69,8 @@ export abstract class Ditamap {
await fs.promises.writeFile(this.destination, output);
}

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

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

Expand Down
1 change: 1 addition & 0 deletions src/ditamap/main-topic-intro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class MainTopicIntro extends Ditamap {
this.destination = join(Ditamap.outputDir, topic, subtopic, filename);
}

// eslint-disable-next-line class-methods-use-this
public getTemplateFileName(): string {
return 'main_topic_intro.hbs';
}
Expand Down
1 change: 1 addition & 0 deletions src/ditamap/subtopic-ditamap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class SubTopicDitamap extends Ditamap {
this.destination = join(Ditamap.outputDir, topic, subtopic, filename);
}

// eslint-disable-next-line class-methods-use-this
public getTemplateFileName(): string {
return 'subtopic_ditamap.hbs';
}
Expand Down
1 change: 1 addition & 0 deletions src/ditamap/topic-ditamap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class TopicDitamap extends Ditamap {
this.destination = join(Ditamap.outputDir, topic, filename);
}

// eslint-disable-next-line class-methods-use-this
public getTemplateFileName(): string {
return 'topic_ditamap.hbs';
}
Expand Down
Loading

0 comments on commit ec4efd5

Please sign in to comment.