mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-09-03 08:40:52 +03:00
feat(skd): support @file references for query text in skd-compile and skd-edit
Allows using "@path/to/file.sql" instead of inline query text. Path resolved relative to definition file, then CWD; absolute paths supported. Closes #9 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
ffa3189442
commit
05fc7eba27
@@ -1,4 +1,4 @@
|
||||
# skd-edit v1.1 — Atomic 1C DCS editor
|
||||
# skd-edit v1.2 — Atomic 1C DCS editor
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -47,6 +47,29 @@ function Esc-Xml {
|
||||
return $s.Replace('&','&').Replace('<','<').Replace('>','>').Replace('"','"')
|
||||
}
|
||||
|
||||
function Resolve-QueryValue {
|
||||
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)
|
||||
)
|
||||
}
|
||||
foreach ($c in $candidates) {
|
||||
if (Test-Path $c) {
|
||||
return (Get-Content -Raw -Encoding UTF8 $c).TrimEnd()
|
||||
}
|
||||
}
|
||||
Write-Error "Query file not found: $filePath (searched: $($candidates -join ', '))"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$script:queryBaseDir = [System.IO.Path]::GetDirectoryName($resolvedPath)
|
||||
|
||||
# --- 2. Type system (copied from skd-compile) ---
|
||||
|
||||
$script:typeSynonyms = New-Object System.Collections.Hashtable
|
||||
@@ -1712,7 +1735,7 @@ switch ($Operation) {
|
||||
}
|
||||
|
||||
# InnerText setter handles XML escaping automatically
|
||||
$queryEl.InnerText = $Value
|
||||
$queryEl.InnerText = Resolve-QueryValue $Value $script:queryBaseDir
|
||||
|
||||
Write-Host "[OK] Query replaced in dataset `"$dsName`""
|
||||
}
|
||||
@@ -1813,6 +1836,7 @@ switch ($Operation) {
|
||||
$childIndent = Get-ChildIndent $root
|
||||
|
||||
$parsed = Parse-DataSetShorthand $Value
|
||||
$parsed.query = Resolve-QueryValue $parsed.query $script:queryBaseDir
|
||||
|
||||
# Auto-name if empty
|
||||
if (-not $parsed.name) {
|
||||
|
||||
Reference in New Issue
Block a user