# cfe-init v1.0 — Create 1C configuration extension scaffold (CFE) # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills param( [Parameter(Mandatory)] [string]$Name, [string]$Synonym = $Name, [string]$NamePrefix, [string]$OutputDir = "src", [ValidateSet("Patch","Customization","AddOn")] [string]$Purpose = "Customization", [string]$Version, [string]$Vendor, [string]$CompatibilityMode = "Version8_3_24", [switch]$NoRole ) $ErrorActionPreference = "Stop" [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 # --- Default NamePrefix --- if (-not $NamePrefix) { $NamePrefix = "${Name}_" } # --- Resolve output dir --- if (-not [System.IO.Path]::IsPathRooted($OutputDir)) { $OutputDir = Join-Path (Get-Location).Path $OutputDir } # --- Check existing --- $cfgFile = Join-Path $OutputDir "Configuration.xml" if (Test-Path $cfgFile) { Write-Error "Configuration.xml already exists: $cfgFile" exit 1 } # --- Generate UUIDs --- $uuidCfg = [guid]::NewGuid().ToString() $uuidLang = [guid]::NewGuid().ToString() $uuidRole = [guid]::NewGuid().ToString() # 7 ContainedObject ObjectIds $co1 = [guid]::NewGuid().ToString() $co2 = [guid]::NewGuid().ToString() $co3 = [guid]::NewGuid().ToString() $co4 = [guid]::NewGuid().ToString() $co5 = [guid]::NewGuid().ToString() $co6 = [guid]::NewGuid().ToString() $co7 = [guid]::NewGuid().ToString() # --- Synonym XML --- $synonymXml = "" if ($Synonym) { $synonymXml = "`r`n`t`t`t`t`r`n`t`t`t`t`tru`r`n`t`t`t`t`t$([System.Security.SecurityElement]::Escape($Synonym))`r`n`t`t`t`t`r`n`t`t`t" } # --- Optional properties --- $vendorXml = if ($Vendor) { [System.Security.SecurityElement]::Escape($Vendor) } else { "" } $versionXml = if ($Version) { [System.Security.SecurityElement]::Escape($Version) } else { "" } # --- Role name --- $roleName = "${NamePrefix}ОсновнаяРоль" # --- DefaultRoles XML --- $defaultRolesXml = "" if (-not $NoRole) { $defaultRolesXml = "`r`n`t`t`t`tRole.$roleName`r`n`t`t`t" } # --- ChildObjects --- $childObjectsXml = "`r`n`t`t`tРусский" if (-not $NoRole) { $childObjectsXml += "`r`n`t`t`t$roleName" } $childObjectsXml += "`r`n`t`t" # --- Configuration.xml --- $cfgXml = @" 9cd510cd-abfc-11d4-9434-004095e12fc7 $co1 9fcd25a0-4822-11d4-9414-008048da11f9 $co2 e3687481-0a87-462c-a166-9f34594f9bba $co3 9de14907-ec23-4a07-96f0-85521cb6b53b $co4 51f2d5d8-ea4d-4064-8892-82951750031e $co5 e68182ea-4237-4383-967f-90c1e3370bc7 $co6 fb282519-d103-4dd3-bc12-cb271d631dfc $co7 Adopted $([System.Security.SecurityElement]::Escape($Name)) $synonymXml $Purpose true $([System.Security.SecurityElement]::Escape($NamePrefix)) $CompatibilityMode ManagedApplication PlatformApplication Russian $defaultRolesXml $vendorXml $versionXml Language.Русский TaxiEnableVersion8_2 $childObjectsXml "@ # --- Languages/Русский.xml (adopted format) --- $langXml = @" Adopted Русский 00000000-0000-0000-0000-000000000000 ru "@ # --- Role XML --- $roleXml = @" $([System.Security.SecurityElement]::Escape($roleName)) "@ # --- Create directories --- if (-not (Test-Path $OutputDir)) { New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null } $langDir = Join-Path $OutputDir "Languages" if (-not (Test-Path $langDir)) { New-Item -ItemType Directory -Path $langDir -Force | Out-Null } # --- Write files with UTF-8 BOM --- $enc = New-Object System.Text.UTF8Encoding($true) [System.IO.File]::WriteAllText($cfgFile, $cfgXml, $enc) $langFile = Join-Path $langDir "Русский.xml" [System.IO.File]::WriteAllText($langFile, $langXml, $enc) # --- Role --- if (-not $NoRole) { $roleDir = Join-Path $OutputDir "Roles" if (-not (Test-Path $roleDir)) { New-Item -ItemType Directory -Path $roleDir -Force | Out-Null } $roleFile = Join-Path $roleDir "$roleName.xml" [System.IO.File]::WriteAllText($roleFile, $roleXml, $enc) } # --- Output --- Write-Host "[OK] Создано расширение: $Name" Write-Host " Каталог: $OutputDir" Write-Host " Назначение: $Purpose" Write-Host " Префикс: $NamePrefix" Write-Host " Configuration.xml: $cfgFile" Write-Host " Languages: $langFile" if (-not $NoRole) { Write-Host " Role: $roleFile" }