-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-UDProject.ps1
68 lines (56 loc) · 1.79 KB
/
New-UDProject.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<#
.SYNOPSIS
Creates the framework for a new dashboard project
.DESCRIPTION
Creates a module for the project that imports all *.ps1 located in the /src folder.
.EXAMPLE
PS C:\> New-UDProject -ProjectName myProject
Creates a new project called myProject. The dashboard will use this for it's title,
but this is configurable in dbconfig.json
.INPUTS
Inputs (if any)
.OUTPUTS
PSCustomObject of the dashboard module name and location
.NOTES
General notes
#>
[cmdletbinding()]
param(
[Parameter(Mandatory)]
[string]$ProjectName
)
Begin {
$ModuleFileContents = @'
$Source = Get-ChildItem $PSScriptRoot\src\*.ps1 -Recurse -ErrorAction SilentlyContinue
Foreach($import in $Source) {
. $import.fullname
}
'@
$Configuration = Get-Content (Join-Path $PSScriptRoot dbconfig.json) | ConvertFrom-Json
}
Process {
$Configuration.dashboard.title = $ProjectName
$Configuration.dashboard.rootmodule = "$ProjectName.psm1"
$Configuration | ConvertTo-Json -Depth 99 | Set-Content -Path (Join-Path $PSScriptRoot dbconfig.json)
Foreach ($folder in 'src','assets') {
$NewItemSplat = @{
ItemType = 'Directory'
Path = (Join-Path $PSScriptRoot $folder)
ErrorAction = 'SilentlyContinue'
}
New-Item @NewItemSplat > $null
}
Set-Content -Path ("{0}\{1}.psm1" -f $PSScriptRoot,$ProjectName) -Value $ModuleFileContents
$ModuleManifestSplat = @{
Path = ("{0}\{1}.psd1" -f $PSScriptRoot,$ProjectName)
RootModule = "$ProjectName.psm1"
}
New-ModuleManifest @ModuleManifestSplat
}
End {
[PSCustomObject]@{
'Name' = $ProjectName
'RootModule' = (Join-Path $PSScriptRoot $Configuration.dashboard.rootmodule )
'ConfigFile' = (Join-Path $PSScriptRoot dbconfig.json)
}
}