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" ;
0 commit comments