@@ -46,7 +46,13 @@ function init {
4646 # Calculate Paths
4747 # The output path is just a temporary output and logging location
4848 $Script :OutputPath = Join-Path $Path output
49- $null = mkdir $OutputPath - Force
49+
50+ if (Test-Path $OutputPath - PathType Leaf) {
51+ throw " Cannot create folder for Configuration because there's a file in the way at '$OutputPath '"
52+ }
53+ if (! (Test-Path $OutputPath - PathType Container)) {
54+ $null = New-Item $OutputPath - Type Directory - Force
55+ }
5056
5157 # We expect the source for the module in a subdirectory called one of three things:
5258 $Script :SourcePath = " src" , " source" , ${ModuleName} | ForEach { Join-Path $Path $_ - Resolve - ErrorAction Ignore } | Select - First 1
@@ -148,7 +154,12 @@ function update {
148154 # force reinstall by cleaning the old ones
149155 remove-item $Path \packages\ - Recurse - Force
150156 }
151- $null = mkdir $Path \packages\ - Force
157+ if (Test-Path $Path \packages\ - PathType Leaf) {
158+ throw " Cannot create folder for Configuration because there's a file in the way at '$Path \packages\'"
159+ }
160+ if (! (Test-Path $Path \packages\ - PathType Container)) {
161+ $null = New-Item $Path \packages\ - Type Directory - Force
162+ }
152163
153164 # Remember, as of now, only nuget actually supports the -Destination flag
154165 foreach ($Package in ([xml ](gc .\packages.config)).packages.package) {
@@ -210,7 +221,13 @@ function build {
210221 $RootModule = " ${ModuleName} .psm1"
211222 }
212223 }
213- $null = mkdir $ReleasePath - Force
224+ if (Test-Path $ReleasePath - PathType Leaf) {
225+ throw " Cannot create folder for Configuration because there's a file in the way at '$ReleasePath '"
226+ }
227+ if (! (Test-Path $ReleasePath - PathType Container)) {
228+ $null = New-Item $ReleasePath - Type Directory - Force
229+ }
230+
214231 $ReleaseModule = Join-Path $ReleasePath ${RootModule}
215232 Trace-Message " Setting content for $ReleaseModule "
216233
@@ -244,7 +261,13 @@ function build {
244261 $ReadMe = Join-Path $Path Readme.md
245262 if (Test-Path $ReadMe - PathType Leaf) {
246263 $LanguagePath = Join-Path $ReleasePath $DefaultLanguage
247- $null = mkdir $LanguagePath - Force
264+ if (Test-Path $LanguagePath - PathType Leaf) {
265+ throw " Cannot create folder for Configuration because there's a file in the way at '$LanguagePath '"
266+ }
267+ if (! (Test-Path $LanguagePath - PathType Container)) {
268+ $null = New-Item $LanguagePath - Type Directory - Force
269+ }
270+
248271 $about_module = Join-Path $LanguagePath " about_${ModuleName} .help.txt"
249272 if (! (Test-Path $about_module )) {
250273 Trace-Message " Turn readme into about_module"
0 commit comments