-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNew-DevopsProject.ps1
183 lines (139 loc) · 5.79 KB
/
New-DevopsProject.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Function New-DevopsProject {
<#
.SYNOPSIS
Creates a New Powershell Devops Project
.DESCRIPTION
The function creates a set of powershell modules for a new Devops project.
This function creates a set of powershell modules with psd, psm, ps1 files
including the unit test files. It creates a sample structure for functions
in each of the module to explain the interconnection and usage.
I created this to kick start a new project without having to waste time setting
up each module initially.
.Notes
Author: Gurpreet Singh Jutla
.EXAMPLE
C:\PS> New-DevopsProject -ProjectName <Project Name> -Modules <Module1>, <Module2> -ProjectPath <projectPath> -CompanyName <Company Name> -Author <Author>
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[String]$ProjectName,
[Parameter(Mandatory = $true)]
[String[]]$Modules,
[Parameter(Mandatory = $true)]
[String]$ProjectPath,
[Parameter(Mandatory = $true)]
[String]$CompanyName,
[Parameter(Mandatory = $true)]
[String]$Author,
[Parameter(Mandatory = $false)]
[String]$ProjectStartDate
)
Process {
if (-not (Test-Path -path (Join-Path -Path $ProjectPath -ChildPath $ProjectName))) {
New-Item -Path $ProjectPath -Name $ProjectName -ItemType "directory"
}
$ProjectPath = (Join-Path -Path $ProjectPath -ChildPath $ProjectName)
if ([string]::IsNullOrEmpty( $ProjectStartDate)) {
$ProjectStartDate = [String](Get-Date)
}
foreach ($module in $Modules) {
$Folder = "$ProjectName.$module"
$file1 = "$ProjectName-$module.psd1"
$file2 = "$ProjectName-$module.psm1"
$file3 = "$ProjectName-$module.tests.ps1"
$file4 = "function-$module.tests.ps1"
$file5 = "function-$module.ps1"
$newguid = New-Guid
$content = "<#==============================================================================================
Copyright(c) $companyName. All rights reserved.
File: $file1
Purpose: Project $projectName- Manifest for $module module
Version: 1.0.0.0 - $projectStartDate - Project $projectNameBuild Release Deployment Team
============================================================================================== #>
@{
# Script module or binary module file associated with this manifest.
RootModule = '$file2'
# Version number of this module.
ModuleVersion = '1.0'
# ID used to uniquely identify this module
GUID = '$newguid'
# Author of this module
Author = '$author'
# Company or vendor of this module
CompanyName = '$companyName'
# Copyright statement for this module
Copyright = '(c) 2018 $companyName. All rights reserved.'
# Description of the functionality provided by this module
Description = 'Compute functions for $projectName deployment'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'
}"
$content2 = "<#==============================================================================================
Copyright(c) $companyName. All rights reserved.
File: $file2
Purpose: Project $ProjectName - Export manifest for the $module module
Version: 1.0.0.0 - $projectStartDate - Project $ProjectName Build Release Deployment Team
==============================================================================================
#>
<#
.DESCRIPTION
This file contains export statements for all public functions located in the imported script files.
#>
. `$PSScriptRoot\$file5
Export-ModuleMember -Function 'New-Dummy$Module'"
$content3 = "#Unit/Pester tests for the $module module for $projectName"
$content4 = "#Unit/Pester tests for the $module functions for $ProjectName"
$content5 = "#Functional code for the $module module for $ProjectName
<#==============================================================================================
Copyright(c) $companyName. All rights reserved.
File: function-$Module.ps1
Purpose: Project $ProjectName - $Module Management
Version: 1.0.0.0 - $projectStartDate - Project $ProjectName Build Release Deployment Team
==============================================================================================
#>
function New-Dummy$Module {
<#
.SYNOPSIS
Explain What this function does
.DESCRIPTION
Detailed Description of the function
.EXAMPLE
C:\PS> New-Dummy$Module -FirstVariable <'FirstVariableValue'>
#>
[CmdletBinding()]
Param (
# Description about the FirstVariable
[Parameter(Mandatory = `$true)]
[string]`$FirstVariable
)
begin {
#Common Code for the Function here
} process {
#processing code for the Function Here
} end {
#Windup Code for the function
}
}"
Write-Host `$content
New-Item -ItemType "Directory" -Path ($ProjectPath ) -Name $folder
New-Item -ItemType "File" -Path ($ProjectPath + "\" + $Folder) -Name $file1
New-Item -ItemType "File" -Path ($ProjectPath + "\" + $Folder) -Name $file2
New-Item -ItemType "File" -Path ($ProjectPath + "\" + $Folder) -Name $file3
New-Item -ItemType "File" -Path ($ProjectPath + "\" + $Folder) -Name $file4
New-Item -ItemType "File" -Path ($ProjectPath + "\" + $Folder) -Name $file5
Set-Content -Path ($ProjectPath + "\" + $Folder + "\" + $file1) -Value $content
Set-Content -Path ($ProjectPath + "\" + $Folder + "\" + $file2) -Value $content2
Set-Content -Path ($ProjectPath + "\" + $Folder + "\" + $file3) -Value $content3
Set-Content -Path ($ProjectPath + "\" + $Folder + "\" + $file4) -Value $content4
Set-Content -Path ($ProjectPath + "\" + $Folder + "\" + $file5) -Value $content5
}
}
}
$modules = ("TestModule")
New-DevopsProject -ProjectName "MyTestProject" `
-Modules $modules `
-ProjectPath "C:\mytestCode" `
-CompanyName "LesserGeek" `
-Author "[email protected]" `
-ProjectStartDate (Get-Date)