# skd-decompile v0.90 — Decompile 1C DCS Template.xml to JSON DSL (draft) # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills param( [Parameter(Mandatory)] [Alias('Path')] [string]$TemplatePath, [string]$OutputPath ) $ErrorActionPreference = "Stop" [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 # --- 0. Resolve and validate input --- if (-not (Test-Path $TemplatePath)) { Write-Error "Template not found: $TemplatePath" exit 1 } $TemplatePath = (Resolve-Path $TemplatePath).Path $xmlDoc = New-Object System.Xml.XmlDocument $xmlDoc.PreserveWhitespace = $false $xmlDoc.Load($TemplatePath) $root = $xmlDoc.DocumentElement # Ring 3: not a DataCompositionSchema → fail-fast if ($root.LocalName -ne 'DataCompositionSchema') { [Console]::Error.WriteLine("skd-decompile: корневой элемент <$($root.LocalName)> не — это не схема СКД (возможно, табличный документ — используй /mxl-decompile).") exit 2 } # --- 1. Namespace manager --- $NS_SCHEMA = "http://v8.1c.ru/8.1/data-composition-system/schema" $NS_COM = "http://v8.1c.ru/8.1/data-composition-system/common" $NS_COR = "http://v8.1c.ru/8.1/data-composition-system/core" $NS_SET = "http://v8.1c.ru/8.1/data-composition-system/settings" $NS_AT = "http://v8.1c.ru/8.1/data-composition-system/area-template" $NS_V8 = "http://v8.1c.ru/8.1/data/core" $NS_V8UI = "http://v8.1c.ru/8.1/data/ui" $NS_XS = "http://www.w3.org/2001/XMLSchema" $NS_XSI = "http://www.w3.org/2001/XMLSchema-instance" $NS_CFG = "http://v8.1c.ru/8.1/data/enterprise/current-config" $ns = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable) $ns.AddNamespace("r", $NS_SCHEMA) $ns.AddNamespace("dcscom", $NS_COM) $ns.AddNamespace("dcscor", $NS_COR) $ns.AddNamespace("dcsset", $NS_SET) $ns.AddNamespace("dcsat", $NS_AT) $ns.AddNamespace("v8", $NS_V8) $ns.AddNamespace("v8ui", $NS_V8UI) $ns.AddNamespace("xs", $NS_XS) $ns.AddNamespace("xsi", $NS_XSI) # --- 1b. Ring 3 scan: bail out on unsupported constructs --- function Fail-Ring3 { param([string]$kind, [string]$loc) [Console]::Error.WriteLine("skd-decompile: декомпиляция не поддерживает $kind (path: $loc)") [Console]::Error.WriteLine("Для точечной работы с этим отчётом используй /skd-edit.") exit 3 } # Picture cells in templates foreach ($el in $xmlDoc.SelectNodes("//*[local-name()='item']")) { $xsi = $el.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance") if ($xsi -match 'Picture$' -and $el.NamespaceURI -eq "http://v8.1c.ru/8.1/data-composition-system/area-template") { Fail-Ring3 -kind "Picture cell в шаблоне" -loc "template/.../item[@xsi:type=Picture]" } } # ValueStorage parameter type foreach ($vt in $xmlDoc.SelectNodes("//*[local-name()='Type']")) { $inner = $vt.InnerText if ($inner -match '^v8:ValueStorage$|:ValueStorage$') { Fail-Ring3 -kind "параметр типа ХранилищеЗначения" -loc "valueType[v8:Type=ValueStorage]" } } # templateCondition (variant templates) — top-level