diff --git a/.github/copilot-commit-message-instructions.md b/.github/copilot-commit-message-instructions.md index 3cb904b..2297468 100644 --- a/.github/copilot-commit-message-instructions.md +++ b/.github/copilot-commit-message-instructions.md @@ -28,7 +28,7 @@ More Examples: - `chore`: (updating grunt tasks etc; no production code change) References: -- https://gist.githubusercontent.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716/raw/e75b1b9536ee5ee82e2ec0ba8948d8f8238488c3/semantic-commit-messages.md + - https://www.conventionalcommits.org/ - https://seesparkbox.com/foundry/semantic_commit_messages - http://karma-runner.github.io/1.0/dev/git-commit-msg.html diff --git a/Test/include/callPrivateContext.ps1 b/Test/include/callPrivateContext.ps1 index f2fa515..c4bae5d 100644 --- a/Test/include/callPrivateContext.ps1 +++ b/Test/include/callPrivateContext.ps1 @@ -14,10 +14,14 @@ if(-not $MODULE_PATH){ throw "Missing MODULE_PATH variable initialization. Check function Invoke-PrivateContext { param ( [Parameter(Mandatory, Position = 0)] - [scriptblock]$ScriptBlock + [scriptblock]$ScriptBlock, + [string]$ModulePath ) - $modulePath = $MODULE_PATH | Split-Path -Parent + if ([string]::IsNullOrEmpty($ModulePath)) { + $modulePath = $MODULE_PATH | Split-Path -Parent + } + $module = Import-Module -Name $modulePath -PassThru if ($null -eq $module) { diff --git a/Test/include/config.mock.ps1 b/Test/include/config.mock.ps1 index 5e86527..a4bd7db 100644 --- a/Test/include/config.mock.ps1 +++ b/Test/include/config.mock.ps1 @@ -9,29 +9,40 @@ if(-not $MODULE_NAME){ throw "Missing MODULE_NAME varaible initialization. Check for module.helerp.ps1 file." } $MOCK_CONFIG_PATH = "test_config_path" -$CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-$($MODULE_NAME)GetConfigRootPath" +$CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-ProjectHelperGetConfigRootPath" function Mock_Config{ param( [Parameter(Position=0)][string] $key = "config", - [Parameter(Position=1)][object] $Config + [Parameter(Position=1)][object] $Config, + [Parameter(Position=2)][string] $ModuleName, + [Parameter(Position=3)][string] $MockPath = $MOCK_CONFIG_PATH ) # Remove mock config path if exists - if(Test-Path $MOCK_CONFIG_PATH){ - Remove-Item -Path $MOCK_CONFIG_PATH -ErrorAction SilentlyContinue -Recurse -Force + if(Test-Path $MockPath){ + Remove-Item -Path $fullpath -ErrorAction SilentlyContinue -Recurse -Force } # create mock config path - New-Item -Path $MOCK_CONFIG_PATH -ItemType Directory -Force + New-Item -Path $MockPath -ItemType Directory -Force + + # make full and not relative path + $fullpath = $MockPath | Resolve-Path # if $config is not null save it to a file if($null -ne $Config){ - $configfile = Join-Path -Path $MOCK_CONFIG_PATH -ChildPath "$key.json" + $configfile = Join-Path -Path $fullpath -ChildPath "$key.json" $Config | ConvertTo-Json -Depth 10 | Set-Content $configfile } + if([string]::IsNullOrWhiteSpace($ModuleName)){ + $moduleName = $MODULE_NAME + } + + $invokefunction = $CONFIG_INVOKE_GET_ROOT_PATH_CMD -replace "ProjectHelper", $moduleName + # Mock invoke call - MockCallToString $CONFIG_INVOKE_GET_ROOT_PATH_CMD -OutString $MOCK_CONFIG_PATH + MockCallToString $invokefunction -OutString $fullpath } diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index fb019ef..f451b55 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -126,8 +126,8 @@ function Enable-ModuleNameVerbose{ $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag) } -Rename-Item -path Function:Enable-ModuleNameVerbose -NewName "Set-$($MODULE_NAME)Verbose" -Export-ModuleMember -Function "Set-$($MODULE_NAME)Verbose" +Copy-Item -path Function:Enable-ModuleNameVerbose -Destination Function:"Enable-$($MODULE_NAME)Verbose" +Export-ModuleMember -Function "Enable-$($MODULE_NAME)Verbose" function Disable-ModuleNameVerbose{ param() @@ -135,8 +135,8 @@ function Disable-ModuleNameVerbose{ $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null) } -Rename-Item -path Function:Disable-ModuleNameVerbose -NewName "Clear-$($MODULE_NAME)Verbose" -Export-ModuleMember -Function "Clear-$($MODULE_NAME)Verbose" +Copy-Item -path Function:Disable-ModuleNameVerbose -Destination Function:"Disable-$($MODULE_NAME)Verbose" +Export-ModuleMember -Function "Disable-$($MODULE_NAME)Verbose" function Test-MyDebug { param( @@ -173,7 +173,7 @@ function Enable-ModuleNameDebug{ $moduleDebugVarName = $MODULE_NAME + "_DEBUG" [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag) } -Rename-Item -path Function:Enable-ModuleNameDebug -NewName "Enable-$($MODULE_NAME)Debug" +Copy-Item -path Function:Enable-ModuleNameDebug -Destination Function:"Enable-$($MODULE_NAME)Debug" Export-ModuleMember -Function "Enable-$($MODULE_NAME)Debug" function Disable-ModuleNameDebug { @@ -182,7 +182,7 @@ function Disable-ModuleNameDebug { $moduleDebugVarName = $MODULE_NAME + "_DEBUG" [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null) } -Rename-Item -path Function:Disable-ModuleNameDebug -NewName "Disable-$($MODULE_NAME)Debug" +Copy-Item -path Function:Disable-ModuleNameDebug -Destination Function:"Disable-$($MODULE_NAME)Debug" Export-ModuleMember -Function "Disable-$($MODULE_NAME)Debug" function Get-ObjetString { diff --git a/include/config.ps1 b/include/config.ps1 index 5e372ca..741525c 100644 --- a/include/config.ps1 +++ b/include/config.ps1 @@ -13,7 +13,9 @@ # # MODULE_NAME -$MODULE_NAME = ($PSScriptRoot | Split-Path -Parent | Get-ChildItem -Filter *.psd1 | Select-Object -First 1).BaseName +$MODULE_NAME_PATH = ($PSScriptRoot | Split-Path -Parent | Get-ChildItem -Filter *.psd1 | Select-Object -First 1) | Split-Path -Parent +$MODULE_NAME = $MODULE_NAME_PATH | Split-Path -LeafBase + if(-Not $MODULE_NAME){ throw "Module name not found. Please check the module structure." } $CONFIG_ROOT = [System.Environment]::GetFolderPath('UserProfile') | Join-Path -ChildPath ".helpers" -AdditionalChildPath $MODULE_NAME, "config" @@ -126,7 +128,7 @@ function Invoke-ModuleNameGetConfigRootPath { $function = "Invoke-ModuleNameGetConfigRootPath" $destFunction = $function -replace "ModuleName", $MODULE_NAME if( -not (Test-Path function:$destFunction )){ - Rename-Item -path Function:$function -NewName $destFunction + Copy-Item -path Function:$function -Destination Function:$destFunction Export-ModuleMember -Function $destFunction } @@ -143,7 +145,7 @@ function Get-ModuleNameConfig{ $function = "Get-ModuleNameConfig" $destFunction = $function -replace "ModuleName", $MODULE_NAME if( -not (Test-Path function:$destFunction )){ - Rename-Item -path Function:$function -NewName $destFunction + Copy-Item -path Function:$function -Destination Function:$destFunction Export-ModuleMember -Function $destFunction } @@ -158,7 +160,7 @@ function Open-ModuleNameConfig{ $function = "Open-ModuleNameConfig" $destFunction = $function -replace "ModuleName", $MODULE_NAME if( -not (Test-Path function:$destFunction )){ - Rename-Item -path Function:$function -NewName $destFunction + Copy-Item -path Function:$function -Destination Function:$destFunction Export-ModuleMember -Function $destFunction } diff --git a/include/featureflag.ps1 b/include/featureflag.ps1 index 5184202..7f32e12 100644 --- a/include/featureflag.ps1 +++ b/include/featureflag.ps1 @@ -2,13 +2,20 @@ # # Feature Flags management module # -# Include design description -# This module depends on Config Include # This module will allow set Feature Flags to the module to quicker release # features with less risk # +# Include design description +# This module depends on Config Include +# Config module will depend on invokeCommand.helper.ps1, MyWrite.ps1, config.ps1, module.helper.ps1 +# +# As you se features keys they will be recorded on a config file. +# Deprecate the FF to have it removed from the config file when the FF is released (aka set functionality to GA with now FF. +# Use Clear-FeatureFlagsRegistered to remove deprecated FF from config + $MODULE_NAME_PATH = ($PSScriptRoot | Split-Path -Parent | Get-ChildItem -Filter *.psd1 | Select-Object -First 1) | Split-Path -Parent +$MODULE_NAME = $MODULE_NAME_PATH | Split-Path -LeafBase function Get-FeatureFlags{ [CmdletBinding()] @@ -86,31 +93,46 @@ function Clear-FeatureFlag{ } +function Clear-FeatureFlagsRegistered{ + [cmdletbinding()] + param() + + $rffs = Get-ModuleNameRegisteredFeatureFlags + $ffs = (Get-FeatureFlags).Clone() + + $rffs.deprecated | ForEach-Object { + $ffs.Remove($_) + } + + Save-FeatureFlags $ffs + +} + ###### -# function Get-ModuleNameRegisteredFeatureFlags{ -# [cmdletbinding()] -# param() +function Get-ModuleNameRegisteredFeatureFlags{ + [cmdletbinding()] + param() -# $ffPath = $MODULE_NAME_PATH | Join-Path -ChildPath "featureflags.json" + $ffPath = $MODULE_NAME_PATH | Join-Path -ChildPath "featureflags.json" -# if(! ($ffPath | Test-Path)){ -# return -# } + if(! ($ffPath | Test-Path)){ + return + } -# $Json = Get-Content $ffPath + $Json = Get-Content $ffPath -# $ff = $Json | ConvertFrom-Json + $ff = $Json | ConvertFrom-Json -# return $ff + return $ff -# } -# $function = "Get-ModuleNameRegisteredFeatureFlags" -# $destFunction = $function -replace "ModuleName", $MODULE_NAME -# if( -not (Test-Path function:$destFunction )){ -# Rename-Item -path Function:$function -NewName $destFunction -# Export-ModuleMember -Function $destFunction -# } +} +$function = "Get-ModuleNameRegisteredFeatureFlags" +$destFunction = $function -replace "ModuleName", $MODULE_NAME +if( -not (Test-Path function:$destFunction )){ + Copy-Item -path Function:$function -Destination Function:$destFunction + Export-ModuleMember -Function $destFunction +} function Get-ModuleNameFeatureFlags{ [cmdletbinding()] @@ -142,3 +164,4 @@ if( -not (Test-Path function:$destFunction )){ Rename-Item -path Function:$function -NewName $destFunction Export-ModuleMember -Function $destFunction } +