-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tour response for Upgrade and Validate actions, Closes #188 #323
Draft
nicodecleyre
wants to merge
1
commit into
pnp:dev
Choose a base branch
from
nicodecleyre:Tour-response-for-Upgrade-and-Validate-#188
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
β30
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -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, ContextKeys, WebViewType, WebviewCommand, WorkflowType } from '../../constants'; | ||
import { AppCatalogApp, GenerateWorkflowCommandInput, SiteAppCatalog, SolutionAddResult, Subscription } from '../../models'; | ||
import { Extension } from '../dataType/Extension'; | ||
|
@@ -16,7 +16,8 @@ import { parseYoRc } from '../../utils/parseYoRc'; | |
import { CertificateActions } from './CertificateActions'; | ||
import path = require('path'); | ||
import { ActionTreeItem } from '../../providers/ActionTreeDataProvider'; | ||
|
||
import { getExtensionSettings } from '../../utils/getExtensionSettings'; | ||
import * as fs from 'fs'; | ||
|
||
export class CliActions { | ||
|
||
|
@@ -479,21 +480,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 projectUpgradeOutputMode: string = getExtensionSettings('projectUpgradeOutputMode', 'both'); | ||
let resultMd: any; | ||
|
||
if (projectUpgradeOutputMode === 'markdown') { | ||
resultMd = await CliExecuter.execute('spfx project upgrade', 'md'); | ||
CliActions.handleMarkdownResult(resultMd, wsFolder, 'upgrade'); | ||
} else if (projectUpgradeOutputMode === 'code tour') { | ||
await CliExecuter.execute('spfx project upgrade', 'tour'); | ||
CliActions.handleTourResult(wsFolder, 'upgrade'); | ||
} else { | ||
resultMd = await CliExecuter.execute('spfx project upgrade', 'md'); | ||
await CliExecuter.execute('spfx project upgrade', 'tour'); | ||
|
||
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); | ||
CliActions.handleMarkdownResult(resultMd, wsFolder, 'upgrade'); | ||
CliActions.handleTourResult(wsFolder, 'upgrade'); | ||
} | ||
} catch (e: any) { | ||
const message = e?.error?.message; | ||
|
@@ -658,21 +659,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 projectValidateOutputMode: string = getExtensionSettings('projectValidateOutputMode', 'both'); | ||
let resultMd: any; | ||
|
||
if (projectValidateOutputMode === 'markdown') { | ||
resultMd = await CliExecuter.execute('spfx project doctor', 'md'); | ||
CliActions.handleMarkdownResult(resultMd, wsFolder, 'validate'); | ||
} else if (projectValidateOutputMode === 'code tour') { | ||
await CliExecuter.execute('spfx project doctor', 'tour'); | ||
CliActions.handleTourResult(wsFolder, 'validation'); | ||
} else { | ||
resultMd = await CliExecuter.execute('spfx project doctor', 'md'); | ||
await CliExecuter.execute('spfx project doctor', 'tour'); | ||
|
||
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); | ||
// Handle both results | ||
CliActions.handleMarkdownResult(resultMd, wsFolder, 'validate'); | ||
CliActions.handleTourResult(wsFolder, 'validation'); | ||
} | ||
} catch (e: any) { | ||
const message = e?.error?.message; | ||
|
@@ -788,4 +790,43 @@ 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, fileName: string) { | ||
if (result?.stdout) { | ||
let savePath = wsFolder?.uri.fsPath; | ||
|
||
if (savePath && TeamsToolkitIntegration.isTeamsToolkitProject) { | ||
savePath = join(savePath, 'src'); | ||
} | ||
|
||
const filePath = join(savePath || '', `spfx.${fileName}.md`); | ||
writeFileSync(filePath, result.stdout); | ||
commands.executeCommand('markdown.showPreview', Uri.file(filePath)); | ||
} else if (result?.stderr) { | ||
Notifications.error(result.stderr); | ||
} | ||
} | ||
|
||
/** | ||
* Handles the Tour result | ||
* @param wsFolder The workspace folder | ||
*/ | ||
private static async handleTourResult(wsFolder: WorkspaceFolder | undefined, fileName: string): Promise<void> { | ||
if (!wsFolder) { | ||
Notifications.error('Workspace folder is undefined. Cannot start Code Tour.'); | ||
return; | ||
} | ||
|
||
const tourFilePath = path.join(wsFolder.uri.fsPath, '.tours', `${fileName}.tour`); | ||
|
||
if (fs.existsSync(tourFilePath)) { | ||
await commands.executeCommand('codetour.startTour'); | ||
} else { | ||
Notifications.error('Validation tour file not found. Cannot start Code Tour.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the error may be misleading as it may not always be the validation tour but also it may be the upgrade tour |
||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if we could just have
if
blocks in which we check for either the specific type/method, likemarkdown
ortour
and check forboth
. In this case we don't need to check explicitly forboth
and we will avoid code repetition. What do you think? I guess it should work