44 lines
2.0 KiB
PowerShell
44 lines
2.0 KiB
PowerShell
Function New-Module {
|
|
# Variables
|
|
$Current_Path = Get-Location | Select-Object -ExpandProperty Path
|
|
$Prompt_Name = Read-Host "Enter Module Name"
|
|
$Out_File = $Current_Path + "\" + "COMPANY." + $Prompt_Name + ".psm1"
|
|
|
|
# Get all .ps1 files from Public and Private folders
|
|
$Files = Get-ChildItem -Path "$Current_Path\Public\*.ps1", "$Current_Path\Private\*.ps1"
|
|
|
|
$Merged_Content = foreach ($File in $Files) {
|
|
# Optional: Use the PowerShell Parser to extract only the function code
|
|
$ast = [System.Management.Automation.Language.Parser]::ParseFile($File.FullName, [ref]$null, [ref]$null)
|
|
$ast.EndBlock.Extent.Text
|
|
"`n" # Add a newline between functions
|
|
}
|
|
$Merged_Content | Set-Content -Path $Out_File
|
|
Write-Output "Module created at: $Out_File"
|
|
|
|
$Question = Read-host "Do you want to create module manifest file now? [y/n]"
|
|
switch ($Question.ToLower()) {
|
|
{ @("y", "yes") -contains $_ } {
|
|
$RootModule = Get-ChildItem -File -Filter *.psm1 -ErrorAction Stop | Select-Object -First 1
|
|
$Path = [System.IO.Path]::ChangeExtension($RootModule.FullName, '.psd1')
|
|
$FunctionNames = Get-ChildItem -Recurse -Depth 1 | Where-Object { $_.Name -like "*.ps1" } | Select-Object -ExpandProperty Name | ForEach-Object { $_ -replace ".ps1", "" } | Sort-Object -Unique
|
|
|
|
$manifest = @{
|
|
Author = $env:USERNAME
|
|
Description = 'Test Description'
|
|
FunctionsToExport = @($FunctionNames)
|
|
Path = $Path
|
|
RootModule = $RootModule.Name
|
|
CompanyName = 'COMPANY'
|
|
LicenseUri = 'https://opensource.org/licenses/MIT'
|
|
ModuleVersion = '1.0.0'
|
|
}
|
|
New-ModuleManifest @manifest
|
|
}
|
|
default {
|
|
Write-Output "Script complete, please create module manifest file manually."
|
|
Start-Sleep 5
|
|
Exit
|
|
}
|
|
}
|
|
} |