param( [string]$OutputDirectory = '' ) $ErrorActionPreference = 'Stop' $scriptRoot = $PSScriptRoot $root = (Resolve-Path (Join-Path $scriptRoot '..\..')).Path $outputDir = if ($OutputDirectory) { (Resolve-Path $OutputDirectory).Path } else { Join-Path $root 'doc' } $technicalBuilder = Join-Path $root 'work\system-technical-document\build-standard-technical-document.ps1' $tempDir = Join-Path $scriptRoot 'source-build' $technicalBase = '大连元利流体技术有限公司MES系统标准技术文档_V1.0_2026-07-24' $designBase = '大连元利流体技术有限公司MES系统标准设计文档_V1.0_2026-07-24' $sourceDocx = Join-Path $tempDir ($technicalBase + '.docx') $targetDocx = Join-Path $outputDir ($designBase + '.docx') $targetPdf = Join-Path $outputDir ($designBase + '.pdf') New-Item -ItemType Directory -Force -Path $outputDir, $tempDir | Out-Null # 在源构建脚本中替换文档基线名称,再由原有生成器一次性生成 DOCX/PDF。 # 这样可以保留封面、页眉、修订记录和文档属性的一致性。 $sourceScript = Join-Path $tempDir 'build-design-source.ps1' $sourceText = [IO.File]::ReadAllText($technicalBuilder, [Text.Encoding]::UTF8) $replacements = @( @('大连元利流体技术有限公司MES系统标准技术文档_V1.0_2026-07-24', '大连元利流体技术有限公司MES系统标准设计文档_V1.0_2026-07-24'), @('MES 系统标准技术文档', 'MES 系统标准设计文档'), @('MES系统标准技术文档', 'MES系统标准设计文档'), @('System Technical Specification', 'System Design Specification'), @('首次形成系统级标准技术文档', '首次形成系统级标准设计文档'), @('本文档定义 MES 系统当前技术实现基线', '本文档定义 MES 系统当前系统设计基线') ) foreach ($pair in $replacements) { $sourceText = $sourceText.Replace($pair[0], $pair[1]) } $utf8Bom = New-Object Text.UTF8Encoding($true) [IO.File]::WriteAllText($sourceScript, $sourceText, $utf8Bom) Copy-Item -LiteralPath (Join-Path $root 'work\system-technical-document\assets') -Destination (Join-Path $tempDir 'assets') -Recurse -Force & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $sourceScript -OutputDirectory $tempDir $generatedDocx = Join-Path $tempDir ($designBase + '.docx') $generatedPdf = Join-Path $tempDir ($designBase + '.pdf') if (-not (Test-Path -LiteralPath $generatedDocx)) { throw "未找到标准设计文档 DOCX:$generatedDocx" } if (-not (Test-Path -LiteralPath $generatedPdf)) { throw "未找到标准设计文档 PDF:$generatedPdf" } Copy-Item -LiteralPath $generatedDocx -Destination $targetDocx -Force Copy-Item -LiteralPath $generatedPdf -Destination $targetPdf -Force Write-Output "已生成:$targetDocx" Write-Output "已生成:$targetPdf"