param( [Parameter(Mandatory)] [string]$ProcessorName, [Parameter(Mandatory)] [string]$TemplateName, [Parameter(Mandatory)] [ValidateSet("HTML", "Text", "SpreadsheetDocument", "BinaryData")] [string]$TemplateType, [string]$Synonym = $TemplateName, [string]$SrcDir = "src" ) $ErrorActionPreference = "Stop" # --- Маппинг типов --- $typeMap = @{ "HTML" = @{ TemplateType = "HTMLDocument"; Ext = ".html" } "Text" = @{ TemplateType = "TextDocument"; Ext = ".txt" } "SpreadsheetDocument" = @{ TemplateType = "SpreadsheetDocument"; Ext = ".xml" } "BinaryData" = @{ TemplateType = "BinaryData"; Ext = ".bin" } } $tmpl = $typeMap[$TemplateType] # --- Проверки --- $rootXmlPath = Join-Path $SrcDir "$ProcessorName.xml" if (-not (Test-Path $rootXmlPath)) { Write-Error "Корневой файл обработки не найден: $rootXmlPath" exit 1 } $processorDir = Join-Path $SrcDir $ProcessorName $templatesDir = Join-Path $processorDir "Templates" $templateMetaPath = Join-Path $templatesDir "$TemplateName.xml" if (Test-Path $templateMetaPath) { Write-Error "Макет уже существует: $templateMetaPath" exit 1 } # --- Создание каталогов --- $templateExtDir = Join-Path (Join-Path $templatesDir $TemplateName) "Ext" New-Item -ItemType Directory -Path $templateExtDir -Force | Out-Null # --- Кодировка --- $encBom = New-Object System.Text.UTF8Encoding($true) # --- 1. Метаданные макета (Templates/.xml) --- $templateUuid = [guid]::NewGuid().ToString() $templateMetaXml = @" "@ [System.IO.File]::WriteAllText($templateMetaPath, $templateMetaXml, $encBom) # --- 2. Содержимое макета (Templates//Ext/Template.) --- $templateFilePath = Join-Path $templateExtDir "Template$($tmpl.Ext)" switch ($TemplateType) { "HTML" { $content = @" "@ [System.IO.File]::WriteAllText($templateFilePath, $content, $encBom) } "Text" { [System.IO.File]::WriteAllText($templateFilePath, "", $encBom) } "SpreadsheetDocument" { $content = @" "@ [System.IO.File]::WriteAllText($templateFilePath, $content, $encBom) } "BinaryData" { [System.IO.File]::WriteAllBytes($templateFilePath, @()) } } # --- 3. Модификация корневого XML --- $rootXmlFull = Resolve-Path $rootXmlPath $xmlDoc = New-Object System.Xml.XmlDocument $xmlDoc.PreserveWhitespace = $true $xmlDoc.Load($rootXmlFull.Path) $nsMgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable) $nsMgr.AddNamespace("md", "http://v8.1c.ru/8.3/MDClasses") $childObjects = $xmlDoc.SelectSingleNode("//md:ChildObjects", $nsMgr) if (-not $childObjects) { Write-Error "Не найден элемент ChildObjects в $rootXmlPath" exit 1 } # Добавить