Skip to content

Commit

Permalink
fix: load commands while linked
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 13, 2022
1 parent 87f18ec commit be6aae9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/commands/dev/generate/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { Messages } from '@salesforce/core';
import { Nullable } from '@salesforce/ts-types';
import { Duration } from '@salesforce/kit';

import { Config, toConfiguredId, toStandardizedId } from '@oclif/core';
import ModuleLoader from '@oclif/core/lib/module-loader';
import { Config, Interfaces, toConfiguredId, toStandardizedId } from '@oclif/core';
import * as fg from 'fast-glob';
import { fileExists } from '../../../util';

Expand Down Expand Up @@ -80,9 +79,8 @@ export default class DevGenerateFlag extends SfCommand<void> {
]);

const standardizedCommandId = toStandardizedId(command, this.config);
const commandFilePath = path.join('.', 'src', 'commands', ...standardizedCommandId.split(':'));

const answers = await this.askQuestions(commandFilePath);
const answers = await this.askQuestions(standardizedCommandId);

const newFlag = this.constructFlag(answers);

Expand All @@ -92,6 +90,7 @@ export default class DevGenerateFlag extends SfCommand<void> {
return;
}

const commandFilePath = path.join('.', 'src', 'commands', ...standardizedCommandId.split(':'));
const lines = (await fs.readFile(`${commandFilePath}.ts`, 'utf8')).split('\n');
const flagsStartIndex = lines.findIndex(
(line) => line.includes('public static flags') || line.includes('public static readonly flags')
Expand Down Expand Up @@ -292,18 +291,12 @@ export default class DevGenerateFlag extends SfCommand<void> {
]);
}

private async loadExistingFlags(
commandFilePath: string
): Promise<Record<string, { type: 'boolean' | 'option'; char?: string }>> {
private async loadExistingFlags(commandId: string): Promise<Record<string, Interfaces.Command.Flag>> {
const config = new Config({ root: process.cwd() });
config.root = config.options.root;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const module = await ModuleLoader.load(config, commandFilePath);

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const existingFlags = module.default.flags as Record<string, { type: 'boolean' | 'option'; char?: string }>;

return existingFlags;
await config.load();
const cmd = config.commands.find((c) => c.id === commandId);
return cmd.flags ?? {};
}

private async findExistingCommands(): Promise<string[]> {
Expand Down
2 changes: 2 additions & 0 deletions src/generators/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import got from 'got';
import { pascalCase } from 'change-case';
import { set } from '@salesforce/kit';
import { get } from '@salesforce/ts-types';
import { exec } from 'shelljs';
import { PackageJson, Topic } from '../types';

// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
Expand Down Expand Up @@ -89,6 +90,7 @@ export default class Command extends Generator {
this.writeMessageFile();
this.writeNutFile();
this.writeUnitTestFile();
exec('yarn compile');
}

private getMessageFileName(): string {
Expand Down

0 comments on commit be6aae9

Please sign in to comment.