Files
cc-1c-skills/.claude/skills/epf-remove-template/scripts/remove-template.ps1
T
Nick Shirokov 43333f1481 Initial commit: EPF skills for Claude Code
7 skills for working with 1C external data processor XML sources:
- epf-init: scaffold a new processor (root XML + ObjectModule.bsl)
- epf-add-form: add a managed form with BSL module
- epf-add-template: add a template (HTML/Text/SpreadsheetDocument/BinaryData)
- epf-remove-form: remove a form and update root XML
- epf-remove-template: remove a template and update root XML
- epf-build: build EPF from XML (documentation only)
- epf-dump: dump EPF to XML (documentation only)

Includes XML format spec and build/dump command reference.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 19:05:27 +03:00

79 lines
2.4 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
param(
[Parameter(Mandatory)]
[string]$ProcessorName,
[Parameter(Mandatory)]
[string]$TemplateName,
[string]$SrcDir = "src"
)
$ErrorActionPreference = "Stop"
# --- Проверки ---
$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"
$templateDir = Join-Path $templatesDir $TemplateName
if (-not (Test-Path $templateMetaPath)) {
Write-Error "Метаданные макета не найдены: $templateMetaPath"
exit 1
}
# --- Удаление файлов ---
if (Test-Path $templateDir) {
Remove-Item -Path $templateDir -Recurse -Force
Write-Host "[OK] Удалён каталог: $templateDir"
}
Remove-Item -Path $templateMetaPath -Force
Write-Host "[OK] Удалён файл: $templateMetaPath"
# --- Модификация корневого 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")
# Удалить <Template>TemplateName</Template> из ChildObjects
$templateNodes = $xmlDoc.SelectNodes("//md:ChildObjects/md:Template", $nsMgr)
foreach ($node in $templateNodes) {
if ($node.InnerText -eq $TemplateName) {
$parent = $node.ParentNode
# Удалить предшествующий whitespace
$prev = $node.PreviousSibling
if ($prev -and $prev.NodeType -eq [System.Xml.XmlNodeType]::Whitespace) {
$parent.RemoveChild($prev) | Out-Null
}
$parent.RemoveChild($node) | Out-Null
break
}
}
# Сохранить с BOM
$encBom = New-Object System.Text.UTF8Encoding($true)
$settings = New-Object System.Xml.XmlWriterSettings
$settings.Encoding = $encBom
$settings.Indent = $false
$stream = New-Object System.IO.FileStream($rootXmlFull.Path, [System.IO.FileMode]::Create)
$writer = [System.Xml.XmlWriter]::Create($stream, $settings)
$xmlDoc.Save($writer)
$writer.Close()
$stream.Close()
Write-Host "[OK] Макет $TemplateName удалён из $rootXmlPath"