|
1 | | -# {{ModuleName}} |
| 1 | +# PowerShell Module Template |
2 | 2 |
|
3 | | -{{Description}} |
| 3 | +A GitHub repository template for building, testing, and publishing PowerShell modules. Click **Use this template** at the top of the repo, run a one-shot init script, and you have a working module project with CI, tests, and documentation scaffolding ready to go. |
4 | 4 |
|
5 | | -## Installation |
| 5 | +## What's included |
6 | 6 |
|
7 | | -### From PowerShell Gallery |
| 7 | +### Build & test |
8 | 8 |
|
9 | | -```powershell |
10 | | -Install-Module -Name {{ModuleName}} -Scope CurrentUser |
11 | | -``` |
| 9 | +- **psake + PowerShellBuild** task pipeline (`build.ps1`, `build.psake.ps1`) |
| 10 | +- **Pester 5.x** test layout with `tests/Unit/{Public,Private}` scaffolding |
| 11 | +- **PSScriptAnalyzer** lint configuration |
| 12 | +- **Code coverage** via JaCoCo + Codecov (`codecov.yml`) |
| 13 | +- **Manifest validation tests** with SemVer-aware version-constraint checks (`tests/Manifest.tests.ps1`, `tests/ManifestHelpers.psm1`) |
| 14 | +- **Help documentation tests** that verify every public function has comment-based help with synopsis, description, and examples (`tests/Help.tests.ps1`) |
| 15 | +- **Meta tests** that catch UTF-16 files and tab indentation (`tests/Meta.tests.ps1`) |
| 16 | +- **Integration test loader** — `tests/local.settings.example.ps1` documents how to wire local secrets without committing them |
12 | 17 |
|
13 | | -### From Source |
| 18 | +### CI/CD (GitHub Actions) |
14 | 19 |
|
15 | | -```powershell |
16 | | -git clone {{ProjectUri}}.git |
17 | | -cd {{ModuleName}} |
18 | | -./build.ps1 -Task Build -Bootstrap |
19 | | -Import-Module ./Output/{{ModuleName}}/*/{{ModuleName}}.psd1 |
20 | | -``` |
| 20 | +- `CI.yaml` — lint + test on push and PR |
| 21 | +- `PublishModuleToPowerShellGallery.yaml` — publish on release |
| 22 | +- `auto-merge-bots.yml` — auto-merge dependabot/pre-commit PRs |
| 23 | +- `ggshield.yaml` — secret scanning |
| 24 | +- Dependabot config and FUNDING file |
21 | 25 |
|
22 | | -## Requirements |
| 26 | +### Developer experience |
23 | 27 |
|
24 | | -- PowerShell 5.1 or later (Desktop or Core) |
25 | | -- Windows, Linux, or macOS |
| 28 | +- **`.devcontainer/`** with Docker Compose + host setup script |
| 29 | +- **`.pre-commit-config.yaml`** with ggshield secret scanning |
| 30 | +- **`instructions/`** — 12 markdown guides for AI agents (PowerShell style, testing, releases, git workflow, etc.) |
| 31 | +- **`AGENTS.md`** — top-level AI agent guidance |
| 32 | +- Markdown linting via `.markdownlint-cli2.jsonc` |
26 | 33 |
|
27 | | -## Quick Start |
| 34 | +### Module scaffolding |
28 | 35 |
|
29 | | -```powershell |
30 | | -# Import the module |
31 | | -Import-Module {{ModuleName}} |
32 | | -
|
33 | | -# Get help for available commands |
34 | | -Get-Command -Module {{ModuleName}} |
| 36 | +- Full `.psd1` manifest with PSEdition tags, license/project URIs, and PSData metadata |
| 37 | +- `.psm1` with public/private dot-source pattern |
| 38 | +- Example public function (`Get-{{Prefix}}Example`) and private helper (`Invoke-{{Prefix}}Helper`) |
| 39 | +- `docs/en-US/about_{{ModuleName}}.help.md` stub for `Get-Help about_<Module>` |
35 | 40 |
|
36 | | -# Example usage |
37 | | -Get-{{Prefix}}Example -Name 'World' |
38 | | -``` |
| 41 | +## Quick start |
39 | 42 |
|
40 | | -## Available Commands |
| 43 | +1. Click **Use this template → Create a new repository** at the top of this repo. |
| 44 | +2. Clone your new repository locally. |
| 45 | +3. Run the initialization script: |
41 | 46 |
|
42 | | -| Command | Description | |
43 | | -|---------|-------------| |
44 | | -| `Get-{{Prefix}}Example` | Example public function | |
| 47 | + ```powershell |
| 48 | + ./Initialize-Template.ps1 |
| 49 | + ``` |
45 | 50 |
|
46 | | -## Development |
| 51 | + You'll be prompted for module name, function prefix, author, description, and project URL. Pass them as parameters for non-interactive use: |
47 | 52 |
|
48 | | -### Prerequisites |
| 53 | + ```powershell |
| 54 | + ./Initialize-Template.ps1 ` |
| 55 | + -ModuleName 'MyAwesomeModule' ` |
| 56 | + -Prefix 'Mam' ` |
| 57 | + -Author 'Jane Doe' ` |
| 58 | + -Description 'Does awesome things' ` |
| 59 | + -ProjectUri 'https://github.com/janedoe/MyAwesomeModule' |
| 60 | + ``` |
49 | 61 |
|
50 | | -- PowerShell 5.1+ or PowerShell 7+ |
51 | | -- Git |
| 62 | +4. The script substitutes placeholders, renames files, optionally runs `git init`, and bootstraps build dependencies. Delete `Initialize-Template.ps1` when done. |
52 | 63 |
|
53 | | -### Building |
| 64 | +## Placeholders |
54 | 65 |
|
55 | | -```powershell |
56 | | -# Clone the repository |
57 | | -git clone {{ProjectUri}}.git |
58 | | -cd {{ModuleName}} |
| 66 | +`Initialize-Template.ps1` replaces these tokens across all `.ps1`, `.psm1`, `.psd1`, `.md`, `.json`, `.yml`, `.yaml`, `.xml`, and `.txt` files: |
59 | 67 |
|
60 | | -# Bootstrap dependencies and build |
61 | | -./build.ps1 -Task Build -Bootstrap |
| 68 | +| Placeholder | Replaced with | Example | |
| 69 | +|---|---|---| |
| 70 | +| `{{ModuleName}}` | Module name | `MyAwesomeModule` | |
| 71 | +| `{{Prefix}}` | Function noun prefix | `Mam` | |
| 72 | +| `{{Author}}` | Author name | `Jane Doe` | |
| 73 | +| `{{Description}}` | Module description | `Does awesome things` | |
| 74 | +| `{{ProjectUri}}` | Repository URL | `https://github.com/...` | |
| 75 | +| `{{GUID}}` | Generated GUID | (new GUID per run) | |
| 76 | +| `{{Date}}` | ISO date at init | `2026-04-29` | |
| 77 | +| `{{Year}}` | Year at init | `2026` | |
62 | 78 |
|
63 | | -# Run tests |
64 | | -./build.ps1 -Task Test |
65 | | -``` |
| 79 | +The script also renames the `{{ModuleName}}` folder, files containing `{{ModuleName}}` or `{{Prefix}}` in their names (in `Public/`, `Private/`, `tests/Unit/`, `docs/en-US/`), and replaces `README.md` with the post-init module README sourced from `README.template.md`. |
66 | 80 |
|
67 | | -### Project Structure |
| 81 | +## Project structure (post-init) |
68 | 82 |
|
69 | 83 | ``` |
70 | | -{{ModuleName}}/ |
71 | | -├── {{ModuleName}}/ # Module source |
72 | | -│ ├── Public/ # Exported functions |
73 | | -│ └── Private/ # Internal helpers |
74 | | -├── tests/ # Pester tests |
75 | | -│ ├── Unit/ # Unit tests |
76 | | -│ ├── Meta.tests.ps1 # Code style tests |
77 | | -│ ├── Manifest.tests.ps1 # Manifest validation |
78 | | -│ └── Help.tests.ps1 # Help documentation tests |
79 | | -├── docs/ # Documentation |
80 | | -├── .github/workflows/ # CI/CD pipelines |
81 | | -└── build.ps1 # Build entry point |
| 84 | +<ModuleName>/ |
| 85 | +├── <ModuleName>/ # Module source |
| 86 | +│ ├── Public/ # Exported functions |
| 87 | +│ └── Private/ # Internal helpers |
| 88 | +├── tests/ |
| 89 | +│ ├── Unit/{Public,Private}/ # Per-function tests |
| 90 | +│ ├── Help.tests.ps1 # Comment-based-help validation |
| 91 | +│ ├── Manifest.tests.ps1 # Manifest + dependency-version validation |
| 92 | +│ ├── Meta.tests.ps1 # Encoding + indentation checks |
| 93 | +│ └── ManifestHelpers.psm1 # SemVer comparison helpers |
| 94 | +├── docs/en-US/ # platyPS help (generated) |
| 95 | +├── instructions/ # AI agent guidance (12 files) |
| 96 | +├── .github/workflows/ # CI, publish, auto-merge, secret scan |
| 97 | +├── .devcontainer/ # VS Code dev container |
| 98 | +├── build.ps1 # Build entry point |
| 99 | +├── build.psake.ps1 # psake task definitions |
| 100 | +├── build.depend.psd1 # Build/test module dependencies |
| 101 | +└── requirements.psd1 # Runtime module dependencies |
82 | 102 | ``` |
83 | 103 |
|
84 | | -### Available Build Tasks |
| 104 | +## Working on the template itself |
| 105 | + |
| 106 | +If you want to contribute to the template (this repo) rather than use it: |
85 | 107 |
|
86 | 108 | ```powershell |
87 | | -./build.ps1 -Help |
| 109 | +./build.ps1 -Task Test -Bootstrap |
88 | 110 | ``` |
89 | 111 |
|
90 | | -| Task | Description | |
91 | | -|------|-------------| |
92 | | -| `Build` | Build the module to Output/ | |
93 | | -| `Test` | Run all tests with code coverage | |
94 | | -| `Analyze` | Run PSScriptAnalyzer | |
95 | | -| `Pester` | Run Pester tests only | |
96 | | -| `Clean` | Remove build artifacts | |
97 | | -| `Publish` | Publish to PowerShell Gallery | |
| 112 | +The test suite runs against the `{{ModuleName}}` placeholder module to verify the scaffolding is sound. See [AGENTS.md](AGENTS.md) and [`instructions/`](instructions/) for contribution conventions. |
98 | 113 |
|
99 | | -## Contributing |
| 114 | +## Requirements |
100 | 115 |
|
101 | | -1. Fork the repository |
102 | | -2. Create a feature branch |
103 | | -3. Make your changes |
104 | | -4. Run tests: `./build.ps1 -Task Test` |
105 | | -5. Submit a pull request |
| 116 | +- PowerShell 5.1+ or PowerShell 7+ |
| 117 | +- Git |
| 118 | +- (Optional) Docker for the devcontainer |
106 | 119 |
|
107 | 120 | ## License |
108 | 121 |
|
109 | | -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
110 | | - |
111 | | -## Changelog |
112 | | - |
113 | | -See [CHANGELOG.md](CHANGELOG.md) for version history. |
| 122 | +[MIT](LICENSE) |
0 commit comments