Skip to content

Commit b8430e7

Browse files
committed
Add some default template files and some initial code to Initialization script
1 parent 9576507 commit b8430e7

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed

_InitializeRepository.ps1

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
11
# Run this script to replace the default template repository values with values specific to your module.
2+
3+
Process
4+
{
5+
Write-Host -ForegroundColor Green "
6+
This script will replace the default template repository files and values with ones specific to your module.
7+
If you have made changes to any files, you may want to commit them before continuing, as this script may overwrite them.
8+
"
9+
10+
[string] $moduleName = Read-Host -Prompt "Enter the name of your module (e.g. 'YourModuleName')"
11+
12+
[string] $organizationName = Read-Host -Prompt "Enter your name, or the the name of your organization (e.g. 'My Company'). This will be used in the module manifest and repository license"
13+
14+
Remove-TemplateModuleFiles
15+
New-ModuleFiles -ModuleName $moduleName -OrganizationName $organizationName
16+
Set-RepositoryDefaultFiles -ModuleName $moduleName -OrganizationName $organizationName
17+
Remove-TemplateDefaultFiles
18+
}
19+
20+
Begin
21+
{
22+
$InformationPreference = 'Continue'
23+
[string] $RepositoryRoot = $PSScriptRoot
24+
25+
function Remove-TemplateModuleFiles
26+
{
27+
[string] $templateModuleDirectoryPath = "$RepositoryRoot\src\Template.PowerShell.ScriptModule"
28+
if (Test-Path -Path $templateModuleDirectoryPath -PathType Container)
29+
{
30+
Remove-Item -Path $templateModuleDirectoryPath -Recurse -Force
31+
}
32+
}
33+
34+
function New-ModuleFiles([string] $moduleName, [string] $organizationName)
35+
{
36+
[string] $moduleDirectoryPath = "$RepositoryRoot\src\$moduleName"
37+
[string] $moduleFilePath = "$moduleDirectoryPath\$moduleName.psm1"
38+
[string] $moduleManifestFilePath = "$moduleDirectoryPath\$moduleName.psd1"
39+
[string] $moduleTestsFilePath = "$moduleDirectoryPath\$moduleName.Tests.ps1"
40+
41+
# Create the module directory.
42+
if (-Not (Test-Path -Path $moduleDirectoryPath -PathType Container))
43+
{
44+
New-Item -Path $moduleDirectoryPath -ItemType Directory
45+
}
46+
47+
# Create the module file.
48+
if (-Not (Test-Path -Path $moduleFilePath -PathType Leaf))
49+
{
50+
51+
}
52+
53+
# Create the module manifest file.
54+
if (-Not (Test-Path -Path $moduleManifestFilePath -PathType Leaf))
55+
{
56+
57+
}
58+
else
59+
{
60+
Write-Host "Module manifest file already exists at '$moduleManifestFilePath'. Skipping creation."
61+
}
62+
63+
# Create the module tests file.
64+
if (-Not (Test-Path -Path $moduleTestsFilePath -PathType Leaf))
65+
{
66+
67+
}
68+
else
69+
{
70+
Write-Host "Module tests file already exists at '$moduleTestsFilePath'. Skipping creation."
71+
}
72+
}
73+
74+
function Remove-TemplateDefaultFiles
75+
{
76+
[string] $templateDefaultFilesDirectoryPath = "$RepositoryRoot\_TemplateDefaultFiles"
77+
if (Test-Path -Path $templateDefaultFilesDirectoryPath -PathType Container)
78+
{
79+
Remove-Item -Path $templateDefaultFilesDirectoryPath -Recurse -Force
80+
}
81+
}
82+
}

_TemplateDefaultFiles/Changelog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
This page is a list of _notable_ changes made in each version.
4+
5+
## v1.0.0 - January 1, 2099
6+
7+
Features:
8+
9+
- Initial release
10+
11+
Fixes:
12+
13+
- Fixes
14+
15+
Community contributions:
16+
17+
- @person: Contribution

_TemplateDefaultFiles/ReadMe.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# NewModuleName PowerShell Module
2+
3+
## 💬 Description
4+
5+
A short description of what this project does.
6+
7+
## ❓ Why this exists
8+
9+
A short description of why this project exists.
10+
What use-case is it meant to solve?
11+
12+
## ✨ Features
13+
14+
List the features of this project:
15+
16+
- Feature 1
17+
- Feature 2
18+
19+
## 🚀 Quick start
20+
21+
A quick guide on how to get started with this module, including installation and usage:
22+
23+
- A link to the module in the PowerShell Gallery.
24+
- Code snippets of installing and using the module.
25+
- Links to wiki or other documentation.
26+
27+
## ➕ How to contribute
28+
29+
Issues and Pull Requests are welcome.
30+
See [the Contributing page](docs/Contributing.md) for more details.
31+
32+
## 📃 Changelog
33+
34+
See what's changed in the application over time by viewing [the changelog](Changelog.md).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# These tests are runs as part of the deployment process to ensure the newly published module is working as expected.
2+
# These tests run against the installed module, not the source code, so they are a real-world test and should not use mocks.
3+
# Since mocks are not used, be careful to not rely on state stored on the machine, such as a module configuration file.
4+
# This is a great place to put tests that differ between operating systems, since they will be ran on multiple platforms.
5+
# To run these tests on your local machine, see the comments in the BeforeAll block.
6+
7+
BeforeAll {
8+
Import-Module -Name 'NewModuleName' -Force
9+
10+
# To run these tests on your local machine, comment out the Import-Module command above and uncomment the one below.
11+
# Do this to use the module version from source code, not the installed version.
12+
# This is necessary to test functionality that you've added to the module, but have not yet published and installed.
13+
# Import-Module "$PSScriptRoot\..\src\Template.PowerShell.ScriptModule" -Force
14+
}
15+
16+
Describe 'Get-HelloWorld' {
17+
It 'Should return "Hello, World!"' {
18+
$expected = 'Hello, World!'
19+
$result = Get-TemplateDescription
20+
$result | Should -Be $expected
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using module './NewModuleName.psm1'
2+
3+
# UPDATE ME: This is just example code. Replace the code below with your module's tests.
4+
Describe 'Get-HelloWorld' {
5+
It 'Should return "Hello, World!"' {
6+
$expected = 'Hello, World!'
7+
$result = Get-TemplateDescription
8+
$result | Should -Be $expected
9+
}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# UPDATE ME: This is just example code. Replace this file's contents with your module code.
2+
3+
function Get-HelloWorld {
4+
[CmdletBinding()]
5+
Param ()
6+
7+
Write-Output "Hello, World!"
8+
}

0 commit comments

Comments
 (0)