Skip to content

Commit 60927b0

Browse files
Merge pull request #91 from CommunityToolkit/fix/codespace-sample-launching
Codespaces: Fix launching all-sample app, add auto sample discovery
2 parents 5d3a476 + 2fefab6 commit 60927b0

File tree

6 files changed

+139
-65
lines changed

6 files changed

+139
-65
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"extensions": [
1919
"ms-dotnettools.csharp",
2020
"unoplatform.vscode",
21-
"ms-vsliveshare.vsliveshare"
21+
"ms-vsliveshare.vsliveshare",
22+
"ms-vscode.powershell"
2223
],
2324
// Use 'forwardPorts' to make a list of ports inside the container available locally.
2425
"forwardPorts": [

.vscode/launch.json

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
2-
// Use IntelliSense to find out which attributes exist for C# debugging
3-
// Use hover for the description of the existing attributes
4-
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
52
"version": "0.2.0",
63
"configurations": [
74
{
8-
"name": "All samples",
5+
"name": "All samples app",
96
"type": "coreclr",
107
"request": "launch",
118
"program": "dotnet",
@@ -19,28 +16,24 @@
1916
"/p:UnoRemoteControlPort=443",
2017
"--project=${workspaceFolder}/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj",
2118
"-p:TargetFrameworks=netstandard2.0",
22-
"-p:TargetFramework=net5.0",
19+
"-p:TargetFramework=net5.0"
2320
],
21+
"presentation": {
22+
"group": "1",
23+
"order": 1
24+
},
2425
"cwd": "${workspaceFolder}/platforms/CommunityToolkit.Labs.Wasm",
26+
"preLaunchTask": "generateAllSolution"
2527
},
2628
{
27-
"name": "CanvasLayout",
28-
"type": "coreclr",
29+
"type": "PowerShell",
2930
"request": "launch",
30-
"program": "dotnet",
31-
"args": [
32-
"run",
33-
"build",
34-
"/r",
35-
"/bl",
36-
"/p:UnoSourceGeneratorUseGenerationHost=true",
37-
"/p:UnoSourceGeneratorUseGenerationController=false",
38-
"/p:UnoRemoteControlPort=443",
39-
"--project=${workspaceFolder}/labs/CanvasLayout/samples/CanvasLayout.Wasm/CanvasLayout.Wasm.csproj",
40-
"-p:TargetFrameworks=netstandard2.0",
41-
"-p:TargetFramework=net5.0",
42-
],
43-
"cwd": "${workspaceFolder}/labs/CanvasLayout/samples/CanvasLayout.Wasm",
31+
"name": "Discover samples",
32+
"script": "${workspaceFolder}/DiscoverSamples.ps1",
33+
"presentation": {
34+
"group": "2",
35+
"order": 2
36+
}
4437
}
4538
]
46-
}
39+
}

.vscode/tasks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "generateAllSolution",
8+
"type": "shell",
9+
"command": "pwsh ./GenerateAllSolution.ps1",
10+
"group": "build"
11+
}
12+
]
13+
}

DiscoverSamples.ps1

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
Param (
2+
[Parameter(HelpMessage = "Disables suppressing changes to the ./.vscode/launch.json file in git, allowing changes to be committed.")]
3+
[switch]$allowGitChanges = $false
4+
)
5+
6+
$templatedSampleProjectReferencesDefinitionMarker = "[TemplatedSampleProjectReferences]"
7+
$sampleRefsPropsTemplatePath = 'common/Labs.SampleRefs.props.template';
8+
$generatedSampleRefsPropsPath = 'common/Labs.SampleRefs.props';
9+
10+
function CreateVsCodeLaunchConfigJson {
11+
param (
12+
[string]$projectName
13+
)
14+
15+
return "{
16+
`"name`": `"$projectName`",
17+
`"type`": `"coreclr`",
18+
`"request`": `"launch`",
19+
`"program`": `"dotnet`",
20+
`"args`": [
21+
`"run`",
22+
`"build`",
23+
`"/r`",
24+
`"/p:UnoSourceGeneratorUseGenerationHost=true`",
25+
`"/p:UnoSourceGeneratorUseGenerationController=false`",
26+
`"/p:UnoRemoteControlPort=443`",
27+
`"--project=`$`{workspaceFolder`}/labs/$projectName/samples/$projectName.Wasm/$projectName.Wasm.csproj`",
28+
`"-p:TargetFrameworks=netstandard2.0`",
29+
`"-p:TargetFramework=net5.0`",
30+
],
31+
`"presentation`": {
32+
`"group`": `"2`",
33+
},
34+
`"cwd`": `"`$`{workspaceFolder`}/labs/$projectName/samples/$projectName.Wasm`",
35+
}";
36+
}
37+
38+
# Execute ProjectReference generation for all heads
39+
$sampleRefsPropsTemplate = Get-Content -Path $sampleRefsPropsTemplatePath;
40+
Write-Output "Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath";
41+
42+
# Add sample projects
43+
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Sample/*.Sample.csproj') {
44+
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
45+
$relativePath = $relativePath.TrimStart('.\');
46+
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
47+
48+
Write-Host "Adding $projectName to project references";
49+
50+
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
51+
52+
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
53+
" + $projectReferenceDefinition);
54+
}
55+
56+
# Add library projects
57+
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/src/*.csproj') {
58+
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
59+
$relativePath = $relativePath.TrimStart('.\');
60+
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
61+
62+
Write-Host "Adding $projectName to project references";
63+
64+
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
65+
66+
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
67+
" + $projectReferenceDefinition);
68+
}
69+
70+
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), "";
71+
72+
# Save
73+
Set-Content -Path $generatedSampleRefsPropsPath -Value $sampleRefsPropsTemplate;
74+
Write-Output "Sample project references generated at $generatedSampleRefsPropsPath";
75+
76+
$launchConfigJson = Get-Content -Path "./.vscode/launch.json";
77+
$launchConfig = $launchConfigJson | ConvertFrom-Json;
78+
79+
# Remove all non-generated configurations
80+
$originalConfigurations = $launchConfig.configurations;
81+
$launchConfig.configurations = @();
82+
$launchConfig.configurations += $originalConfigurations[0];
83+
$launchConfig.configurations += $originalConfigurations[1];
84+
85+
foreach ($wasmProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Wasm/*.Wasm.csproj') {
86+
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($wasmProjectPath) -Replace ".Wasm", "";
87+
Write-Host "Generating VSCode launch config for $projectName";
88+
89+
$configJson = CreateVsCodeLaunchConfigJson $projectName;
90+
$config = $configJson | ConvertFrom-Json;
91+
92+
$launchConfig.configurations += $config;
93+
}
94+
95+
if ($allowGitChanges.IsPresent) {
96+
Write-Warning "Changes to the default launch.json in Labs can now be committed. Run this command again without the -allowGitChanges flag to disable committing further changes.";
97+
git update-index --no-assume-unchanged ./.vscode/launch.json
98+
}
99+
else {
100+
Write-Output "Changes to the default launch.json in Labs are now suppressed. To switch branches, run git reset --hard with a clean working tree. Include the -allowGitChanges flag to enable committing changes.";
101+
git update-index --assume-unchanged ./.vscode/launch.json
102+
}
103+
104+
# Save
105+
Set-Content -Path "./.vscode/launch.json" -Value ($launchConfig | ConvertTo-Json -Depth 9);
106+
Write-Output "Saved VSCode launch configs to ./.vscode/launch.json";

GenerateAllSolution.ps1

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ $templatedProjectDefinitionsMarker = "[TemplatedProjectDefinitions]";
1919
$templatedSharedTestProjectSelfDefinitionsMarker = "[TemplatedSharedTestProjectDefinitions]";
2020
$templatedSharedTestUwpProjectSelfDefinitionsMarker = "[TemplatedSharedTestUwpProjectDefinitions]";
2121
$templatedSharedTestWinAppSdkProjectSelfDefinitionsMarker = "[TemplatedSharedTestWinAppSdkProjectDefinitions]";
22-
$templatedSampleProjectReferencesDefinitionMarker = "[TemplatedSampleProjectReferences]"
2322

2423
$sampleProjectTypeGuid = "9A19103F-16F7-4668-BE54-9A1E7A4F7556";
2524
$sharedProjectTypeGuid = "D954291E-2A0B-460D-934E-DC6B0785DB48";
@@ -28,9 +27,6 @@ $libProjectTypeGuid = $sampleProjectTypeGuid;
2827
$solutionTemplatePath = 'common/Toolkit.Labs.All.sln.template';
2928
$generatedSolutionFilePath = 'Toolkit.Labs.All.sln'
3029

31-
$sampleRefsPropsTemplatePath = 'common/Labs.SampleRefs.props.template';
32-
$generatedSampleRefsPropsPath = 'common/Labs.SampleRefs.props';
33-
3430
function CreateProjectConfiguration {
3531
param (
3632
[string]$projectGuid
@@ -248,40 +244,5 @@ $solutionTemplate = $solutionTemplate -replace "(?m)^\s*`r`n", "";
248244
Set-Content -Path $generatedSolutionFilePath -Value $solutionTemplate;
249245
Write-Output "Solution generated at $generatedSolutionFilePath";
250246

251-
# Execute ProjectReference generation for all heads
252-
$sampleRefsPropsTemplate = Get-Content -Path $sampleRefsPropsTemplatePath;
253-
Write-Output "Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath";
254-
255-
# Add sample projects
256-
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Sample/*.Sample.csproj') {
257-
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
258-
$relativePath = $relativePath.TrimStart('.\');
259-
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
260-
261-
Write-Host "Adding $projectName to project references";
262-
263-
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
264-
265-
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
266-
" + $projectReferenceDefinition);
267-
}
268-
269-
# Add library projects
270-
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/src/*.csproj') {
271-
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
272-
$relativePath = $relativePath.TrimStart('.\');
273-
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);
274-
275-
Write-Host "Adding $projectName to project references";
276-
277-
$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";
278-
279-
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
280-
" + $projectReferenceDefinition);
281-
}
282-
283-
$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), "";
284-
285-
# Save
286-
Set-Content -Path $generatedSampleRefsPropsPath -Value $sampleRefsPropsTemplate;
287-
Write-Output "Sample project references generated at $generatedSampleRefsPropsPath";
247+
# Run sample discovery
248+
& ./DiscoverSamples.ps1

common/CommunityToolkit.Labs.Core.SourceGenerators/ToolkitSampleMetadataGenerator.Documentation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private ImmutableArray<ToolkitFrontMatter> GatherDocumentFrontMatter(SourceProdu
147147
}
148148

149149
// Get the filepath we need to be able to load the markdown file in sample app.
150-
var filepath = file.Path.Split(new string[] { @"\labs\" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
150+
var filepath = file.Path.Split(new string[] { @"\labs\", "/labs/" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
151151

152152
// Look for sample id tags
153153
var matches = MarkdownRegexSampleTag.Matches(content);

0 commit comments

Comments
 (0)