diff --git a/.github/linters/.markdown-lint.yml b/.github/linters/.markdown-lint.yml index b9ecdfa..2ca7e45 100644 --- a/.github/linters/.markdown-lint.yml +++ b/.github/linters/.markdown-lint.yml @@ -6,20 +6,20 @@ # - https://github.com/DavidAnson/markdownlint ############### -# Rules by id # +# Rules by ID # ############### -MD004: false # Unordered list style +MD004: false # Unordered list style MD007: - indent: 2 # Unordered list indentation + indent: 2 # Unordered list indentation MD013: - line_length: 808 # Line length + line_length: 808 # Line length MD026: - punctuation: ".,;:!。,;:" # List of not allowed -MD029: false # Ordered list item prefix -MD033: false # Allow inline HTML -MD036: false # Emphasis used instead of a heading + punctuation: '.,;:!。,;:' # List of not allowed +MD029: false # Ordered list item prefix +MD033: false # Allow inline HTML +MD036: false # Emphasis used instead of a heading ################# # Rules by tags # ################# -blank_lines: false # Error on blank lines +blank_lines: false # Error on blank lines diff --git a/.github/linters/.powershell-psscriptanalyzer.psd1 b/.github/linters/.powershell-psscriptanalyzer.psd1 index 570ac0d..648c270 100644 --- a/.github/linters/.powershell-psscriptanalyzer.psd1 +++ b/.github/linters/.powershell-psscriptanalyzer.psd1 @@ -2,10 +2,10 @@ @{ #CustomRulePath='path\to\CustomRuleModule.psm1' #RecurseCustomRulePath='path\of\customrules' - #Severity = @( - # 'Error' - # 'Warning' - #) + # Severity = @( + # 'Error' + # 'Warning' + # ) #IncludeDefaultRules=${true} ExcludeRules = @( 'PSMissingModuleManifestField' diff --git a/.github/linters/.textlintrc b/.github/linters/.textlintrc new file mode 100644 index 0000000..db48de8 --- /dev/null +++ b/.github/linters/.textlintrc @@ -0,0 +1,513 @@ +{ + "filters": { + "comments": true + }, + "rules": { + "terminology": { + "defaultTerms": false, + "terms": [ + "Airbnb", + "Android", + "AppleScript", + "AppVeyor", + "AVA", + "BrowserStack", + "Browsersync", + "Codecov", + "CodePen", + "CodeSandbox", + "DefinitelyTyped", + "EditorConfig", + "ESLint", + "GitHub", + "GraphQL", + "GraphiQL", + "iOS", + "JavaScript", + "JetBrains", + "jQuery", + "LinkedIn", + "Lodash", + "MacBook", + "Markdown", + "OpenType", + "PayPal", + "PhpStorm", + "PowerShell", + "PlayStation", + "RubyMine", + "Sass", + "SemVer", + "TypeScript", + "UglifyJS", + "Wasm", + "WebAssembly", + "WebStorm", + "WordPress", + "YouTube", + [ + "Common[ .]js", + "CommonJS" + ], + [ + "JSDocs?", + "JSDoc" + ], + [ + "Node[ .]js", + "Node.js" + ], + [ + "React[ .]js", + "React" + ], + [ + "SauceLabs", + "Sauce Labs" + ], + [ + "StackOverflow", + "Stack Overflow" + ], + [ + "styled ?components", + "styled-components" + ], + [ + "HTTP[ /]2(?:\\.0)?", + "HTTP/2" + ], + [ + "OS X", + "macOS" + ], + [ + "Mac ?OS", + "macOS" + ], + [ + "a npm", + "an npm" + ], + "ECMAScript", + [ + "ES2015", + "ES6" + ], + [ + "ES7", + "ES2016" + ], + "3D", + [ + "3-D", + "3D" + ], + "Ajax", + "API", + "APIs", + "API's", + [ + "(? [Alias('Get-NerdFonts')] + [OutputType([System.Object[]])] [CmdletBinding()] param ( # Name of the NerdFont to get @@ -21,6 +31,7 @@ [string] $Name = '*' ) - Write-Verbose "Selecting assets by name: '$Name'" + Write-Verbose 'Selecting assets by:' + Write-Verbose "Name: [$Name]" $script:NerdFonts | Where-Object { $_.Name -like $Name } } diff --git a/src/functions/public/Install-NerdFont.ps1 b/src/functions/public/Install-NerdFont.ps1 index 96ce6cd..f2a3815 100644 --- a/src/functions/public/Install-NerdFont.ps1 +++ b/src/functions/public/Install-NerdFont.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules Admin, Fonts +#Requires -Modules @{ ModuleName = 'Fonts'; RequiredVersion = '1.1.13' } function Install-NerdFont { <# @@ -13,6 +13,11 @@ function Install-NerdFont { Installs the font 'Fira Code' to the current user. + .EXAMPLE + Install-NerdFont -Name 'Ubuntu*' + + Installs all fonts that match the pattern 'Ubuntu*' to the current user. + .EXAMPLE Install-NerdFont -Name 'Fira Code' -Scope AllUsers @@ -29,16 +34,17 @@ function Install-NerdFont { )] [Alias('Install-NerdFonts')] param( - # Specify the name of the Nerd font(s) to install. + # Specify the name of the NerdFont(s) to install. [Parameter( ParameterSetName = 'ByName', Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName )] + [SupportsWildcards()] [string[]] $Name, - # Specify to install all Nerd Font(s). + # Specify to install all NerdFont(s). [Parameter( ParameterSetName = 'All', Mandatory @@ -47,7 +53,11 @@ function Install-NerdFont { # Specify the scope of where to install the font(s). [Parameter()] - [Scope] $Scope = 'CurrentUser' + [Scope] $Scope = 'CurrentUser', + + # Force will overwrite existing fonts + [Parameter()] + [switch] $Force ) begin { @@ -60,14 +70,12 @@ Please run the command again with elevated rights (Run as Administrator) or prov } $nerdFontsToInstall = @() - $tempPath = Join-Path -Path $HOME -ChildPath '.temp' + $guid = (New-Guid).Guid + $tempPath = Join-Path -Path $HOME -ChildPath "NerdFonts-$guid" if (-not (Test-Path -Path $tempPath -PathType Container)) { Write-Verbose "Create folder [$tempPath]" $null = New-Item -Path $tempPath -ItemType Directory - $tempFolderCreated = $true } - - $Name = $PSBoundParameters.Name } process { @@ -75,44 +83,43 @@ Please run the command again with elevated rights (Run as Administrator) or prov $nerdFontsToInstall = $script:NerdFonts } else { foreach ($fontName in $Name) { - $nerdFontsToInstall += $script:NerdFonts | Where-Object Name -EQ $fontName + $nerdFontsToInstall += $script:NerdFonts | Where-Object { $_.Name -like $fontName } } } Write-Verbose "[$Scope] - Installing [$($nerdFontsToInstall.count)] fonts" - foreach ($NerdFont in $nerdFontsToInstall) { - $URL = $NerdFont.URL - $fontName = $NerdFont.Name - $downloadPath = Join-Path -Path $tempPath -ChildPath "$FontName$script:ArchiveExtension" - $extractPath = Join-Path -Path $tempPath -ChildPath "$fontName" + foreach ($nerdFont in $nerdFontsToInstall) { + $URL = $nerdFont.URL + $fontName = $nerdFont.Name + $downloadFileName = Split-Path -Path $URL -Leaf + $downloadPath = Join-Path -Path $tempPath -ChildPath $downloadFileName Write-Verbose "[$fontName] - Downloading to [$downloadPath]" - $storedProgressPreference = $ProgressPreference - $ProgressPreference = 'SilentlyContinue' # Suppress progress bar - if ($PSCmdlet.ShouldProcess($fontName, "Download $fontName")) { - Invoke-WebRequest -Uri $URL -OutFile $downloadPath -Verbose:$false + if ($PSCmdlet.ShouldProcess("[$fontName] to [$downloadPath]", 'Download')) { + Invoke-WebRequest -Uri $URL -OutFile $downloadPath -RetryIntervalSec 5 -MaximumRetryCount 5 } - $ProgressPreference = $storedProgressPreference - Write-Verbose "[$fontName] - Unpack to [$extractPath]" - if ($PSCmdlet.ShouldProcess($fontName, 'Extract archive')) { + $extractPath = Join-Path -Path $tempPath -ChildPath $fontName + Write-Verbose "[$fontName] - Extract to [$extractPath]" + if ($PSCmdlet.ShouldProcess("[$fontName] to [$extractPath]", 'Extract')) { Expand-Archive -Path $downloadPath -DestinationPath $extractPath -Force Remove-Item -Path $downloadPath -Force } Write-Verbose "[$fontName] - Install to [$Scope]" - if ($PSCmdlet.ShouldProcess($fontName, 'Install font')) { - Install-Font -Path $extractPath -Scope $Scope + if ($PSCmdlet.ShouldProcess("[$fontName] to [$Scope]", 'Install font')) { + Install-Font -Path $extractPath -Scope $Scope -Force:$Force Remove-Item -Path $extractPath -Force -Recurse } } } end { - if ($tempFolderCreated) { - Write-Verbose "Remove folder [$tempPath]" - Remove-Item -Path $tempPath -Force - } + Write-Verbose "Remove folder [$tempPath]" + } + + clean { + Remove-Item -Path $tempPath -Force } } diff --git a/src/functions/public/completers.ps1 b/src/functions/public/completers.ps1 index c00bfdd..d0cb716 100644 --- a/src/functions/public/completers.ps1 +++ b/src/functions/public/completers.ps1 @@ -1,8 +1,6 @@ -Register-ArgumentCompleter -CommandName Install-NerdFont, Get-NerdFont -ParameterName Name -ScriptBlock { +Register-ArgumentCompleter -CommandName Get-NerdFont, Install-NerdFont -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter - - Get-NerdFont | Select-Object -ExpandProperty Name | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { - [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) - } + Get-NerdFont -Verbose:$false | Select-Object -ExpandProperty Name | Where-Object { $_ -like "$wordToComplete*" } | + ForEach-Object { [System.Management.Automation.CompletionResult]::new("'$_'", $_, 'ParameterValue', $_) } } diff --git a/src/variables/private/NerdFonts.ps1 b/src/variables/private/NerdFonts.ps1 index cd63014..ceeb5ba 100644 --- a/src/variables/private/NerdFonts.ps1 +++ b/src/variables/private/NerdFonts.ps1 @@ -1,9 +1 @@ -$script:Release = Invoke-RestMethod 'https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest' -$script:NerdFonts = $script:Release.assets.browser_download_url | Where-Object { $_ -like '*.zip' } | ForEach-Object { - [pscustomobject]@{ - Name = $_.Split('/')[-1].Split('.')[0] - Version = $script:Release.tag_name - URL = $_ - } -} -$script:ArchiveExtension = '.zip' +$script:NerdFonts = Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath 'FontsData.json') | ConvertFrom-Json diff --git a/tests/NerdFonts.Tests.ps1 b/tests/NerdFonts.Tests.ps1 index 0eb1500..c32d4a7 100644 --- a/tests/NerdFonts.Tests.ps1 +++ b/tests/NerdFonts.Tests.ps1 @@ -1,9 +1,5 @@ Describe 'Module' { Context 'Function: Get-NerdFont' { - It 'Function exists' { - Get-Command Get-NerdFont | Should -Not -BeNullOrEmpty - } - It 'Returns all fonts' { $fonts = Get-NerdFont Write-Verbose ($fonts | Out-String) -Verbose @@ -18,16 +14,12 @@ } Context 'Function: Install-NerdFont' { - It '[Install-NerdFont] - Exists' { - Get-Command -Name Install-NerdFont | Should -Not -BeNullOrEmpty - } - - It '[Install-NerdFont] - Installs a font' { + It 'Install-NerdFont - Installs a font' { { Install-NerdFont -Name 'Tinos' } | Should -Not -Throw Get-Font -Name 'Tinos*' | Should -Not -BeNullOrEmpty } - It '[Install-NerdFont] - Installs all fonts' { + It 'Install-NerdFont - Installs all fonts' { { Install-NerdFont -All -Verbose } | Should -Not -Throw Get-Font -Name 'VictorMono*' | Should -Not -BeNullOrEmpty } diff --git a/tmp/Download-NerdFonts.ps1 b/tmp/Download-NerdFonts.ps1 deleted file mode 100644 index b64d978..0000000 --- a/tmp/Download-NerdFonts.ps1 +++ /dev/null @@ -1,7 +0,0 @@ -# function Download-NerdFonts { -# [CmdletBinding()] -# param( -# $Path = "$env:TEMP\NerdFonts" -# ) - -# } diff --git a/tmp/Get-NerdFontsRelease.ps1 b/tmp/Get-NerdFontsRelease.ps1 deleted file mode 100644 index 701e2ee..0000000 --- a/tmp/Get-NerdFontsRelease.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -# function Get-NerdFontsRelease { -# [CmdletBinding()] -# param( -# [Parameter( -# ParameterSetName = 'Latest', -# Mandatory -# )] -# [switch] $Latest, - -# [Parameter( -# ParameterSetName = 'Latest' -# )] -# [switch] $AllowPrerelease, - -# [Parameter( -# ParameterSetName = 'Version' -# )] -# [ValidateSet({ Get-NerdFontsVersionList })] -# [string] $Version -# ) - -# begin { -# $versionPattern = [regex]'(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' -# } - -# process { -# foreach ($TerraformPath in $Path) { -# $terraformVersionOutput = & $TerraformPath --version -# $version = $versionPattern.Match($terraformVersionOutput).Value -# [pscustomobject]@{ -# Path = $TerraformPath -# Version = $version -# } -# } -# } - -# end { -# return $versions -# } -# } diff --git a/tmp/Get-NerdFontsVersionList.ps1 b/tmp/Get-NerdFontsVersionList.ps1 deleted file mode 100644 index 8c9c658..0000000 --- a/tmp/Get-NerdFontsVersionList.ps1 +++ /dev/null @@ -1,12 +0,0 @@ -# function Get-NerdFontsVersionList { -# [OutputType([string[]])] -# [CmdletBinding()] -# param() - -# $versionPattern = [regex]'(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' - -# $release = Invoke-RestMethod $script:NerdFontsReleaseURL -Verbose:$false -# $versions = $release.tag_name | Where-Object { $_ -match $versionPattern } | Sort-Object - -# return $versions -# }