Giter Club home page Giter Club logo

powershell-module-template's Introduction

PowerShell Module Template

My PowerShell module project template, for use with Plaster.

This template sets up a number of things to make getting started with authoring a new PowerShell module much less time consuming, while following best practices around organising source code, unit testing and documentation. On top of a basic project structure, it also has a number of build tasks setup and some extra things like VS Code tasks already configured.

This is the result of me seeing how a number of other projects and people organise their modules, and then tweaking/simplifying things to my liking.

Using The Template

To create a new PowerShell module project with this template, download/clone this repository into a folder and then run...

Invoke-Plaster -TemplatePath <PathToFolder> -DestinationPath <PathForNewProject>

You will then have a newly scaffolded PowerShell module project to start work on.

Dependencies

How It Works

When invoked, Plaster reads the plasterManifest.xml file to scaffold a new module project. The Plaster manifest XML file declaratively describes the content and creation process for the new project. Take a look at the plasterManifest.xml file to see how it generates the output shown below.

For more information on Plaster manifests and how they work, head over to the Plaster docs.

Output Example

MyNewModule
|
|---.vscode
|       settings.json
|       tasks.json
|
|---docs
|   
|---src
|   |---docs
|   |   |---en-US
|   |   |       about_MyNewModule.md
|   |   |       Add-YourFirstFunction.md
|   |
|   |---private
|   |       Add-PrivateFunction.ps1
|   |
|   |---public
|   |       Add-YourFirstFunction.ps1
|   |
|   |   MyNewModule.psd1
|   |   MyNewModule.psm1
|
|---tests
|   |---private
|   |       Add-PrivateFunction.Tests.ps1
|   |
|   |---public
|   |       Add-YourFirstFunction.Tests.ps1
|   |
|   |   _InitializeTests.ps1
|   |   MyNewModule.Manifest.Tests.ps1
|
|   .gitignore
|   LICENSE
|   MyNewModule.Build.ps1
|   PSScriptAnalyzerSettings.psd1
|   README.md

Output Details

.vscode

Contains Visual Studio Code workspace settings and task definitions.

  • extensions.json - Provides extension recommendations.
  • settings.json - Overrides editor settings for tab indents and whitespace.
  • tasks.json - Generated by New-VSCodeTask script so Invoke-Build tasks are available as VS Code tasks.

docs

Directory for project documentation as per GitHub convention, separate from the module's own documentation.

src

Contains all source code for the PowerShell module.

  • docs\en-US - Contains markdown sources for module documentation.
    • about_MyNewModule.md - platyPS template for PowerShell's 'about' help topic.
    • Add-YourFirstFunction.md - platyPS template for the example public function's help document.
  • private - Contains sources for all private module functions.
    • Add-PrivateFunction.ps1 - Example private module function.
  • public - Contains sources for all public module functions.
    • Add-YourFirstFunction.ps1 - Example public module function.
  • MyNewModule.psd1 - PowerShell module manifest file.
  • MyNewModule.psm1 - PowerShell root module file.

tests

Contains all Pester tests for the module.

  • private - Contains Pester tests for private module functions.
    • Add-PrivateFunction.Tests.ps1 - Example Pester test for example private module function.
  • public - Contains Pester tests for public module functions.
    • Add-YourFirstFunction.Tests.ps1 - Example Pester test for example public module function.
  • _InitializeTests.ps1 - Common initialize script that can be dot sourced into individual Pester test files.
  • MyNewModule.Manifest.Tests.ps1 - Pester test file for the PowerShell module's manifest file.

/

  • .gitignore - Ignore file for Git.
  • LICENSE - MIT license document.
  • MyNewModule.Build.ps1 - Invoke-Build script, containing task definitions.
  • PSScriptAnalyzerSettings.psd1 - Settings file for PSScriptAnalyzer.
  • README.md - Project readme file.

Contributions

Although this template is built to my own preferences, any contributions or suggestions for improvements would be very welcomed!

powershell-module-template's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jberkers42 jensgj

powershell-module-template's Issues

Updates to Pester require changes to Test Scripts

Expected Behavior

Pester tests included with the template should continue to work on systems running an up-to-date version of Pester.

Actual Behavior

Pester tests fail with:

 RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.  Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4

Since the requirements in the Build Script already specify Pester version 4.7.3, this should not be a breaking change for anyone using the minimum supported version of Pester for this Template.

Steps to Reproduce the Problem

  1. Create a new PowerShell Module Skeleton with Invoke-Plaster -TemplatePath <Path to Folder> -DestinationPath <Path to Module>
  2. From within the new module path, run Invoke-Build -task Test

Specifications

  • Version: Plaster version 1.0
  • Platform: PowerShell Core
  • Subsystem: Pester version 5.2.0

I will submit a pull request with the necessary fixes for this.

Updates to Publish-Module require the source folder to be the same as the module name

Expected Behavior

When performing the Invoke-Build -Task Publish, assuming all requirements are met, the module should be published to PSGallery.

Actual Behavior

When performing the Invoke-Build -Task Publish all tasks complete, except the publish itself, returning an error:

No valid module was found at the specified location

Steps to Reproduce the Problem

  1. Create an otherwise valid PowerShell Module that passes all tests and compiles
  2. Perform Invoke-Build -Task Publish
  3. The error is returned

One of the current requirements for Publish-Module is that the Folder/Directory specified in the -Path parameter have the same name as the module itself. In the Module Build script the folder name is build.

Specifications

  • Version: Plaster 1.0.x
  • Platform: PowerShell Core
  • Subsystem: Invoke-Build

Solution

Adjust the Build script to create a sub-folder under build using the module name, derived in the same way as in other parts of the script.

I will submit a PR for the same.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.