Skip to content

Commit

Permalink
Make stuff work
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLawrie committed Aug 25, 2024
1 parent ca2433a commit cf58911
Show file tree
Hide file tree
Showing 51 changed files with 8,862 additions and 8,463 deletions.
47 changes: 47 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Contributing

👋🏻 Hi, and thank you for getting as far as reading the contributing guide!

I'm thrilled that you're interested in contributing to this project. Your contributions are valuable and help make the module even better.

## How to Contribute

### 🐛 Reporting Bugs

If you find a bug, please raise an issue on the GitHub repo. Please include as much detail as possible, including the version of the module you're using, the version of PowerShell, and the OS you're running on.

### ✨ Suggesting Enhancements

If you have an idea for an enhancement, please raise an issue on the GitHub repo as a starting point. This allows us to discuss a potential solution. I've found that discussing the enhancement before writing code can save a lot of time and effort.

### 💻 Development Guidelines

These are guidelines not rules, you can do whatever you want to make things work and open a PR but following these guidelines will make it easier for me to review your PR and get it merged.

1. Fork this repo from the `prerelease` branch. This is where all development is done and pre-release versions are published from. The `main` branch is only used for production releases after the pre-release changes have had some more thorough testing.
2. This is a PowerShell module and I intend on keeping it mostly PowerShell so those familiar with PowerShell but not C# can still contribute. If you're adding a feature that requires a C# class, please raise an issue first so we can discuss the best way to implement it. I'm aware not all features can be implemented in PowerShell and I'm open to adding C# code where necessary.
3. Importing namespaces at the top of the `ps1` scripts is not advised, it makes the code more concise but it removes the ability to easily copy-paste code into a script.
4. All public functions go in the `/PwshSpectreConsole/public` folder. These functions also need to be added to the FunctionsToExport array in the `PwshSpectreConsole.psd1` file to make them accessible to users.
5. All internal functions go in the `/PwshSpectreConsole/private` folder.
6. All functions in the `/PwshSpectreConsole/public` folder should have a comment-based help block at the top of the function. This is used to generate the markdown for the documentation site. See [`Read-SpectreMultiSelection.ps1`](PwshSpectreConsole/public/prompts/Read-SpectreMultiSelection.ps1) for an example. See [documentation help](/PwshSpectreConsole.Docs/README.md) for more information.
7. All public functions should have unit tests in the `/PwshSpectreConsole.Tests` folder. These tests should be written in Pester and should test the function in a variety of scenarios. The tests should be named the same as the function they're testing with `.Tests` appended to the end. e.g. [`Read-SpectreMultiSelection.tests.ps1`](PwshSpectreConsole.Tests/prompts/Read-SpectreMultiSelection.tests.ps1).

## Thanks to Those Who Have Already Contributed

These people are awesome and you should go follow them to keep tabs on all the other awesome stuff they're doing:

- @patriksvensson
The [Spectre Console](https://spectreconsole.net/) creator. Without the dotnet library this module wouldn't exist.
- @dfinke
Doug Finke helped fix some broken table logic in the earliest days of the module yet his biggest contribution has been to my growth as a developer. Thanks for helping me gather the courage to build in the open.
- @trackd
The table whisperer. Most of the logic for translating between PowerShell objects and the format required by the Spectre Console table widgets has come from their big brain and it's melted mine. They're a crazy-talented PowerShell developer who has helped teach me a lot and their contributions are a big part of the v2 release.
- @StartAutomating
Thanks for the sponsorship, EZOut and HelpOut modules. HelpOut is used to generate the markdown that powers the [pwshspectreconsole.com](https://pwshspectreconsole.com/reference/formatting/format-spectrebarchart/) documentation site.
- @futuremotiondev, @ruckii and @csillikd-messerli
Thank you for the issues raised and the fixes you've pulled together making this module better.

## Contact Me

If you have any questions, please reach out to me on Twitter [@shaun_lawrie](https://twitter.com/shaun_lawrie).
You can also find me on Discord in the [PowerShell discord](https://discord.gg/powershell) as `shaunlawrie`.
74 changes: 74 additions & 0 deletions PwshSpectreConsole.Docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Documentation

Most documentation is generated from the comment-based help in the module functions. This means that the documentation is always up-to-date with the code. You don't need to format the comment based help correctly as any issues should be discovered when your PR is merged to the prerelease branch but if you need to make changes to the documentation locally you can follow the steps below.

## Testing the Documentation Locally

This requires you have nodejs v20 installed. If you don't have nodejs installed, you can install it from [nodejs.org](https://nodejs.org/) or you can use my preferred method of using [nvm-windows](https://github.com/coreybutler/nvm-windows).

1. Clone this repository and open a terminal in the root directory.
2. Install the HelpOut PowerShell module by running `Install-Module helpout -Scope CurrentUser -RequiredVersion 0.5`. Version 0.5 is required because changes to the formatting in HelpOut can break the Markdown generation and 0.5 is what's being used in the Github Actions.
3. Change to the docs directory `cd .\PwshSpectreConsole.Docs`.
4. Run `npm install`.
5. Run `npm run dev` to start the dev server. You should be able to view the documentation at [http://localhost:4321](http://localhost:4321)
6. To update the help for the public functions:
- Press `ctrl-c` in the terminal session that's hosting the docs dev server to stop it.
- Update the comment based help in your public functions. See [Comment Based Help](#comment-based-help) below for more information on how to format the help docs.
- Run `npm run update-docs:no-commit -- -TargetFunction Set-SpectreColors` again to see the changes for the function you've changed, replace "Set-SpectreColors" with the function you're working on. The dev server will start again after updating the docs and you can view the changes at [http://localhost:4321](http://localhost:4321).
7. When you're happy that the docs look correct you can open a PR with the changes. You don't have to commit the docs files, they will be autogenerated when your branch is merged into the prerelease branch of PwshSpectreConsole.

## Comment Based Help

The comment based help in the module functions is used to generate the markdown for the documentation site. The comment based help is written in a specific format to ensure that the markdown is generated correctly.

When generation the help the following fields are used and others are dropped:

- `DESCRIPTION` is used as the main description on the docs site.
- `PARAMETER` documentation will be kept and grouped under Parameters on the docs page.
- `EXAMPLE` documentation is the hard part so two examples are provided below. You can provide multiple examples.

> [!WARNING]
> You can't start your example with a comment line. There is a limitation in the way that the markdown is generated that means the first line of the example can't be a comment or it will break the markdown generation.
### Example 1 - Basic Example

For a standard function a simple example will only require the code required to make the function do its magic. In the example below the function Format-SpectreBarChart is used to create a bar chart but it requires data setup. The example code needs to work as one full statement that you could copy and paste into a PowerShell console so the data setup is part of the example.

```powershell
<#
.EXAMPLE
$data = @()
$data += New-SpectreChartItem -Label "Apples" -Value 10 -Color "Green"
$data += New-SpectreChartItem -Label "Oranges" -Value 5 -Color "DarkOrange"
$data += New-SpectreChartItem -Label "Bananas" -Value 2.2 -Color "#FFFF00"
Format-SpectreBarChart -Data $data -Label "Fruit Sales" -Width 50
#>
```

See the example in action at: [https://pwshspectreconsole.com/reference/formatting/format-spectrebarchart/](https://pwshspectreconsole.com/reference/formatting/format-spectrebarchart/)

### Example 2 - Advanced Example

For more complex functions you may not be able to generate an example without providing user input. If you were to try and generate an example for a function like was required for `Read-SpectreText` you would need to simulate a user typing.

To generate user input you can add a `# Type` comment at the point in the example where the input is required. The example generator takes each double quoted string after the directive as a separate piece of user input, multiple inputs can be provided by separating them with a comma.

e.g.

1. `# Type "This is a test"` will type the string "This is a test" into the console with some delay between each character.
2. `# Type "This is a test", "↲"` will type the string "This is a test" and then press enter afterwards.
3. `# Type "a"` will enter a single character "a" into the console.
4. `# Type "↑", "↓", "↲", "<space>"` will press the up arrow key, down arrow key, enter, and space keys respectively.

```powershell
<#
.EXAMPLE
$favouriteColor = Read-SpectreText -Question "What's your favorite color?" -AnswerColor "Cyan1" -Choices "Black", "Green", "Magenta", "I'll never tell!"
# Type "orange", "↲", "magenta", "↲" to enter text that must match a choice in the choices list, orange will be rejected, magenta will be accepted
Write-SpectreHost "Your favourite color is '$favouriteColor'"
#>
```

See the example in action at: [https://pwshspectreconsole.com/reference/prompts/read-spectretext/](https://pwshspectreconsole.com/reference/prompts/read-spectretext/)
1 change: 1 addition & 0 deletions PwshSpectreConsole.Docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default defineConfig({
label: "Command Reference",
autogenerate: {
directory: "reference",
collapsed: true,
},
},
],
Expand Down
Loading

0 comments on commit cf58911

Please sign in to comment.