From ebb747784b9307efe8f79b963e9cdad79986388e Mon Sep 17 00:00:00 2001 From: Nico De Cleyre Date: Sun, 13 Oct 2024 20:14:55 +0200 Subject: [PATCH] First commit --- package.json | 22 ++++++++ src/services/actions/CliActions.ts | 86 +++++++++++++++++++----------- 2 files changed, 77 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 55596ab..a59ecbd 100644 --- a/package.json +++ b/package.json @@ -186,6 +186,28 @@ "type": "boolean", "default": "true", "description": "Show the tenant-wide extensions in the account view." + }, + "spfx-toolkit.projectUpgradeOutputMode": { + "title": "Project upgrade output mode", + "type": "string", + "default": "both", + "enum": [ + "markdown", + "code tour", + "both" + ], + "description": "Choose the output mode for the project upgrade. Choose between `markdown`, `code tour`, or `both`." + }, + "spfx-toolkit.projectValidateOutputMode": { + "title": "Project validate output mode", + "type": "string", + "default": "both", + "enum": [ + "markdown", + "code tour", + "both" + ], + "description": "Choose the output mode for the project validation. Choose between `markdown`, `code tour`, or `both`." } } }, diff --git a/src/services/actions/CliActions.ts b/src/services/actions/CliActions.ts index 89b0d15..2da3522 100644 --- a/src/services/actions/CliActions.ts +++ b/src/services/actions/CliActions.ts @@ -1,6 +1,6 @@ import { readFileSync, writeFileSync } from 'fs'; import { Folders } from '../check/Folders'; -import { commands, Progress, ProgressLocation, Uri, window, workspace } from 'vscode'; +import { commands, Progress, ProgressLocation, Uri, window, workspace, WorkspaceFolder } from 'vscode'; import { Commands, WebViewType, WebviewCommand, WorkflowType } from '../../constants'; import { GenerateWorkflowCommandInput, SiteAppCatalog, SolutionAddResult, Subscription } from '../../models'; import { Extension } from '../dataType/Extension'; @@ -15,6 +15,8 @@ import { PnPWebview } from '../../webview/PnPWebview'; import { parseYoRc } from '../../utils/parseYoRc'; import { CertificateActions } from './CertificateActions'; import path = require('path'); +import * as fs from 'fs'; +import { getExtensionSettings } from '../../utils/getExtensionSettings'; export class CliActions { @@ -273,21 +275,21 @@ export class CliActions { cancellable: true }, async (progress: Progress<{ message?: string; increment?: number }>) => { try { - const result = await CliExecuter.execute('spfx project upgrade', 'md'); - - if (result.stdout) { - // Create a file to allow the Markdown preview to correctly open the linked/referenced files - let savePath = wsFolder?.uri.fsPath; - - if (savePath && TeamsToolkitIntegration.isTeamsToolkitProject) { - savePath = join(savePath, 'src'); - } - - const filePath = join(savePath || '', 'spfx.upgrade.md'); - writeFileSync(filePath, result.stdout); - await commands.executeCommand('markdown.showPreview', Uri.file(filePath)); - } else if (result.stderr) { - Notifications.error(result.stderr); + const projectUpgradeOutputMode: string = getExtensionSettings('projectUpgradeOutputMode', 'both'); + let resultMd: any; + + if (projectUpgradeOutputMode === 'markdown') { + resultMd = await CliExecuter.execute('spfx project upgrade', 'md'); + CliActions.handleMarkdownResult(resultMd,wsFolder); + } else if (projectUpgradeOutputMode === 'code tour') { + await CliExecuter.execute('spfx project upgrade', 'tour'); + commands.executeCommand('codetour.startTour'); + } else { + resultMd = await CliExecuter.execute('spfx project upgrade', 'md'); + await CliExecuter.execute('spfx project upgrade', 'tour'); + + CliActions.handleMarkdownResult(resultMd, wsFolder); + commands.executeCommand('codetour.startTour'); } } catch (e: any) { const message = e?.error?.message; @@ -452,21 +454,22 @@ export class CliActions { cancellable: true }, async (progress: Progress<{ message?: string; increment?: number }>) => { try { - const result = await CliExecuter.execute('spfx project doctor', 'md'); - - if (result.stdout) { - // Create a file to allow the Markdown preview to correctly open the linked/referenced files - let savePath = wsFolder?.uri.fsPath; - - if (savePath && TeamsToolkitIntegration.isTeamsToolkitProject) { - savePath = join(savePath, 'src'); - } - - const filePath = join(savePath || '', 'spfx.validate.md'); - writeFileSync(filePath, result.stdout); - await commands.executeCommand('markdown.showPreview', Uri.file(filePath)); - } else if (result.stderr) { - Notifications.error(result.stderr); + const projectValidateOutputMode: string = getExtensionSettings('projectValidateOutputMode', 'both'); + let resultMd: any; + + if (projectValidateOutputMode === 'markdown') { + resultMd = await CliExecuter.execute('spfx project doctor', 'md'); + CliActions.handleMarkdownResult(resultMd,wsFolder); + } else if (projectValidateOutputMode === 'code tour') { + await CliExecuter.execute('spfx project doctor', 'tour'); + commands.executeCommand('codetour.startTour'); + } else { + resultMd = await CliExecuter.execute('spfx project doctor', 'md'); + await CliExecuter.execute('spfx project doctor', 'tour'); + + // Handle both results + CliActions.handleMarkdownResult(resultMd, wsFolder); + commands.executeCommand('codetour.startTour'); } } catch (e: any) { const message = e?.error?.message; @@ -582,4 +585,25 @@ export class CliActions { } }); } + + /** + * Handles the Markdown result + * @param result The result of the (CLI) command execution + * @param wsFolder The workspace folder + */ + private static handleMarkdownResult(result: any, wsFolder: WorkspaceFolder | undefined) { + if (result?.stdout) { + let savePath = wsFolder?.uri.fsPath; + + if (savePath && TeamsToolkitIntegration.isTeamsToolkitProject) { + savePath = join(savePath, 'src'); + } + + const filePath = join(savePath || '', 'spfx.upgrade.md'); + writeFileSync(filePath, result.stdout); + commands.executeCommand('markdown.showPreview', Uri.file(filePath)); + } else if (result?.stderr) { + Notifications.error(result.stderr); + } + } } \ No newline at end of file