Package creation template and scoop package
Set-MyPackage has a template option that will create skelaton content when a new package is created. Add scoop package, so that refresh will occur automatically on powershell launch if it hasn't been run in the past 3 hours.
This commit is contained in:
parent
4ba9a69fb9
commit
1672c384ad
|
@ -7,7 +7,9 @@
|
||||||
[switch]$LocalUser,
|
[switch]$LocalUser,
|
||||||
[switch]$Force,
|
[switch]$Force,
|
||||||
[switch]$PassThru,
|
[switch]$PassThru,
|
||||||
[switch]$DryRun
|
[switch]$DryRun,
|
||||||
|
[ValidateSet("Default","None")]
|
||||||
|
[string]$Template="Default"
|
||||||
)
|
)
|
||||||
|
|
||||||
process {
|
process {
|
||||||
|
@ -37,7 +39,19 @@ process {
|
||||||
if( -not $DryRun ) {
|
if( -not $DryRun ) {
|
||||||
$local:pkgPath = Join-Path $MyPSScriptRoot $iObj.name
|
$local:pkgPath = Join-Path $MyPSScriptRoot $iObj.name
|
||||||
Write-Verbose "pkgPath=$pkgPath"
|
Write-Verbose "pkgPath=$pkgPath"
|
||||||
if( -not (Test-Path $pkgPath) ) { $null = New-Item -Type Directory $pkgPath -Force:$Force }
|
if( -not (Test-Path $pkgPath) ) {
|
||||||
|
$null = New-Item -Type Directory $pkgPath -Force:$Force
|
||||||
|
} elseif ( -not $Force ) {
|
||||||
|
$Template = "None"
|
||||||
|
}
|
||||||
|
switch($Template){
|
||||||
|
"Default" {
|
||||||
|
New-Item -Type Directory (Join-Path $pkgPath 'profile.d')
|
||||||
|
New-Item -Type Directory (Join-Path $pkgPath 'Aliases')
|
||||||
|
New-Item -Type Directory (Join-Path $pkgPath 'src')
|
||||||
|
New-Item -Type File -Path (Join-Path (Join-Path $pkgPath 'profile.d') 'env.local.ps1') -Value ''
|
||||||
|
}
|
||||||
|
}
|
||||||
$jsonPath = Join-Path $pkgPath '_.package.json'
|
$jsonPath = Join-Path $pkgPath '_.package.json'
|
||||||
if( $Force -or -not (Test-Path $jsonPath) ) {
|
if( $Force -or -not (Test-Path $jsonPath) ) {
|
||||||
$jsonOut | Out-File $jsonPath -Force:$Force
|
$jsonOut | Out-File $jsonPath -Force:$Force
|
||||||
|
|
|
@ -23,7 +23,9 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||||
$local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot)
|
$local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot)
|
||||||
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
|
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
|
||||||
$local:hostname = $(hostname)
|
$local:hostname = $(hostname)
|
||||||
|
|
||||||
$local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } )
|
$local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } )
|
||||||
|
|
||||||
foreach( $local:c in $Package.Condition ) {
|
foreach( $local:c in $Package.Condition ) {
|
||||||
if( $valid -eq ($c.Logic -in ([szLogic]::or, [szLogic]::ornot )) ) { continue }
|
if( $valid -eq ($c.Logic -in ([szLogic]::or, [szLogic]::ornot )) ) { continue }
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,20 @@
|
||||||
|
$local:whenLast = $null
|
||||||
|
$local:whenLastSavePath = $(Join-Path $env:SCOOP last-scoop-refresh.clixml)
|
||||||
|
|
||||||
|
if( Test-Path $whenLastSavePath ) {
|
||||||
|
$whenLast = Import-Clixml -LiteralPath $whenLastSavePath
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $whenLast ) {
|
||||||
|
$local:TimePassed = (Get-Date) - $local:whenLast
|
||||||
|
if( $TimePassed.TotalHours -ge 3 ) {
|
||||||
|
$whenLast = $null
|
||||||
|
} else {
|
||||||
|
Write-Host -ForegroundColor Yellow "Only $(ConvertFrom-TimeSpan $TimePassed) has passed, skipping scoop refresh."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( -not $whenLast ) {
|
||||||
|
scoop refresh
|
||||||
|
$whenLast | Export-Clixml -LiteralPath $whenLastSavePath
|
||||||
|
}
|
Loading…
Reference in New Issue