# Pure OOXML fixture generation: does not start Word, connect to PlotDirector or alter existing files. param([Parameter(Mandatory=$true)][string]$OutputDirectory) $ErrorActionPreference='Stop' Add-Type -AssemblyName System.IO.Compression.FileSystem New-Item -ItemType Directory -Force -Path $OutputDirectory | Out-Null function New-Fixture([string]$Name,[int]$Words,[int]$WordsPerParagraph,[int]$Book) { $target=Join-Path $OutputDirectory "$Name.docx" if(Test-Path $target){throw "Refusing to overwrite $target"} $guid=[Guid]::NewGuid().ToString('D') $builder=New-Object System.Text.StringBuilder [void]$builder.Append('') $remaining=$Words;$chapter=0;$scene=0;$paragraph=0 while($remaining -gt 0){ if($paragraph % 100 -eq 0){ $chapter++ [void]$builder.Append("Chapter $chapter") } if($paragraph % 20 -eq 0){ $scene++ [void]$builder.Append("Scene $scene") } $take=[Math]::Min($WordsPerParagraph,$remaining) $text=(1..$take | ForEach-Object {'word'}) -join ' ' [void]$builder.Append("$text") $remaining-=$take;$paragraph++ } [void]$builder.Append('') $entries=@{ '[Content_Types].xml'='' '_rels/.rels'='' 'word/_rels/document.xml.rels'='' 'word/styles.xml'='' 'word/document.xml'=$builder.ToString() 'docProps/custom.xml'="$guid1$Book" } $stream=[System.IO.File]::Open($target,[System.IO.FileMode]::CreateNew) $zip=New-Object System.IO.Compression.ZipArchive($stream,[System.IO.Compression.ZipArchiveMode]::Create) try{foreach($item in $entries.GetEnumerator()){$entry=$zip.CreateEntry($item.Key);$writer=New-Object System.IO.StreamWriter($entry.Open(),(New-Object System.Text.UTF8Encoding($false)));try{$writer.Write($item.Value)}finally{$writer.Dispose()}}}finally{$zip.Dispose();$stream.Dispose()} [pscustomobject]@{File=$target;ProseWords=$Words;Paragraphs=$paragraph;Book=$Book;ManuscriptGuid=$guid} } @( New-Fixture 'Discovery-190k' 190000 60 101 New-Fixture 'Reckoning-250k' 250000 60 102 New-Fixture 'Redemption-many-short' 250000 10 103 New-Fixture 'Long-paragraph-250k' 250000 250000 104 ) | ConvertTo-Json | Set-Content (Join-Path $OutputDirectory 'fixtures.json')