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+
16$templatedSampleProjectReferencesDefinitionMarker = " [TemplatedSampleProjectReferences]"
27$sampleRefsPropsTemplatePath = ' common/Labs.SampleRefs.props.template' ;
38$generatedSampleRefsPropsPath = ' common/Labs.SampleRefs.props' ;
49
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+ `" /bl`" ,
25+ `" /p:UnoSourceGeneratorUseGenerationHost=true`" ,
26+ `" /p:UnoSourceGeneratorUseGenerationController=false`" ,
27+ `" /p:UnoRemoteControlPort=443`" ,
28+ `" --project=${workspaceFolder} /labs/$projectName /samples/$projectName .Wasm/$projectName .Wasm.csproj`" ,
29+ `" -p:TargetFrameworks=netstandard2.0`" ,
30+ `" -p:TargetFramework=net5.0`" ,
31+ ],
32+ `" presentation`" : {
33+ `" group`" : `" 2`" ,
34+ },
35+ `" cwd`" : `" ${workspaceFolder} /labs/$projectName /samples/$projectName .Wasm`" ,
36+ }" ;
37+ }
38+
539# Execute ProjectReference generation for all heads
640$sampleRefsPropsTemplate = Get-Content - Path $sampleRefsPropsTemplatePath ;
741Write-Output " Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath " ;
842
943# Add sample projects
1044foreach ($sampleProjectPath in Get-ChildItem - Recurse - Path ' labs/*/samples/*.Sample/*.Sample.csproj' ) {
11- $relativePath = Resolve-Path - Relative - Path $sampleProjectPath ;
12- $relativePath = $relativePath.TrimStart (' .\' );
13- $projectName = [System.IO.Path ]::GetFileNameWithoutExtension($relativePath );
45+ $relativePath = Resolve-Path - Relative - Path $sampleProjectPath ;
46+ $relativePath = $relativePath.TrimStart (' .\' );
47+ $projectName = [System.IO.Path ]::GetFileNameWithoutExtension($relativePath );
1448
15- Write-Host " Adding $projectName to project references" ;
49+ Write-Host " Adding $projectName to project references" ;
1650
17- $projectReferenceDefinition = " <ProjectReference Include=`"`$ (RepositoryDirectory)$relativePath `" />" ;
51+ $projectReferenceDefinition = " <ProjectReference Include=`"`$ (RepositoryDirectory)$relativePath `" />" ;
1852
19- $sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex ]::escape($templatedSampleProjectReferencesDefinitionMarker ), ($templatedSampleProjectReferencesDefinitionMarker + "
53+ $sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex ]::escape($templatedSampleProjectReferencesDefinitionMarker ), ($templatedSampleProjectReferencesDefinitionMarker + "
2054 " + $projectReferenceDefinition );
2155}
2256
2357# Add library projects
2458foreach ($sampleProjectPath in Get-ChildItem - Recurse - Path ' labs/*/src/*.csproj' ) {
25- $relativePath = Resolve-Path - Relative - Path $sampleProjectPath ;
26- $relativePath = $relativePath.TrimStart (' .\' );
27- $projectName = [System.IO.Path ]::GetFileNameWithoutExtension($relativePath );
59+ $relativePath = Resolve-Path - Relative - Path $sampleProjectPath ;
60+ $relativePath = $relativePath.TrimStart (' .\' );
61+ $projectName = [System.IO.Path ]::GetFileNameWithoutExtension($relativePath );
2862
29- Write-Host " Adding $projectName to project references" ;
63+ Write-Host " Adding $projectName to project references" ;
3064
31- $projectReferenceDefinition = " <ProjectReference Include=`"`$ (RepositoryDirectory)$relativePath `" />" ;
65+ $projectReferenceDefinition = " <ProjectReference Include=`"`$ (RepositoryDirectory)$relativePath `" />" ;
3266
33- $sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex ]::escape($templatedSampleProjectReferencesDefinitionMarker ), ($templatedSampleProjectReferencesDefinitionMarker + "
67+ $sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex ]::escape($templatedSampleProjectReferencesDefinitionMarker ), ($templatedSampleProjectReferencesDefinitionMarker + "
3468 " + $projectReferenceDefinition );
3569}
3670
3771$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex ]::escape($templatedSampleProjectReferencesDefinitionMarker ), " " ;
3872
3973# Save
4074Set-Content - Path $generatedSampleRefsPropsPath - Value $sampleRefsPropsTemplate ;
41- Write-Output " Sample project references generated at $generatedSampleRefsPropsPath " ;
75+ Write-Output " Sample project references generated at $generatedSampleRefsPropsPath " ;
76+
77+ $launchConfigJson = Get-Content - Path " ./.vscode/launch.json" ;
78+ $launchConfig = $launchConfigJson | ConvertFrom-Json ;
79+
80+ # Remove all non-generated configurations
81+ $originalConfigurations = $launchConfig.configurations ;
82+ $launchConfig.configurations = @ ();
83+ $launchConfig.configurations += $originalConfigurations [0 ];
84+ $launchConfig.configurations += $originalConfigurations [1 ];
85+
86+ foreach ($wasmProjectPath in Get-ChildItem - Recurse - Path ' labs/*/samples/*.Wasm/*.Wasm.csproj' ) {
87+ $projectName = [System.IO.Path ]::GetFileNameWithoutExtension($wasmProjectPath ) -Replace " .Wasm" , " " ;
88+ Write-Host " Generating VSCode launch config for $projectName " ;
89+
90+ $configJson = CreateVsCodeLaunchConfigJson $projectName ;
91+ $config = $configJson | ConvertFrom-Json ;
92+
93+ $launchConfig.configurations += $config ;
94+ }
95+
96+ if ($allowGitChanges.IsPresent ) {
97+ 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." ;
98+ git update-index -- no- assume- unchanged ./ .vscode/ launch.json
99+ }
100+ else {
101+ 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." ;
102+ git update-index -- assume- unchanged ./ .vscode/ launch.json
103+ }
104+
105+ # Save
106+ Set-Content - Path " ./.vscode/launch.json" - Value ($launchConfig | ConvertTo-Json - Depth 9 );
107+ Write-Output " Saved VSCode launch configs to ./.vscode/launch.json" ;
0 commit comments