diff --git a/README.md b/README.md index 8d12aa7..15122de 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ Whether you're creating simple or robust modules, ModuleTools streamlines the pr [![ModuleTools@PowerShell Gallery][BadgeIOCount]][PSGalleryLink] ![WorkFlow Status][WorkFlowStatus] - - The structure of the ModuleTools module is meticulously designed according to PowerShell best practices for module development. While some design decisions may seem unconventional, they are made to ensure that ModuleTools and the process of building modules remain straightforward and easy to manage. > [!IMPORTANT] @@ -28,7 +26,7 @@ The structure of the ModuleTools module is meticulously designed according to Po Install-Module -Name ModuleTools ``` -> Note: ModuleTolls is still in early devleopment phase and lot of changes are expected. Please read through [ChangeLog](/CHANGELOG.md) for all updates. +> Note: ModuleTolls is still in early development phase and lot of changes are expected. Please read through [ChangeLog](/CHANGELOG.md) for all updates. ## ๐Ÿงต Design @@ -62,8 +60,6 @@ Generated module is stored in dist folder, you can easily import it or publish i โ””โ”€โ”€ ๏…› TestModule.psm1 ``` - - ### Project JSON File The `project.json` file contains all the important details about your module and is used during the module build. It should comply with a specific schema. You can refer to the sample `project-sample.json` file in the `example` directory for guidance. @@ -72,9 +68,43 @@ Run `New-MTModule` to generate the scaffolding; this will also create the `proje ### Src Folder - - Place all your functions in the `private` and `public` folders within the `src` directory. - - All functions in the `public` folder are exported during the module build. - - All functions in the `private` folder are accessible internally within the module but are not exposed outside the module. +- Place all your functions in the `private` and `public` folders within the `src` directory. +- All functions in the `public` folder are exported during the module build. +- All functions in the `private` folder are accessible internally within the module but are not exposed outside the module. +- Contents of the `src/resources` folder, including any subfolder, will included in the `dist` folder during the module build. + +#### resources Folder + +The `resources` folder within the `src` directory is intended for including any additional resources required by your module. This can include files such as: + +- **Configuration files**: Store any JSON, XML, or other configuration files needed by your module. +- **Script files**: Place any scripts that are used by your functions or modules, but are not directly part of the public or private functions. +- **Documentation files**: Include any supplementary documentation that supports the usage or development of the module. +- **Data files**: Store any data files that are used by your module, such as CSV or JSON files. +- **Subfolder**: Include any additional folders and their content to be included with the module, such as dependant Modules, APIs, DLLs, etc... organized by a subfolder. + +When the module is built, the contents of the `src/resources` folder will be copied directly to the `dist` folder. If the `src/resources` folder contains any subfolders, those subfolders and their contents will also be included in the `dist` folder, ensuring that all necessary files are available for the module to function correctly. + +How the resources folder gets copied to the "OutputModuleDir" folder will depends on the "ResourceCopyMode" project setting. When missing or set to "Folder", the resources folder will be copied. When "ResourceCopyMode" is set to "Content", then only the content of the resources folder will be copied. + +Leave `src\resources` empty if there is no need to include any additional content in the `dist` folder. + +An example of the module build where resources were included: + +```powershell +dist +โ””โ”€โ”€ TestModule + โ”œโ”€โ”€ TestModule.psd1 + โ”œโ”€โ”€ TestModule.psm1 + โ”œโ”€โ”€ config.json + โ”œโ”€โ”€ additionalScript.ps1 + โ”œโ”€โ”€ helpDocumentation.md + โ”œโ”€โ”€ sampleData.csv + โ””โ”€โ”€ subfolder + โ”œโ”€โ”€ subConfig.json + โ”œโ”€โ”€ subScript.ps1 + โ””โ”€โ”€ subData.csv +``` ### Tests Folder @@ -97,6 +127,11 @@ New-MTModule ~/Work `ModuleTools` is designed so that you don't need any additional tools like `make` or `psake` to run the build commands. There's no need to maintain complex `build.ps1` files or sample `.psd1` files. Simply follow the structure outlined above, and you can run `Invoke-MTBuild` to build the module. The output will be saved in the `dist` folder, ready for distribution. +The Invoke-MTBuild CmdLet includes a step where the resources folder and/or it's contents are copied to the "OutputModuleDir" folder. This is controlled by the optional "ResourceCopyMode" project setting. + +If "ResourceCopyMode" = 'Folder or if it's missing, the entire resources folder gets copied to the "OutputModuleDir" folder. +If "ResourceCopyMode" = 'Content', only the content of the resources folder gets copied to the "OutputModuleDir" folder. + ```powershell # From the Module root Invoke-MTBuild @@ -126,7 +161,15 @@ A simple command to update the module version by modifying the values in `projec ## Advanced - Use it in Github Actions -This is not required for local module builds, if you are running github actions, use below template to test, build and publish module with ease. +This is not required for local module builds, if you are running github actions, use the following yaml workflow template to test, build and publish module which helps to automate the process of: + +1. Checking out the repository code. +1. Installing the `ModuleTools` module from the PowerShell Gallery. +1. Building the module. +1. Running Pester tests. +1. Publishing the module to a specified repository. + +This allows for seamless and automated management of your PowerShell module, ensuring consistency and reliability in your build, test, and release processes. ```yaml name: Build, Test and Publish @@ -154,6 +197,7 @@ jobs: - name: Run Pester Tests run: Invoke-MTTest shell: pwsh + - name: Publish Package to Github run: | Publish-PSResource -Path ./dist/YourModule -Repository SomeRepository -ApiKey $Env:ApiKey diff --git a/project.json b/project.json index ee220ab..5bf1ff0 100644 --- a/project.json +++ b/project.json @@ -1,7 +1,8 @@ { "ProjectName": "ModuleTools", "Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.", - "Version": "0.0.9", + "Version": "0.0.10", + "ResourceCopyMode": "Folder", "Manifest": { "Author": "Manjunath Beli", "PowerShellHostVersion": "7.4", diff --git a/src/private/CopyProjectResource.ps1 b/src/private/CopyProjectResource.ps1 index 99f1868..79dff04 100644 --- a/src/private/CopyProjectResource.ps1 +++ b/src/private/CopyProjectResource.ps1 @@ -1,11 +1,22 @@ function Copy-ProjectResource { $data = Get-MTProjectInfo $resFolder = [System.IO.Path]::Join($data.ProjectRoot, 'src', 'resources') - if (Test-Path $resFolder) { - if (Get-ChildItem $resFolder -ErrorAction SilentlyContinue) { - Write-Verbose 'Files found in resource folder, Copying resource folder content' - Copy-Item -Path $resFolder -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop + if ($data.ResourceCopyMode -eq 'Content') { + # Copy the resources folder content to the OutputModuleDir + $items = Get-ChildItem -Path $resFolder -ErrorAction SilentlyContinue + if ($items) { + Write-Verbose 'Files found in resource folder, copying resource folder content' + foreach ($item in $items) { + Copy-Item -Path $item.FullName -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop + } + } + } else { + # Copy the resources folder to the OutputModuleDir + if (Get-ChildItem $resFolder -ErrorAction SilentlyContinue) { + Write-Verbose 'Files found in resource folder, Copying resource folder' + Copy-Item -Path $resFolder -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop + } } } -} \ No newline at end of file +} diff --git a/src/resources/ProjectTemplate.json b/src/resources/ProjectTemplate.json index c2c04d9..3829d00 100644 --- a/src/resources/ProjectTemplate.json +++ b/src/resources/ProjectTemplate.json @@ -2,6 +2,7 @@ "ProjectName": "", "Description": "", "Version": "", + "ResourceCopyMode": "", "Manifest": { "Author": "", "PowerShellHostVersion": "", diff --git a/src/resources/Schema-Build.json b/src/resources/Schema-Build.json index 4104722..18b889e 100644 --- a/src/resources/Schema-Build.json +++ b/src/resources/Schema-Build.json @@ -12,6 +12,9 @@ "Version": { "type": "string" }, + "ResourceCopyMode": { + "type": "string" + }, "Manifest": { "type": "object", "properties": {