generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,654 additions
and
2,500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# updateCliVersion | ||
|
||
Update your CLI version from: %s to the latest version: %s | ||
|
||
# latestCliVersionError | ||
|
||
Could not determine latest CLI version due to: | ||
%s | ||
|
||
# salesforceDxPluginDetected | ||
|
||
The salesforcedx plugin is deprecated. Please uninstall by running: `%s plugins:uninstall salesforcedx` | ||
|
||
# linkedPluginWarning | ||
|
||
Warning: the [%s] plugin is linked. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ import * as os from 'os'; | |
import { exec } from 'child_process'; | ||
import { flags, SfdxCommand } from '@salesforce/command'; | ||
import { Messages, Lifecycle } from '@salesforce/core'; | ||
import { Doctor as SFDoctor, SfDoctorDiagnosis } from '../doctor'; | ||
import { Doctor as SFDoctor, SfDoctor, SfDoctorDiagnosis } from '../doctor'; | ||
import { DiagnosticStatus } from '../diagnostics'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-info', 'doctor'); | ||
|
@@ -37,39 +38,35 @@ export default class Doctor extends SfdxCommand { | |
}), | ||
}; | ||
|
||
// Array of promises that are various doctor tasks to perform | ||
// such as running a command and running diagnostics. | ||
private tasks: Array<Promise<void>> = []; | ||
|
||
private doctor: SfDoctor; | ||
|
||
private filesWrittenMsgs: string[] = []; | ||
|
||
public async run(): Promise<SfDoctorDiagnosis> { | ||
let promises: Array<Promise<void>> = []; | ||
const doctor = SFDoctor.getInstance(); | ||
SFDoctor.init(this.config, { | ||
cliVersion: 'sfdx-cli/7.165.1', | ||
pluginVersions: ['foo', 'bar (link)', 'salesforcedx'], | ||
nodeVersion: 'node-v16.17.0', | ||
architecture: 'darwin-x64' | ||
}); | ||
this.doctor = SFDoctor.getInstance(); | ||
const lifecycle = Lifecycle.getInstance(); | ||
|
||
const plugin = this.flags.plugin as string; | ||
const command = this.flags.command as string; | ||
const newissue = this.flags.newissue as boolean; | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
lifecycle.on<DiagnosticStatus>('Doctor:diagnostic', async (data) => { | ||
this.ux.log(`${data.status} - ${data.testName}`); | ||
}); | ||
|
||
if (command) { | ||
const cmdString = this.parseCommand(command); | ||
this.ux.log(`Running Command: ${cmdString}\n`); | ||
const cmdName = cmdString.split(' ')[1]; | ||
doctor.addCommandName(cmdName); | ||
|
||
const execPromise = new Promise<void>((resolve) => { | ||
const execOptions = { | ||
env: Object.assign({}, process.env), | ||
}; | ||
|
||
exec(cmdString, execOptions, (error, stdout, stderr) => { | ||
const code = error?.code || 0; | ||
const stdoutWithCode = `Command exit code: ${code}\n\n${stdout}`; | ||
const stdoutFileName = `${cmdName}-stdout.log`; | ||
const stderrFileName = `${cmdName}-stderr.log`; | ||
const stdoutLogLocation = doctor.writeFileSync(stdoutFileName, stdoutWithCode); | ||
const debugLogLocation = doctor.writeFileSync(stderrFileName, stderr); | ||
this.ux.log(`Wrote command stdout log to: ${stdoutLogLocation}`); | ||
this.ux.log(`Wrote command debug log to: ${debugLogLocation}`); | ||
resolve(); | ||
}); | ||
}); | ||
promises.push(execPromise); | ||
this.setupCommandExecution(command); | ||
} | ||
|
||
if (plugin) { | ||
|
@@ -80,44 +77,34 @@ export default class Doctor extends SfdxCommand { | |
} | ||
|
||
// run the diagnostics for a specific plugin | ||
this.ux.log(`Running diagnostics for plugin: ${plugin}`); | ||
promises.push(lifecycle.emit(`sf-doctor-${plugin}`, doctor)); | ||
this.ux.styledHeader(`Running diagnostics for plugin: ${plugin}`); | ||
this.tasks.push(lifecycle.emit(`sf-doctor-${plugin}`, this.doctor)); | ||
} else { | ||
this.ux.log('Running diagnostics for all plugins and the core CLI'); | ||
this.ux.styledHeader('Running all diagnostics'); | ||
// run all diagnostics | ||
promises.push(lifecycle.emit('sf-doctor', doctor)); | ||
this.tasks.push(lifecycle.emit('sf-doctor', this.doctor)); | ||
|
||
/* eslint-disable @typescript-eslint/ban-ts-comment,@typescript-eslint/no-unsafe-assignment */ | ||
// @ts-ignore Seems like a TypeScript bug. Compiler thinks doctor.diagnose() returns `void`. | ||
promises = [...promises, ...doctor.diagnose()]; | ||
this.tasks = [...this.tasks, ...this.doctor.diagnose()]; | ||
/* eslint-enable @typescript-eslint/ban-ts-comment,@typescript-eslint/no-unsafe-assignment */ | ||
} | ||
|
||
await Promise.all(promises); | ||
await Promise.all(this.tasks); | ||
|
||
const diagnosis = this.doctor.getDiagnosis(); | ||
const diagnosisLocation = this.doctor.writeFileSync('diagnosis.json', JSON.stringify(diagnosis, null, 2)); | ||
this.filesWrittenMsgs.push(`Wrote doctor diagnosis to: ${diagnosisLocation}`); | ||
|
||
const diagnosis = doctor.getDiagnosis(); | ||
const diagnosisLocation = doctor.writeFileSync('diagnosis.json', JSON.stringify(diagnosis, null, 2)); | ||
this.ux.log(`Wrote doctor diagnosis to: ${diagnosisLocation}`); | ||
this.ux.log(); | ||
this.filesWrittenMsgs.forEach((msg) => this.ux.log(msg)); | ||
|
||
this.ux.log(); | ||
this.ux.styledHeader('Suggestions'); | ||
diagnosis.suggestions.forEach(s => this.ux.log(` * ${s}`)); | ||
|
||
if (newissue) { | ||
// create a new issue via prompts (Inquirer) | ||
|
||
// See https://docs.github.com/en/[email protected]/issues/tracking-your-work-with-issues/creating-an-issue#creating-an-issue-from-a-url-query | ||
// Example: https://github.com/forcedotcom/cli/issues/new?title=PLEASE+UPDATE&body=Autofill+info+collected+by+doctor...&labels=doctor | ||
|
||
this.ux.warn('New GitHub issue creation is not yet implemented. Coming soon!'); | ||
// this.ux.log('\nCreating a new GitHub issue for the CLI...\n'); | ||
// const isItNew = await this.ux.prompt( | ||
// 'Have you first checked the list of GitHub issues to ensure it has not already been posted? (y/n)' | ||
// ); | ||
|
||
// if (isItNew.toLowerCase() === 'y') { | ||
// const title = await this.ux.prompt('What is the subject of the issue?'); | ||
// this.ux.log('Encoded title=', encodeURI(title)); | ||
// this.ux.log("I'll create an issue for you with that title and attach the doctor diagnostics."); | ||
// } else { | ||
// this.ux.log('Please check https://github.com/forcedotcom/cli/issues first'); | ||
// } | ||
this.createNewIssue(); | ||
} | ||
|
||
return diagnosis; | ||
|
@@ -139,4 +126,54 @@ export default class Doctor extends SfdxCommand { | |
|
||
return fullCmd; | ||
} | ||
|
||
// Adds a promise to execute the provided command and all | ||
// parameters in debug mode, writing stdout and stderr to files | ||
// in the doctor directory. | ||
private setupCommandExecution(command: string): void { | ||
const cmdString = this.parseCommand(command); | ||
this.ux.log(`Running Command: "${cmdString}"\n`); | ||
const cmdName = cmdString.split(' ')[1]; | ||
this.doctor.addCommandName(cmdName); | ||
|
||
const execPromise = new Promise<void>((resolve) => { | ||
const execOptions = { | ||
env: Object.assign({}, process.env), | ||
}; | ||
|
||
exec(cmdString, execOptions, (error, stdout, stderr) => { | ||
const code = error?.code || 0; | ||
const stdoutWithCode = `Command exit code: ${code}\n\n${stdout}`; | ||
const stdoutFileName = `${cmdName}-stdout.log`; | ||
const stderrFileName = `${cmdName}-stderr.log`; | ||
const stdoutLogLocation = this.doctor.writeFileSync(stdoutFileName, stdoutWithCode); | ||
const debugLogLocation = this.doctor.writeFileSync(stderrFileName, stderr); | ||
this.filesWrittenMsgs.push(`Wrote command stdout log to: ${stdoutLogLocation}`); | ||
this.filesWrittenMsgs.push(`Wrote command debug log to: ${debugLogLocation}`); | ||
resolve(); | ||
}); | ||
}); | ||
this.tasks.push(execPromise); | ||
} | ||
|
||
private createNewIssue(): void { | ||
// create a new issue via prompts (Inquirer) | ||
|
||
// See https://docs.github.com/en/[email protected]/issues/tracking-your-work-with-issues/creating-an-issue#creating-an-issue-from-a-url-query | ||
// Example: https://github.com/forcedotcom/cli/issues/new?title=PLEASE+UPDATE&body=Autofill+info+collected+by+doctor...&labels=doctor | ||
|
||
this.ux.warn('New GitHub issue creation is not yet implemented. Coming soon!'); | ||
// this.ux.log('\nCreating a new GitHub issue for the CLI...\n'); | ||
// const isItNew = await this.ux.prompt( | ||
// 'Have you first checked the list of GitHub issues to ensure it has not already been posted? (y/n)' | ||
// ); | ||
|
||
// if (isItNew.toLowerCase() === 'y') { | ||
// const title = await this.ux.prompt('What is the subject of the issue?'); | ||
// this.ux.log('Encoded title=', encodeURI(title)); | ||
// this.ux.log("I'll create an issue for you with that title and attach the doctor diagnostics."); | ||
// } else { | ||
// this.ux.log('Please check https://github.com/forcedotcom/cli/issues first'); | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.