PowerShell: simple folder structure for an html project

I liked the folder template that Deborah Kurata outlined for an html project in her PluralSight course on LOB applications in  Angular.

As I might want to do that a number of times, it feels like creating an identical folder structure for each application we write is a good candidate for a PowerShell cmdlet. For now, let’s just get the raw commands. Below, $htmlDevRoot would normally be constant on any one machine, and therefore would be a default parameter, $appDir is the name of the folder immediately below that, and which is not defaulted, and everything else follows her pattern:

# user defined…
$htmlDevRoot = “d:\build\HtmlDevDir” #defaulted once configuration is done for the current machine, assumes that $htmlDevRoot exists by the time PS gets to it: fail and exit if path not found
$appDir = “BikeMaintenance” # parameter – different for each new application
# don’t edit below here..
$fullAppDirPathRoot = “$htmlDevRoot\$appDir”
New-Item -Path $fullAppDirPathRoot -ItemType Dir
New-Item -Path $fullAppDirPathRoot\index.html -ItemType File
New-Item -Path “$fullAppDirPathRoot\app” -ItemType Dir
New-Item -Path “$fullAppDirPathRoot\app\feature1” -ItemType Dir
New-Item -Path “$fullAppDirPathRoot\app\feature2” -ItemType Dir
New-Item -Path “$fullAppDirPathRoot\common” -ItemType Dir
New-Item -Path “$fullAppDirPathRoot\common\services” -ItemType Dir
New-Item -Path “$fullAppDirPathRoot\css” -ItemType Dir
New-Item -Path “$fullAppDirPathRoot\fonts” -ItemType Dir
New-Item -Path “$fullAppDirPathRoot\images” -ItemType Dir
New-Item -Path “$fullAppDirPathRoot\js” -ItemType Dir
gci $fullAppDirPathRoot -Recurse

Since the original edit, I’ve added a line to create an empty index.html. Why not.

index01

HtmlPs02

That can be reduced to this, comments removed this time:

$htmlDevRoot = "d:\build\HtmlDevDir"
$appDir = "BikeMaintenance"
$fullAppDirPathRoot = "$htmlDevRoot\$appDir"
New-Item -Path $fullAppDirPathRoot -ItemType Dir
$subfolders = @("app","app\feature1", "app\feature2", "common", "common\services","css","fonts","images","js")
$subfolders | % {New-Item -Path "$fullAppDirPathRoot\$_" -ItemType Dir}

HtmlPs03

HtmlPs04