mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-09-20 09:15:52 +03:00
refactor(skd-compile,skd-edit,form-compile,role-*): одно правило поиска @файла
Чтение текста из файла жило тремя копиями под именем Resolve-QueryValue и вне реестра гарда, а role-* завели четвёртое правило — только от рабочего каталога. Теперь функция одна на пять навыков: Resolve-TextFromFile / resolve_text_from_file, заведена семья в check-inline-drift, эталон — skd-edit. Правило поиска общее: абсолютный путь как есть, относительный — рядом с DSL (у edit-навыков — рядом с редактируемым объектом), затем в текущем каталоге, не нашли — ошибка со списком проверенных мест. Имя без "query": в ролях из файла приходит условие RLS, а не запрос. Текст ошибки приведён к языку остальных сообщений. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FGkXwoXTuafcu1SXMsauFq
This commit is contained in:
co-authored by
Claude Opus 5
parent
121c9c8ad3
commit
d425833709
@@ -1,4 +1,4 @@
|
||||
# role-compile v1.40 — Compile 1C role from JSON
|
||||
# role-compile v1.41 — Compile 1C role from JSON
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
[CmdletBinding(PositionalBinding=$false)]
|
||||
param(
|
||||
@@ -1073,17 +1073,27 @@ function Validate-RightName {
|
||||
}
|
||||
|
||||
# "@путь" в значении условия — текст берётся из файла: условия RLS типовых занимают десятки
|
||||
# строк с кавычками, и внутри JSON-строки это источник ошибок экранирования. Путь относительный —
|
||||
# от текущего каталога, как в role-edit.
|
||||
function Resolve-TextValue([string]$text) {
|
||||
if (-not $text -or -not $text.StartsWith("@")) { return $text }
|
||||
$valueFile = $text.Substring(1).Trim()
|
||||
if (-not [System.IO.Path]::IsPathRooted($valueFile)) { $valueFile = Join-Path (Get-Location).Path $valueFile }
|
||||
if (-not (Test-Path -LiteralPath $valueFile -PathType Leaf)) {
|
||||
Add-ValidationError "Файл значения не найден: $valueFile"
|
||||
return $text
|
||||
# строк с кавычками, и внутри JSON-строки это источник ошибок экранирования. Относительный
|
||||
# путь ищется рядом с JSON-описанием роли, затем в текущем каталоге.
|
||||
function Resolve-TextFromFile {
|
||||
param([string]$val, [string]$baseDir)
|
||||
if (-not $val.StartsWith("@")) { return $val }
|
||||
$filePath = $val.Substring(1)
|
||||
if ([System.IO.Path]::IsPathRooted($filePath)) {
|
||||
$candidates = @($filePath)
|
||||
} else {
|
||||
$candidates = @(
|
||||
(Join-Path $baseDir $filePath),
|
||||
(Join-Path (Get-Location).Path $filePath)
|
||||
)
|
||||
}
|
||||
return [System.IO.File]::ReadAllText($valueFile).Trim()
|
||||
foreach ($c in $candidates) {
|
||||
if (Test-Path $c) {
|
||||
return (Get-Content -Raw -Encoding UTF8 $c).TrimEnd()
|
||||
}
|
||||
}
|
||||
Write-Error "Файл значения не найден: $filePath (искали: $($candidates -join ', '))"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# --- 5a. Service roots: expand to leaves ---
|
||||
@@ -1304,7 +1314,7 @@ function Parse-ObjectEntry {
|
||||
foreach ($p in $entry.rls.PSObject.Properties) {
|
||||
$rlsRight = Translate-RightName $p.Name
|
||||
if ($rightsMap.Contains($rlsRight)) {
|
||||
$rightsMap[$rlsRight].Condition = Resolve-TextValue "$($p.Value)"
|
||||
$rightsMap[$rlsRight].Condition = Resolve-TextFromFile "$($p.Value)" $script:textBaseDir
|
||||
} else {
|
||||
Write-Warning "${objName}: RLS for '$rlsRight' but this right is not in the rights list"
|
||||
}
|
||||
@@ -1332,6 +1342,9 @@ if (-not $def.objects -and $def.rights) { $def | Add-Member -NotePropertyName ob
|
||||
# Путь нужен уже здесь: раскрытие сервисного корня читает метаданные сервиса рядом с ролью.
|
||||
$resolvedOutputDir = if ([System.IO.Path]::IsPathRooted($OutputDir)) { $OutputDir } else { Join-Path (Get-Location) $OutputDir }
|
||||
|
||||
# Относительный путь @файла ищем сначала рядом с JSON-описанием роли.
|
||||
$script:textBaseDir = [System.IO.Path]::GetDirectoryName((Resolve-Path $JsonPath).Path)
|
||||
|
||||
$parsedObjects = @()
|
||||
$seenObjectNames = @{}
|
||||
if ($def.objects) {
|
||||
@@ -1492,7 +1505,7 @@ if ($def.templates) {
|
||||
foreach ($tpl in $def.templates) {
|
||||
X "`t<restrictionTemplate>"
|
||||
X "`t`t<name>$(Esc-XmlText "$($tpl.name)")</name>"
|
||||
X "`t`t<condition>$(Esc-XmlText (Resolve-TextValue "$($tpl.condition)"))</condition>"
|
||||
X "`t`t<condition>$(Esc-XmlText (Resolve-TextFromFile "$($tpl.condition)" $script:textBaseDir))</condition>"
|
||||
X "`t</restrictionTemplate>"
|
||||
$templateCount++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user