Skip to content

Commit a4beb3c

Browse files
committed
Fix template scripts, make them more flexible and robust
1 parent c3d0a61 commit a4beb3c

File tree

5 files changed

+378
-16
lines changed

5 files changed

+378
-16
lines changed

src/ProjectTemplates/scripts/Run-BlazorWasm-Locally.ps1

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,78 @@
33

44
# This script packages, installs and creates a template to help with rapid iteration in the templating area.
55
[CmdletBinding(PositionalBinding = $false)]
6-
param()
6+
param(
7+
[ValidateSet("net9.0", "net10.0")]
8+
[string] $Framework = "net9.0",
9+
[Parameter(Mandatory = $false)]
10+
[switch] $NoRestore,
11+
[Parameter(Mandatory = $false)]
12+
[switch] $ExcludeLaunchSettings,
13+
[Parameter(Mandatory = $false)]
14+
[switch] $Empty,
15+
[Parameter(Mandatory = $false)]
16+
[ValidateSet("None", "Individual")]
17+
[string] $Auth = "None",
18+
[Parameter(Mandatory = $false)]
19+
[switch] $NoHttps,
20+
[Parameter(Mandatory = $false)]
21+
[switch] $UseProgramMain,
22+
[Parameter(Mandatory = $false)]
23+
[string] $Authority,
24+
[Parameter(Mandatory = $false)]
25+
[string] $ClientId,
26+
[switch] $Pwa,
27+
[Parameter(ValueFromRemainingArguments = $true)]
28+
[string[]] $Args
29+
)
730

831
Set-StrictMode -Version 2
932
$ErrorActionPreference = 'Stop'
1033

11-
. $PSScriptRoot\Test-Template.ps1
34+
$templateArguments = @("blazorwasm");
1235

13-
Test-Template "blazorwasm" "blazorwasm --hosted --auth Individual" "Microsoft.DotNet.Web.ProjectTemplates.9.0.9.0.0-dev.nupkg" $true
36+
if ($ExcludeLaunchSettings) {
37+
$templateArguments += "--exclude-launch-settings"
38+
}
39+
40+
if ($Empty) {
41+
$templateArguments += "-e"
42+
}
43+
44+
if ($Auth) {
45+
$templateArguments += "--auth";
46+
$templateArguments += $Auth;
47+
}
48+
49+
$mainProjectRelativePath = $null;
50+
51+
if ($NoHttps) {
52+
$templateArguments += "--no-https"
53+
}
54+
55+
if ($Authority) {
56+
$templateArguments += "--authority"
57+
$templateArguments += $Authority
58+
}
59+
60+
if ($ClientId) {
61+
$templateArguments += "--client-id"
62+
$templateArguments += $ClientId
63+
}
64+
65+
if ($Pwa) {
66+
$templateArguments += "--pwa"
67+
}
68+
69+
if ($UseProgramMain) {
70+
$templateArguments += "--use-program-main"
71+
}
72+
73+
Import-Module -Name .\Test-Template.psm1;
74+
75+
Test-Template `
76+
-TemplateName "MyBlazorWasmApp" `
77+
-TemplateArguments $templateArguments `
78+
-MainProjectRelativePath $mainProjectRelativePath `
79+
-TargetFramework $Framework `
80+
-Verbose:$VerbosePreference;

src/ProjectTemplates/scripts/Run-BlazorWeb-Locally.ps1

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,84 @@
22
#requires -version 4
33

44
# This script packages, installs and creates a template to help with rapid iteration in the templating area.
5-
[CmdletBinding(PositionalBinding = $false)]
6-
param()
5+
[CmdletBinding(PositionalBinding = $false)]
6+
param(
7+
[Parameter(Mandatory = $false, Position = 0)]
8+
[ValidateSet("net9.0", "net10.0")]
9+
[string] $Framework = "net9.0",
10+
[Parameter(Mandatory = $false)]
11+
[switch] $NoRestore,
12+
[Parameter(Mandatory = $false)]
13+
[switch] $ExcludeLaunchSettings,
14+
[Parameter(Mandatory = $false)]
15+
[ValidateSet("None", "Server", "WebAssembly", "Auto")]
16+
[string] $Interactivity = "Server",
17+
[Parameter(Mandatory = $false)]
18+
[switch] $Empty,
19+
[Parameter(Mandatory = $false)]
20+
[ValidateSet("None", "Individual")]
21+
[string] $Auth = "None",
22+
[Parameter(Mandatory = $false)]
23+
[switch] $UseLocalDb,
24+
[Parameter(Mandatory = $false)]
25+
[switch] $AllInteractive,
26+
[Parameter(Mandatory = $false)]
27+
[switch] $NoHttps,
28+
[Parameter(Mandatory = $false)]
29+
[switch] $UseProgramMain,
30+
[Parameter(ValueFromRemainingArguments = $true)]
31+
[string[]] $Args
32+
)
733

8-
Set-StrictMode -Version 2
9-
$ErrorActionPreference = 'Stop'
34+
Set-StrictMode -Version 2
35+
$ErrorActionPreference = 'Stop'
1036

11-
. $PSScriptRoot\Test-Template.ps1
37+
$templateArguments = @("blazor");
1238

13-
Test-Template "MyBlazorApp" "blazor" "Microsoft.DotNet.Web.ProjectTemplates.9.0.9.0.0-dev.nupkg" $true
39+
if ($ExcludeLaunchSettings) {
40+
$templateArguments += "--exclude-launch-settings"
41+
}
42+
43+
if ($Interactivity) {
44+
$templateArguments += "--interactivity"
45+
$templateArguments += $Interactivity;
46+
}
47+
48+
if ($Empty) {
49+
$templateArguments += "-e"
50+
}
51+
52+
if ($Auth) {
53+
$templateArguments += "--auth";
54+
$templateArguments += $Auth;
55+
}
56+
57+
$mainProjectRelativePath = $null;
58+
if($Interactivity -in @("Auto", "WebAssembly")){
59+
$mainProjectRelativePath = "MyBlazorApp";
60+
}
61+
62+
if ($UseLocalDb) {
63+
$templateArguments += "-uld"
64+
}
65+
66+
if ($AllInteractive) {
67+
$templateArguments += "-ai"
68+
}
69+
70+
if ($NoHttps) {
71+
$templateArguments += "--no-https"
72+
}
73+
74+
if ($UseProgramMain) {
75+
$templateArguments += "--use-program-main"
76+
}
77+
78+
Import-Module -Name .\Test-Template.psm1;
79+
80+
Test-Template `
81+
-TemplateName "MyBlazorApp" `
82+
-TemplateArguments $templateArguments `
83+
-MainProjectRelativePath $mainProjectRelativePath `
84+
-TargetFramework $Framework `
85+
-Verbose:$VerbosePreference;
Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,57 @@
1-
#!/usr/bin/env powershell
1+
#!/usr/bin/env pwsh
22
#requires -version 4
33

4+
# This script packages, installs and creates a template to help with rapid iteration in the templating area.
45
[CmdletBinding(PositionalBinding = $false)]
5-
param()
6+
param(
7+
[Parameter(Mandatory = $false, Position = 0)]
8+
[ValidateSet("net9.0", "net10.0")]
9+
[string] $Framework = "net9.0",
10+
[Parameter(Mandatory = $false)]
11+
[switch] $ExcludeLaunchSettings,
12+
[Parameter(Mandatory = $false)]
13+
[ValidateSet("None", "Individual")]
14+
[string] $Auth = "None",
15+
[Parameter(Mandatory = $false)]
16+
[switch] $UseLocalDb,
17+
[Parameter(Mandatory = $false)]
18+
[switch] $NoHttps,
19+
[Parameter(Mandatory = $false)]
20+
[switch] $UseProgramMain,
21+
[Parameter(ValueFromRemainingArguments = $true)]
22+
[string[]] $Args
23+
)
624

7-
. $PSScriptRoot\Test-Template.ps1
25+
Set-StrictMode -Version 2
26+
$ErrorActionPreference = 'Stop'
827

9-
Test-Template "webapp" "webapp -au Individual" "Microsoft.DotNet.Web.ProjectTemplates.9.0.9.0.0-dev.nupkg" $false
28+
$templateArguments = @("webapp");
29+
30+
if ($ExcludeLaunchSettings) {
31+
$templateArguments += "--exclude-launch-settings"
32+
}
33+
34+
if ($Auth) {
35+
$templateArguments += "--auth";
36+
$templateArguments += $Auth;
37+
}
38+
39+
if ($UseLocalDb) {
40+
$templateArguments += "-uld"
41+
}
42+
43+
if ($NoHttps) {
44+
$templateArguments += "--no-https"
45+
}
46+
47+
if ($UseProgramMain) {
48+
$templateArguments += "--use-program-main"
49+
}
50+
51+
Import-Module -Name .\Test-Template.psm1;
52+
53+
Test-Template `
54+
-TemplateName "MyWebApp" `
55+
-TemplateArguments $templateArguments `
56+
-TargetFramework $Framework `
57+
-Verbose:$VerbosePreference;
Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,57 @@
11
#!/usr/bin/env pwsh
22
#requires -version 4
33

4+
# This script packages, installs and creates a template to help with rapid iteration in the templating area.
45
[CmdletBinding(PositionalBinding = $false)]
5-
param()
6+
param(
7+
[Parameter(Mandatory = $false, Position = 0)]
8+
[ValidateSet("net9.0", "net10.0")]
9+
[string] $Framework = "net9.0",
10+
[Parameter(Mandatory = $false)]
11+
[switch] $ExcludeLaunchSettings,
12+
[Parameter(Mandatory = $false)]
13+
[ValidateSet("None", "Individual")]
14+
[string] $Auth = "None",
15+
[Parameter(Mandatory = $false)]
16+
[switch] $UseLocalDb,
17+
[Parameter(Mandatory = $false)]
18+
[switch] $NoHttps,
19+
[Parameter(Mandatory = $false)]
20+
[switch] $UseProgramMain,
21+
[Parameter(ValueFromRemainingArguments = $true)]
22+
[string[]] $Args
23+
)
624

725
Set-StrictMode -Version 2
826
$ErrorActionPreference = 'Stop'
927

10-
. $PSScriptRoot\Test-Template.ps1
28+
$templateArguments = @("mvc");
1129

12-
Test-Template "mvc" "mvc -au Individual" "Microsoft.DotNet.Web.ProjectTemplates.9.0.9.0.0-dev.nupkg" $false
30+
if ($ExcludeLaunchSettings) {
31+
$templateArguments += "--exclude-launch-settings"
32+
}
33+
34+
if ($Auth) {
35+
$templateArguments += "--auth";
36+
$templateArguments += $Auth;
37+
}
38+
39+
if ($UseLocalDb) {
40+
$templateArguments += "-uld"
41+
}
42+
43+
if ($NoHttps) {
44+
$templateArguments += "--no-https"
45+
}
46+
47+
if ($UseProgramMain) {
48+
$templateArguments += "--use-program-main"
49+
}
50+
51+
Import-Module -Name .\Test-Template.psm1;
52+
53+
Test-Template `
54+
-TemplateName "MyMvcApp" `
55+
-TemplateArguments $templateArguments `
56+
-TargetFramework $Framework `
57+
-Verbose:$VerbosePreference;

0 commit comments

Comments
 (0)