Skip to content

Latest commit

 

History

History
142 lines (104 loc) · 4.08 KB

Readme.md

File metadata and controls

142 lines (104 loc) · 4.08 KB

docs.PsCraft

This PowerShell module is a toolbox to streamline the process of building and distributing PowerShell modules.
it_just_works

Sometimes I just want something to work and not to have think about it.

To focus on writing code and not get bogged down in intricacies of the build process.

This module aims to eliminate the need to write and test build scripts The only code you are expected to write is in Public functions and Tests.

😔 Tests have to be written by humans. There's just no other way.

The goal is to give you a starting point that just works.

All you need to do is run 3 commands minimum, then let an LLM take care of the rest.

Using PsCraft

First make sure you install and Import the module.

Import-Module PsCraft

Create a module:

New-PsModule -Name MyModule

Image

References

The structure used by this module is based on official documentation.

Practical Module Development concepts like separating functionality into directories, along with modular imports, are practical tips shared in blog posts and forums and various developer blogs.

Misc

  1. Sign your scripts
Add-Signature -File MyNewScript.ps1
  1. Create GUIs

Yes you can create a GUI dor your scripts even on Linux using PowerShell.

Add-GUI -Script MyNewScript.ps1

[WIP] ...

todo: fix Unresolved bugs:

  1. remove any invisible characters from repo.

Example: removing any invisible Chars

function Remove-InvisibleChars {
    <#
    .SYNOPSIS
    Removes invisible characters from all files in the current directory and subdirectories.

    .NOTES
    - Written by chatgpt for Linux.
    - Requires `sed` or appropriate substitution tool.
    #>
    [CmdletBinding()]
    param (
        [string[]]$chars = @(
          "`x00", # Null
          "`x01", # Start of Header
          "`x02", # Start of Text
          "`x03", # End of Text
          "`x09", # Horizontal Tab
          "`x0B", # Vertical Tab
          "`x0C"  # Form Feed
        )
    )

    # Retrieve all files recursively
    $files = Get-ChildItem -File -Recurse -Force

    foreach ($file in $files) {
        Write-Verbose "Processing file: $($file.FullName)"

        # Read content of the file
        $content = Get-Content -Raw -Path $file.FullName

        # Remove invisible characters
        foreach ($char in $chars) {
            $charValue = [char][byte]($char -replace '`x', '0x')
            $content = $content -replace [regex]::Escape($charValue), ''
        }

        # Save the cleaned content back to the file
        $cleanFilePath = [System.IO.Path]::Combine($file.DirectoryName, "$($file.BaseName)_clean$($file.Extension)")
        Set-Content -Path $cleanFilePath -Value $content
    }

    # Optionally delete old files and rename cleaned files
    foreach ($file in $files) {
        $cleanFilePath = [System.IO.Path]::Combine($file.DirectoryName, "$($file.BaseName)_clean$($file.Extension)")
        if (Test-Path $cleanFilePath) {
            Remove-Item -Path $file.FullName -Verbose
            Rename-Item -Path $cleanFilePath -NewName $file.Name -Verbose
        }
    }
}