Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions PSModuleDevelopment/PSModuleDevelopment.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'PSModuleDevelopment.psm1'

# Version number of this module.
ModuleVersion = '2.0.0.0'
ModuleVersion = '2.1.0.1'

# ID used to uniquely identify this module
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'
Expand Down Expand Up @@ -41,7 +41,7 @@

# Modules that must be imported into the global environment prior to importing
# this module
RequiredModules = @(@{ ModuleName='PSFramework'; ModuleVersion='0.9.4.9' })
RequiredModules = @(@{ ModuleName='PSFramework'; ModuleVersion= '0.9.8.17' })

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @('bin\PSModuleDevelopment.dll')
Expand Down Expand Up @@ -71,6 +71,7 @@
'Get-PSMDModuleDebug',
'Import-PSMDModuleDebug',
'Measure-PSMDCommandEx',
'New-PSMDDotNetProject',
'New-PSMDHeader',
'New-PSMDFormatTableDefinition',
'New-PssModuleProject',
Expand All @@ -92,6 +93,7 @@

# Aliases to export from this module
AliasesToExport = @(
'dotnetnew',
'find',
'hex',
'Restart-Shell',
Expand Down
2 changes: 1 addition & 1 deletion PSModuleDevelopment/PSModuleDevelopment.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$script:PSModuleRoot = $PSScriptRoot
$script:PSModuleVersion = "2.0.0.0"
$script:PSModuleVersion = "2.1.0.1"

$script:doDotSource = $false
if (Get-PSFConfigValue -Name PSModuleDevelopment.Import.DoDotSource) { $script:doDotSource = $true }
Expand Down
10 changes: 10 additions & 0 deletions PSModuleDevelopment/PSModuleDevelopment.psproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<Folder>tests\functions</Folder>
<Folder>tests\general</Folder>
<Folder>internal\functions</Folder>
<Folder>functions\templating</Folder>
<Folder>internal\tabcompletion</Folder>
<Folder>internal\tabcompletion\scriptblocks</Folder>
<Folder>internal\maintenance</Folder>
</Folders>
<Files>
<File Build="2">PSModuleDevelopment.psd1</File>
Expand Down Expand Up @@ -70,6 +74,12 @@
<File Build="2">tests\readme.md</File>
<File Build="2">xml\PSModuleDevelopment.Format.ps1xml</File>
<File Build="2">tests\functions\readme.md</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-New-PSMDDotNetProject_ps1">functions\templating\New-PSMDDotNetProject.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-assignment_ps1">internal\tabcompletion\assignment.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-dotNetTemplates_ps1">internal\tabcompletion\scriptblocks\dotNetTemplates.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-dotNetTemplatesUninstall_ps1">internal\tabcompletion\scriptblocks\dotNetTemplatesUninstall.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-dotNetTemplateCache_ps1">internal\maintenance\dotNetTemplateCache.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-dotNetTemplatesInstall_ps1">internal\tabcompletion\scriptblocks\dotNetTemplatesInstall.ps1</File>
</Files>
<StartupScript>F:\Synchronized Data\Scripte\Powershell Studio\Projects\PSModuleDevelopment\Test-Module.ps1</StartupScript>
</Project>
4 changes: 3 additions & 1 deletion PSModuleDevelopment/en-us/about_psmoduledevelopment.help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ LONG DESCRIPTION
# Changelog #
#-------------------------------------------------------------------------#

2.1.0.1 (???)
2.1.0.1 (January 24th, 2018)
- new: Included suite of tests, in order to provide a more reliable user
experience.
- new: Command New-PSMDDotNetProject
A wrapper around dotnet.exe

2.0.0.0 (December 18th, 2017)
- Breaking change: Renamed all commands to include the PSMD prefix
Expand Down
183 changes: 183 additions & 0 deletions PSModuleDevelopment/functions/templating/New-PSMDDotNetProject.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
function New-PSMDDotNetProject
{
<#
.SYNOPSIS
Wrapper function around 'dotnet new'

.DESCRIPTION
This function is a wrapper around the dotnet.exe application with the parameter 'new'.
It can be used to create projects from templates, as well as to administrate templates.

.PARAMETER TemplateName
The name of the template to create

.PARAMETER List
List the existing templates.

.PARAMETER Help
Ask for help / documentation.
Particularly useful when dealing with project types that have a lot of options.

.PARAMETER Force
Overwrite existing files.

.PARAMETER Name
The name of the project to create

.PARAMETER Output
The folder in which to create it.
Note: This folder will automatically be te root folder of the project.
If this folder doesn't exist yet, it will be created.
When used with -Force, it will automatically purge all contents.

.PARAMETER Install
Install the specified template from the VS marketplace.

.PARAMETER Uninstall
Uninstall an installed template.

.PARAMETER Arguments
Additional arguments to pass to the application.
Generally used for parameters when creating a project from a template.

.PARAMETER Confirm
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

.PARAMETER WhatIf
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

.EXAMPLE
PS C:\> dotnetnew -l

Lists all installed templates.

.EXAMPLE
PS C:\> dotnetnew mvc foo F:\temp\projects\foo -au Windows --no-restore

Creates a new MVC project named "foo" in folder "F:\Temp\projects\foo"
- It will set authentication to windows
- It will skip the automatic restore of the project on create
#>
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = 'Create')]
Param (
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Create')]
[Parameter(Position = 0, ParameterSetName = 'List')]
[string]
$TemplateName,

[Parameter(ParameterSetName = 'List')]
[Alias('l')]
[switch]
$List,

[Alias('h')]
[switch]
$Help,

[switch]
$Force,

[Parameter(Position = 1, ParameterSetName = 'Create')]
[Alias('n')]
[string]
$Name,

[Parameter(Position = 2, ParameterSetName = 'Create')]
[Alias('o')]
[string]
$Output,

[Parameter(Mandatory = $true, ParameterSetName = 'Install')]
[Alias('i')]
[string]
$Install,

[Parameter(Mandatory = $true, ParameterSetName = 'Uninstall')]
[Alias('u')]
[string]
$Uninstall,

[Parameter(ValueFromRemainingArguments = $true)]
[Alias('a')]
[string[]]
$Arguments
)

begin
{
$parset = $PSCmdlet.ParameterSetName
Write-PSFMessage -Level InternalComment -Message "Active parameterset: $parset" -Tag 'start'

if (-not (Get-Command dotnet.exe))
{
throw "Could not find dotnet.exe! This should automatically be available on machines with Visual Studio installed."
}

$dotNetArgs = @()
switch ($parset)
{
'Create'
{
if (Test-PSFParameterBinding -ParameterName TemplateName) { $dotNetArgs += $TemplateName }
if ($Help) { $dotNetArgs += "-h" }
if (Test-PSFParameterBinding -ParameterName Name)
{
$dotNetArgs += "-n"
$dotNetArgs += $Name
}
if (Test-PSFParameterBinding -ParameterName Output)
{
$dotNetArgs += "-o"
$dotNetArgs += $Output
}
if ($Force) { $dotNetArgs += "--Force" }
}
'List'
{
if (Test-PSFParameterBinding -ParameterName TemplateName) { $dotNetArgs += $TemplateName }
$dotNetArgs += '-l'
if ($Help) { $dotNetArgs += "-h" }
}
'Install'
{
$dotNetArgs += '-i'
$dotNetArgs += $Install
if ($Help) { $dotNetArgs += '-h'}
}
'Uninstall'
{
$dotNetArgs += '-u'
$dotNetArgs += $Uninstall
if ($Help) { $dotNetArgs += '-h' }
}
}

foreach ($item in $Arguments)
{
$dotNetArgs += $item
}
Write-PSFMessage -Level Verbose -Message "Resolved arguments: $($dotNetArgs -join " ")" -Tag 'argument','start'
}
process
{
if ($PSCmdlet.ShouldProcess("dotnet", "Perform action: $parset"))
{
if ($parset -eq 'Create')
{
if ($Output)
{
if ((Test-Path $Output) -and $Force) { $null = New-Item $Output -ItemType Directory -Force -ErrorAction Stop }
if (-not (Test-Path $Output)) { $null = New-Item $Output -ItemType Directory -Force -ErrorAction Stop }
}
}
Write-PSFMessage -Level Verbose -Message "Executing with arguments: $($dotNetArgs -join " ")" -Tag 'argument', 'start'
& dotnet.exe new $dotNetArgs
}
}
end
{

}
}

New-Alias -Name dotnetnew -Value New-PSMDDotNetProject -Option AllScope -Scope Global -ErrorAction Ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$scriptBlock = {
$webclient = New-Object System.Net.WebClient
$string = $webclient.DownloadString("http://dotnetnew.azurewebsites.net/")
$templates = $string -split "`n" | Select-String '<a href="/template/(.*?)/.*?">.*?</a>' | ForEach-Object { $_.Matches.Groups[1].Value } | Select-Object -Unique | Sort-Object

Set-PSFTaskEngineCache -Module PSModuleDevelopment -Name "dotNetTemplates" -Value $templates
}
Register-PSFTaskEngineTask -Name "psmd_dotNetTemplateCache" -ScriptBlock $scriptBlock -Priority Low -Once -Description "Builds up the cache of installable templates for dotnet"
15 changes: 14 additions & 1 deletion PSModuleDevelopment/internal/scripts/postload.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@ foreach ($__module in $__modules)
}

# Import License
. Import-PSMDFile -Path "$PSModuleRoot\internal\scripts\license.ps1"
. Import-PSMDFile -Path "$PSModuleRoot\internal\scripts\license.ps1"

# Import maintenance tasks
foreach ($file in (Get-ChildItem -Path "$PSModuleRoot\internal\maintenance"))
{
. Import-PSMDFile -Path $file.FullName
}

# Import tab completion
foreach ($file in (Get-ChildItem -Path "$PSModuleRoot\internal\tabcompletion\scriptblocks"))
{
. Import-PSMDFile -Path $file.FullName
}
Import-PSMDFile -Path "$PSModuleRoot\internal\tabcompletion\assignment.ps1"
4 changes: 4 additions & 0 deletions PSModuleDevelopment/internal/tabcompletion/assignment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# New-PSMDDotNetProject
Register-PSFTeppArgumentCompleter -Name PSMD_dotNetTemplates -Command New-PSMDDotNetProject -Parameter TemplateName
Register-PSFTeppArgumentCompleter -Name PSMD_dotNetTemplatesUninstall -Command New-PSMDDotNetProject -Parameter Uninstall
Register-PSFTeppArgumentCompleter -Name PSMD_dotNetTemplatesInstall -Command New-PSMDDotNetProject -Parameter Install
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Register-PSFTeppScriptblock -Name PSMD_dotNetTemplates -ScriptBlock {
if (-not (Test-Path "$env:USERPROFILE\.templateengine\dotnetcli")) { return }

$folder = (Get-ChildItem "$env:USERPROFILE\.templateengine\dotnetcli" | Sort-Object Name | Select-Object -Last 1).FullName
Get-Content -Path "$folder\templatecache.json" | ConvertFrom-Json | Select-Object -ExpandProperty TemplateInfo | Select-Object -ExpandProperty ShortName -Unique
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Register-PSFTeppScriptblock -Name PSMD_dotNetTemplatesInstall -ScriptBlock {
Get-PSFTaskEngineCache -Module PSModuleDevelopment -Name "dotNetTemplates"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Register-PSFTeppScriptblock -Name PSMD_dotNetTemplatesUninstall -ScriptBlock {
if (-not (Test-Path "$env:USERPROFILE\.templateengine\dotnetcli")) { return }

$folder = (Get-ChildItem "$env:USERPROFILE\.templateengine\dotnetcli" | Sort-Object Name | Select-Object -Last 1).FullName
$items = Get-Content -Path "$folder\installUnitDescriptors.json" | ConvertFrom-Json | Select-Object -ExpandProperty InstalledItems
$items.PSObject.Properties.Value
}