Skip to content

Commit ee41ae4

Browse files
committed
refactor(include): update include helpers modules
1 parent 2c9231f commit ee41ae4

6 files changed

Lines changed: 79 additions & 39 deletions

File tree

.github/copilot-commit-message-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ More Examples:
2828
- `chore`: (updating grunt tasks etc; no production code change)
2929

3030
References:
31-
- https://gist.githubusercontent.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716/raw/e75b1b9536ee5ee82e2ec0ba8948d8f8238488c3/semantic-commit-messages.md
31+
3232
- https://www.conventionalcommits.org/
3333
- https://seesparkbox.com/foundry/semantic_commit_messages
3434
- http://karma-runner.github.io/1.0/dev/git-commit-msg.html

Test/include/callPrivateContext.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ if(-not $MODULE_PATH){ throw "Missing MODULE_PATH variable initialization. Check
1414
function Invoke-PrivateContext {
1515
param (
1616
[Parameter(Mandatory, Position = 0)]
17-
[scriptblock]$ScriptBlock
17+
[scriptblock]$ScriptBlock,
18+
[string]$ModulePath
1819
)
1920

20-
$modulePath = $MODULE_PATH | Split-Path -Parent
21+
if ([string]::IsNullOrEmpty($ModulePath)) {
22+
$modulePath = $MODULE_PATH | Split-Path -Parent
23+
}
24+
2125
$module = Import-Module -Name $modulePath -PassThru
2226

2327
if ($null -eq $module) {

Test/include/config.mock.ps1

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,40 @@
99
if(-not $MODULE_NAME){ throw "Missing MODULE_NAME varaible initialization. Check for module.helerp.ps1 file." }
1010

1111
$MOCK_CONFIG_PATH = "test_config_path"
12-
$CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-$($MODULE_NAME)GetConfigRootPath"
12+
$CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-ProjectHelperGetConfigRootPath"
1313

1414
function Mock_Config{
1515
param(
1616
[Parameter(Position=0)][string] $key = "config",
17-
[Parameter(Position=1)][object] $Config
17+
[Parameter(Position=1)][object] $Config,
18+
[Parameter(Position=2)][string] $ModuleName,
19+
[Parameter(Position=3)][string] $MockPath = $MOCK_CONFIG_PATH
1820
)
1921

2022
# Remove mock config path if exists
21-
if(Test-Path $MOCK_CONFIG_PATH){
22-
Remove-Item -Path $MOCK_CONFIG_PATH -ErrorAction SilentlyContinue -Recurse -Force
23+
if(Test-Path $MockPath){
24+
Remove-Item -Path $fullpath -ErrorAction SilentlyContinue -Recurse -Force
2325
}
2426

2527
# create mock config path
26-
New-Item -Path $MOCK_CONFIG_PATH -ItemType Directory -Force
28+
New-Item -Path $MockPath -ItemType Directory -Force
29+
30+
# make full and not relative path
31+
$fullpath = $MockPath | Resolve-Path
2732

2833
# if $config is not null save it to a file
2934
if($null -ne $Config){
30-
$configfile = Join-Path -Path $MOCK_CONFIG_PATH -ChildPath "$key.json"
35+
$configfile = Join-Path -Path $fullpath -ChildPath "$key.json"
3136
$Config | ConvertTo-Json -Depth 10 | Set-Content $configfile
3237
}
3338

39+
if([string]::IsNullOrWhiteSpace($ModuleName)){
40+
$moduleName = $MODULE_NAME
41+
}
42+
43+
$invokefunction = $CONFIG_INVOKE_GET_ROOT_PATH_CMD -replace "ProjectHelper", $moduleName
44+
3445
# Mock invoke call
35-
MockCallToString $CONFIG_INVOKE_GET_ROOT_PATH_CMD -OutString $MOCK_CONFIG_PATH
46+
MockCallToString $invokefunction -OutString $fullpath
3647

3748
}

include/MyWrite.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ function Enable-ModuleNameVerbose{
126126
$moduleDebugVarName = $MODULE_NAME + "_VERBOSE"
127127
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag)
128128
}
129-
Rename-Item -path Function:Enable-ModuleNameVerbose -NewName "Set-$($MODULE_NAME)Verbose"
130-
Export-ModuleMember -Function "Set-$($MODULE_NAME)Verbose"
129+
Copy-Item -path Function:Enable-ModuleNameVerbose -Destination Function:"Enable-$($MODULE_NAME)Verbose"
130+
Export-ModuleMember -Function "Enable-$($MODULE_NAME)Verbose"
131131

132132
function Disable-ModuleNameVerbose{
133133
param()
134134

135135
$moduleDebugVarName = $MODULE_NAME + "_VERBOSE"
136136
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null)
137137
}
138-
Rename-Item -path Function:Disable-ModuleNameVerbose -NewName "Clear-$($MODULE_NAME)Verbose"
139-
Export-ModuleMember -Function "Clear-$($MODULE_NAME)Verbose"
138+
Copy-Item -path Function:Disable-ModuleNameVerbose -Destination Function:"Disable-$($MODULE_NAME)Verbose"
139+
Export-ModuleMember -Function "Disable-$($MODULE_NAME)Verbose"
140140

141141
function Test-MyDebug {
142142
param(
@@ -173,7 +173,7 @@ function Enable-ModuleNameDebug{
173173
$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
174174
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag)
175175
}
176-
Rename-Item -path Function:Enable-ModuleNameDebug -NewName "Enable-$($MODULE_NAME)Debug"
176+
Copy-Item -path Function:Enable-ModuleNameDebug -Destination Function:"Enable-$($MODULE_NAME)Debug"
177177
Export-ModuleMember -Function "Enable-$($MODULE_NAME)Debug"
178178

179179
function Disable-ModuleNameDebug {
@@ -182,7 +182,7 @@ function Disable-ModuleNameDebug {
182182
$moduleDebugVarName = $MODULE_NAME + "_DEBUG"
183183
[System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null)
184184
}
185-
Rename-Item -path Function:Disable-ModuleNameDebug -NewName "Disable-$($MODULE_NAME)Debug"
185+
Copy-Item -path Function:Disable-ModuleNameDebug -Destination Function:"Disable-$($MODULE_NAME)Debug"
186186
Export-ModuleMember -Function "Disable-$($MODULE_NAME)Debug"
187187

188188
function Get-ObjetString {

include/config.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#
1414

1515
# MODULE_NAME
16-
$MODULE_NAME = ($PSScriptRoot | Split-Path -Parent | Get-ChildItem -Filter *.psd1 | Select-Object -First 1).BaseName
16+
$MODULE_NAME_PATH = ($PSScriptRoot | Split-Path -Parent | Get-ChildItem -Filter *.psd1 | Select-Object -First 1) | Split-Path -Parent
17+
$MODULE_NAME = $MODULE_NAME_PATH | Split-Path -LeafBase
18+
1719
if(-Not $MODULE_NAME){ throw "Module name not found. Please check the module structure." }
1820

1921
$CONFIG_ROOT = [System.Environment]::GetFolderPath('UserProfile') | Join-Path -ChildPath ".helpers" -AdditionalChildPath $MODULE_NAME, "config"
@@ -126,7 +128,7 @@ function Invoke-ModuleNameGetConfigRootPath {
126128
$function = "Invoke-ModuleNameGetConfigRootPath"
127129
$destFunction = $function -replace "ModuleName", $MODULE_NAME
128130
if( -not (Test-Path function:$destFunction )){
129-
Rename-Item -path Function:$function -NewName $destFunction
131+
Copy-Item -path Function:$function -Destination Function:$destFunction
130132
Export-ModuleMember -Function $destFunction
131133
}
132134

@@ -143,7 +145,7 @@ function Get-ModuleNameConfig{
143145
$function = "Get-ModuleNameConfig"
144146
$destFunction = $function -replace "ModuleName", $MODULE_NAME
145147
if( -not (Test-Path function:$destFunction )){
146-
Rename-Item -path Function:$function -NewName $destFunction
148+
Copy-Item -path Function:$function -Destination Function:$destFunction
147149
Export-ModuleMember -Function $destFunction
148150
}
149151

@@ -158,7 +160,7 @@ function Open-ModuleNameConfig{
158160
$function = "Open-ModuleNameConfig"
159161
$destFunction = $function -replace "ModuleName", $MODULE_NAME
160162
if( -not (Test-Path function:$destFunction )){
161-
Rename-Item -path Function:$function -NewName $destFunction
163+
Copy-Item -path Function:$function -Destination Function:$destFunction
162164
Export-ModuleMember -Function $destFunction
163165
}
164166

include/featureflag.ps1

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
#
33
# Feature Flags management module
44
#
5-
# Include design description
6-
# This module depends on Config Include
75
# This module will allow set Feature Flags to the module to quicker release
86
# features with less risk
97
#
8+
# Include design description
9+
# This module depends on Config Include
10+
# Config module will depend on invokeCommand.helper.ps1, MyWrite.ps1, config.ps1, module.helper.ps1
11+
#
12+
# As you se features keys they will be recorded on a config file.
13+
# Deprecate the FF to have it removed from the config file when the FF is released (aka set functionality to GA with now FF.
14+
# Use Clear-FeatureFlagsRegistered to remove deprecated FF from config
15+
1016

1117
$MODULE_NAME_PATH = ($PSScriptRoot | Split-Path -Parent | Get-ChildItem -Filter *.psd1 | Select-Object -First 1) | Split-Path -Parent
18+
$MODULE_NAME = $MODULE_NAME_PATH | Split-Path -LeafBase
1219

1320
function Get-FeatureFlags{
1421
[CmdletBinding()]
@@ -86,31 +93,46 @@ function Clear-FeatureFlag{
8693

8794
}
8895

96+
function Clear-FeatureFlagsRegistered{
97+
[cmdletbinding()]
98+
param()
99+
100+
$rffs = Get-ModuleNameRegisteredFeatureFlags
101+
$ffs = (Get-FeatureFlags).Clone()
102+
103+
$rffs.deprecated | ForEach-Object {
104+
$ffs.Remove($_)
105+
}
106+
107+
Save-FeatureFlags $ffs
108+
109+
}
110+
89111
######
90112

91-
# function Get-ModuleNameRegisteredFeatureFlags{
92-
# [cmdletbinding()]
93-
# param()
113+
function Get-ModuleNameRegisteredFeatureFlags{
114+
[cmdletbinding()]
115+
param()
94116

95-
# $ffPath = $MODULE_NAME_PATH | Join-Path -ChildPath "featureflags.json"
117+
$ffPath = $MODULE_NAME_PATH | Join-Path -ChildPath "featureflags.json"
96118

97-
# if(! ($ffPath | Test-Path)){
98-
# return
99-
# }
119+
if(! ($ffPath | Test-Path)){
120+
return
121+
}
100122

101-
# $Json = Get-Content $ffPath
123+
$Json = Get-Content $ffPath
102124

103-
# $ff = $Json | ConvertFrom-Json
125+
$ff = $Json | ConvertFrom-Json
104126

105-
# return $ff
127+
return $ff
106128

107-
# }
108-
# $function = "Get-ModuleNameRegisteredFeatureFlags"
109-
# $destFunction = $function -replace "ModuleName", $MODULE_NAME
110-
# if( -not (Test-Path function:$destFunction )){
111-
# Rename-Item -path Function:$function -NewName $destFunction
112-
# Export-ModuleMember -Function $destFunction
113-
# }
129+
}
130+
$function = "Get-ModuleNameRegisteredFeatureFlags"
131+
$destFunction = $function -replace "ModuleName", $MODULE_NAME
132+
if( -not (Test-Path function:$destFunction )){
133+
Copy-Item -path Function:$function -Destination Function:$destFunction
134+
Export-ModuleMember -Function $destFunction
135+
}
114136

115137
function Get-ModuleNameFeatureFlags{
116138
[cmdletbinding()]
@@ -142,3 +164,4 @@ if( -not (Test-Path function:$destFunction )){
142164
Rename-Item -path Function:$function -NewName $destFunction
143165
Export-ModuleMember -Function $destFunction
144166
}
167+

0 commit comments

Comments
 (0)