-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathPlaster.psm1
More file actions
191 lines (169 loc) · 11.2 KB
/
Copy pathPlaster.psm1
File metadata and controls
191 lines (169 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# spell-checker:ignore Multichoice Assigments
# Import localized data
data LocalizedData {
# culture="en-US"
ConvertFrom-StringData @'
DestPath_F1=Destination path: {0}
ErrorFailedToLoadStoreFile_F1=Failed to load the default value store file: '{0}'.
ErrorProcessingDynamicParams_F1=Failed to create dynamic parameters from the template's manifest file. Template-based dynamic parameters will not be available until the error is corrected. The error was: {0}
ErrorTemplatePathIsInvalid_F1=The TemplatePath parameter value must refer to an existing directory. The specified path '{0}' does not.
ErrorUnencryptingSecureString_F1=Failed to unencrypt value for parameter '{0}'.
ErrorPathDoesNotExist_F1=Cannot find path '{0}' because it does not exist.
ErrorPathMustBeRelativePath_F2=The path '{0}' specified in the {1} directive in the template manifest cannot be an absolute path. Change the path to a relative path.
ErrorPathMustBeUnderDestPath_F2=The path '{0}' must be under the specified DestinationPath '{1}'.
ExpressionInvalid_F2=The expression '{0}' is invalid or threw an exception. Error: {1}
ExpressionNonTermErrors_F2=The expression '{0}' generated error output - {1}
ExpressionExecError_F2=PowerShell expression failed execution. Location: {0}. Error: {1}
ExpressionErrorLocationFile_F2=<{0}> attribute '{1}'
ExpressionErrorLocationModify_F1=<modify> attribute '{0}'
ExpressionErrorLocationNewModManifest_F1=<newModuleManifest> attribute '{0}'
ExpressionErrorLocationParameter_F2=<parameter> name='{0}', attribute '{1}'
ExpressionErrorLocationRequireModule_F2=<requireModule> name='{0}', attribute '{1}'
ExpressionInvalidCondition_F3=The Plaster manifest condition '{0}' failed. Location: {1}. Error: {2}
InterpolationError_F3=The Plaster manifest attribute value '{0}' failed string interpolation. Location: {1}. Error: {2}
FileConflict=Plaster file conflict
ManifestFileMissing_F1=The Plaster manifest file '{0}' was not found.
ManifestMissingDocElement_F2=The Plaster manifest file '{0}' is missing the document element. It should be specified as <plasterManifest xmlns="{1}"></plasterManifest>.
ManifestMissingDocTargetNamespace_F2=The Plaster manifest file '{0}' is missing or has an invalid target namespace on the document element. It should be specified as <plasterManifest xmlns="{1}"></plasterManifest>.
ManifestPlasterVersionNotSupported_F2=The template file '{0}' specifies a plasterVersion of {1} which is greater than the installed version of Plaster. Update the Plaster module and try again.
ManifestSchemaInvalidAttrValue_F5=Invalid '{0}' attribute value '{1}' on '{2}' element in file '{3}'. Error: {4}
ManifestSchemaInvalidCondition_F3=Invalid condition '{0}' in file '{1}'. Error: {2}
ManifestSchemaInvalidChoiceDefault_F3=Invalid default attribute value '{0}' for parameter '{1}' in file '{2}'. The default value must specify a zero-based integer index that corresponds to the default choice.
ManifestSchemaInvalidMultichoiceDefault_F3=Invalid default attribute value '{0}' for parameter '{1}' in file '{2}'. The default value must specify one or more zero-based integer indexes in a comma separated list that correspond to the default choices.
ManifestSchemaInvalidRequireModuleAttrs_F2=The requireModule attribute 'requiredVersion' for module '{0}' in file '{1}' cannot be used together with either the 'minimumVersion' or 'maximumVersion' attribute.
ManifestSchemaValidationError_F2=Plaster manifest schema error in file '{0}'. Error: {1}
ManifestSchemaVersionNotSupported_F2=The template's manifest schema version ({0}) in file '{1}' requires a newer version of Plaster. Update the Plaster module and try again.
ManifestErrorReading_F1=Error reading Plaster manifest: {0}
ManifestNotValid_F1=The Plaster manifest '{0}' is not valid.
ManifestNotValidVerbose_F1=The Plaster manifest '{0}' is not valid. Specify -Verbose to see the specific schema errors.
ManifestNotWellFormedXml_F2=The Plaster manifest '{0}' is not a well-formed XML file. {1}
ManifestWrongFilename_F1=The Plaster manifest filename '{0}' is not valid. The value of the Path argument must refer to a file named 'plasterManifest.xml', 'plasterManifest.json', or a culture-specific variant (e.g., 'plasterManifest_en-US.xml'). Change the Plaster manifest filename and then try again.
MissingParameterPrompt_F1=<Missing prompt value for parameter '{0}'>
NewModManifest_CreatingDir_F1=Creating destination directory for module manifest: {0}
OpConflict=Conflict
OpCreate=Create
OpForce=Force
OpIdentical=Identical
OpMissing=Missing
OpModify=Modify
OpUpdate=Update
OpVerify=Verify
OverwriteFile_F1=Overwrite {0}
ParameterTypeChoiceMultipleDefault_F1=Parameter name {0} is of type='choice' and can only have one default value.
RequireModuleVerified_F2=The required module {0}{1} is already installed.
RequireModuleMissing_F2=The required module {0}{1} was not found.
RequireModuleMinVersion_F1=minimum version: {0}
RequireModuleMaxVersion_F1=maximum version: {0}
RequireModuleRequiredVersion_F1=required version: {0}
ShouldCreateNewPlasterManifest=Create Plaster manifest
ShouldProcessCreateDir=Create directory
ShouldProcessExpandTemplate=Expand template file
ShouldProcessNewModuleManifest=Create new module manifest
TempFileOperation_F1={0} into temp file before copying to destination
TempFileTarget_F1=temp file for '{0}'
TestPlasterNoXmlSchemaValidationWarning=The version of .NET Core that PowerShell is running on does not support XML schema-based validation. Test-PlasterManifest will operate in "limited validation" mode primarily verifying the specified manifest file is well-formed XML. For full, XML schema-based validation, run this command on Windows PowerShell.
UnrecognizedParametersElement_F1=Unrecognized manifest parameters child element: {0}.
UnrecognizedParameterType_F2=Unrecognized parameter type '{0}' on parameter name '{1}'.
UnrecognizedContentElement_F1=Unrecognized manifest content child element: {0}.
'@
}
# Import localized data with improved error handling
try {
Microsoft.PowerShell.Utility\Import-LocalizedData LocalizedData -FileName 'Plaster.Resources.psd1' -ErrorAction SilentlyContinue
} catch {
Write-Warning "Failed to import localized data: $_"
}
# Module variables with proper scoping and type safety
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$PlasterVersion = (Import-PowerShellDataFile -Path (Join-Path $PSScriptRoot 'Plaster.psd1')).ModuleVersion
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$JsonSchemaPath = Join-Path $PSScriptRoot "Schema\plaster-manifest-v2.json"
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$LatestSupportedSchemaVersion = [System.Version]'1.2'
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$TargetNamespace = "http://www.microsoft.com/schemas/PowerShell/Plaster/v1"
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$DefaultEncoding = 'UTF8-NoBOM'
# Cross-platform parameter store path configuration
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$ParameterDefaultValueStoreRootPath = switch ($true) {
# Windows (both Desktop and Core)
(($PSVersionTable.PSVersion.Major -le 5) -or ($PSVersionTable.PSEdition -eq 'Desktop') -or ($IsWindows -eq $true)) {
if ($env:LOCALAPPDATA) {
"$env:LOCALAPPDATA\Plaster"
} else {
"$env:USERPROFILE\AppData\Local\Plaster"
}
}
# Linux - Follow XDG Base Directory Specification
($IsLinux -eq $true) {
if ($env:XDG_DATA_HOME) {
"$env:XDG_DATA_HOME/plaster"
} else {
"$Home/.local/share/plaster"
}
}
# macOS and other Unix-like systems
default {
"$Home/.plaster"
}
}
# Enhanced platform detection with fallback
if (-not (Get-Variable -Name 'IsWindows' -ErrorAction SilentlyContinue)) {
$script:IsWindows = $PSVersionTable.PSVersion.Major -le 5 -or $PSVersionTable.PSEdition -eq 'Desktop'
}
if (-not (Get-Variable -Name 'IsLinux' -ErrorAction SilentlyContinue)) {
$script:IsLinux = $false
}
if (-not (Get-Variable -Name 'IsMacOS' -ErrorAction SilentlyContinue)) {
$script:IsMacOS = $false
}
# .NET Core compatibility check for XML Schema validation
$script:XmlSchemaValidationSupported = $null -ne ('System.Xml.Schema.XmlSchemaSet' -as [type])
if (-not $script:XmlSchemaValidationSupported) {
Write-Verbose "XML Schema validation is not supported on this platform. Limited validation will be performed."
}
# Module logging configuration
$script:LogLevel = if ($env:PLASTER_LOG_LEVEL) { $env:PLASTER_LOG_LEVEL } else { 'Information' }
# Dot-source functions when running from source (not compiled build)
# The build system (PowerShellBuild) compiles all functions into this PSM1.
# When running from source, we need to dot-source them from Private/ and Public/.
$privatePath = Join-Path $PSScriptRoot 'Private'
$publicPath = Join-Path $PSScriptRoot 'Public'
if (Test-Path $privatePath) {
foreach ($file in (Get-ChildItem -Path $privatePath -Filter '*.ps1' -Recurse)) {
. $file.FullName
}
}
if (Test-Path $publicPath) {
foreach ($file in (Get-ChildItem -Path $publicPath -Filter '*.ps1' -Recurse)) {
. $file.FullName
}
}
# Global variables and constants for Plaster 2.0
# Enhanced $TargetNamespace definition with proper scoping
if (-not (Get-Variable -Name 'TargetNamespace' -Scope Script -ErrorAction SilentlyContinue)) {
Set-Variable -Name 'TargetNamespace' -Value 'http://www.microsoft.com/schemas/PowerShell/Plaster/v1' -Scope Script -Option ReadOnly
}
# Enhanced $DefaultEncoding definition
if (-not (Get-Variable -Name 'DefaultEncoding' -Scope Script -ErrorAction SilentlyContinue)) {
Set-Variable -Name 'DefaultEncoding' -Value 'UTF8-NoBOM' -Scope Script -Option ReadOnly
}
# JSON Schema version for new manifests
if (-not (Get-Variable -Name 'JsonSchemaVersion' -Scope Script -ErrorAction SilentlyContinue)) {
Set-Variable -Name 'JsonSchemaVersion' -Value '2.0' -Scope Script -Option ReadOnly
}
# Export the variables that need to be available globally
Export-ModuleMember -Variable @('TargetNamespace', 'DefaultEncoding', 'JsonSchemaVersion')
# Module cleanup on removal
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
Write-PlasterLog -Level Verbose -Message "Plaster module is being removed"
# Clean up any module-scoped variables or resources
Remove-Variable -Name 'PlasterVersion' -Scope Script -ErrorAction SilentlyContinue
Remove-Variable -Name 'LatestSupportedSchemaVersion' -Scope Script -ErrorAction SilentlyContinue
Remove-Variable -Name 'TargetNamespace' -Scope Script -ErrorAction SilentlyContinue
Remove-Variable -Name 'DefaultEncoding' -Scope Script -ErrorAction SilentlyContinue
Remove-Variable -Name 'ParameterDefaultValueStoreRootPath' -Scope Script -ErrorAction SilentlyContinue
}
# Module initialization complete
Write-PlasterLog -Level Verbose -Message "Plaster v$PlasterVersion module loaded successfully (PowerShell $($PSVersionTable.PSVersion))"