Skip to content

Conversation

@PrzemyslawKlys
Copy link
Member

Summary

  • add Convert-FileEncoding public function for converting files between encodings
  • add private helper Convert-FileEncodingSingle

Testing

  • pwsh -NoLogo -NoProfile -Command ./PSPublishModule.Tests.ps1 (fails: Write-Color/Invoke-Pester not recognized)

https://chatgpt.com/codex/tasks/task_e_684abe75f2f4832eaf9c444b86d0d485

@SamErde
Copy link
Contributor

SamErde commented Jun 12, 2025

Awesome idea. We've all done this process, so I can't believe I haven't seen a script to do it yet. Would be a great addition to an 'essentials' module.

@PrzemyslawKlys
Copy link
Member Author

Essentials as in PSSharedGoods ? :) I wanted this to be here, as I mostly will use it to cleanup my projects .. but what do you think?

@SamErde
Copy link
Contributor

SamErde commented Jun 12, 2025

Yes. For example, if I had thought of it, I would put it in PSPreworkout so I could use it any time for any project. PSPublishModule would probably catch most relevant usage scenarios, though. (And since I use PSPublishModule, this works!)

Copy link
Contributor

@SamErde SamErde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@PrzemyslawKlys
Copy link
Member Author

You know you can use ApprovedModules functionality so that if you use any module like PSSharedGoods or PSPublishModule and those modules have functions that you use internally in your modules (say PSPreworkout) it will auto "copy" those functions and relevant other functions to Private functions in that module of yours? This way you don't need to bundle or copy things on your own.

@SamErde
Copy link
Contributor

SamErde commented Jun 12, 2025

You know you can use ApprovedModules functionality so that if you use any module like PSSharedGoods or PSPublishModule and those modules have functions that you use internally in your modules (say PSPreworkout) it will auto "copy" those functions and relevant other functions to Private functions in that module of yours? This way you don't need to bundle or copy things on your own.

ApprovedModules is a function of PSPublishModule, right?

I didn't realize that it actually copies the function into the target module's PSM1 file. 👍

@PrzemyslawKlys
Copy link
Member Author

PrzemyslawKlys commented Jun 12, 2025

image
What the "Approved" does is that if it finds in your module you are using function that matches given modules it will copy it to private functions during merge in PSM1 process. It's useful so I don't have to take PSWriteColor, PSShareGoods dependency for using 5 functions in total. If there's no underlying dependnecies like html files or css file or dll library, it will work.

image
image

* Removed `Build-ModuleSimplified.ps1` as it was redundant.
* Updated comments for clarity and consistency.
* Adjusted configuration settings for improved module building.
- Introduced `Convert-ProjectEncoding` and `Convert-ProjectLineEnding` documentation.
- Added `Get-ProjectConsistency`, `Get-ProjectEncoding`, and `Get-ProjectLineEnding` documentation.
- Updated `Readme.md` to include links to new cmdlets.
- Introduced `Example.TestEncoding.ps1` to provide basic analysis of folder encoding.
- The script includes better defaults, displaying files and recommendations automatically.
- Added functionality to show encoding distribution and a beautiful summary display.
* Deleted the `Convert-FileEncoding` function from the script.
* This change may be part of a larger refactor or removal of unused functionality.
* Introduces a new function to convert files between different encodings.
* Supports various parameters for file selection, encoding types, and processing options.
* Includes detailed documentation and examples for usage.
…ed validation and rollback

* Added comprehensive validation for source and target encodings.
* Implemented backup creation before conversion for safety.
* Enhanced error handling and content verification post-conversion.
* Improved verbosity for better debugging and user feedback.
… conversion

* Introduces a new function to convert file encodings in specified folders based on file extensions.
* Supports multiple file types and includes safety features like backup creation and WhatIf support.
* Enhances user experience by providing a more intuitive interface compared to `Convert-FileEncoding`.
…rsion

* Implements a new function to convert line endings in files.
* Supports creating backups and ensuring final newlines.
* Handles empty files gracefully with a skip status.
* Implements a new function to read a file and determine its line ending type (CRLF, LF, CR, or None).
* Returns an object indicating the line ending type and whether the file has a final newline.
…oding detection logic

* Enhanced function documentation for clarity and completeness.
* Improved BOM detection order for more accurate encoding identification.
* Refined logic for distinguishing between UTF8 and ASCII based on non-ASCII character scanning.
* Introduces a new function `Get-FolderEncoding` that analyzes file encodings in specified folders based on file extensions.
* Supports single and multiple file extensions with predefined file type groups.
* Provides detailed analysis including encoding distribution, inconsistencies, and recommendations for file conversions.
* Includes parameters for path, extensions, file types, and options for excluding directories and recursion.
* Implements functionality to analyze file line endings (CRLF, LF, CR).
* Returns structured information including line ending type, final newline status, and file size.
* Handles empty files and errors gracefully.
… function

* Enhanced the documentation for the `Resolve-Encoding` function to provide clearer usage examples and descriptions.
* Reformatted the code structure for better readability and maintainability.
* Introduces a new function to convert encoding for all source files in a project directory.
* Supports various project types and includes safety features like WhatIf support, automatic backups, and detailed reporting.
* Validates input parameters and provides a summary report after processing.
…ersion

* Recursively converts line endings for various source files in a project directory.
* Includes safety features: WhatIf support, automatic backups, and detailed reporting.
* Supports conversion between CRLF (Windows) and LF (Unix/Linux) line endings.
* Allows customization of file types and exclusion of specific directories.
…ct analysis

- Provides analysis of encoding and line ending consistency across a project.
- Combines results from `Get-ProjectEncoding` and `Get-ProjectLineEnding`.
- Includes parameters for path, project type, recommended encoding, and line endings.
- Outputs detailed reports and recommendations for standardization.
…sistency

* Introduces a new function to analyze encoding across files in a project directory.
* Provides detailed reports on encoding inconsistencies and recommendations for standardization.
* Supports various project types and allows for custom file extensions.
* Includes options for exporting results to a CSV file.
…g consistency

* Introduces a new function to analyze line ending consistency across files in a project directory.
* Provides detailed reporting on line endings, including detection of mixed line endings.
* Supports various project types and allows for custom file extensions and export options.
* Refactored tests to use `Convert-ProjectEncoding` instead of `Convert-FileEncoding`.
* Added tests for encoding detection and conversion scenarios.
* Ensured proper handling of mixed content and skipped conversions when encodings do not match.
* Added `Convert-ProjectEncoding` and `Convert-ProjectLineEnding` to `FunctionsToExport`.
* Updated `ModuleVersion` from `2.0.19` to `2.0.22`.
* Implements a method to calculate relative paths between two paths.
* Ensures compatibility with PowerShell 5.1 by providing an alternative to the .NET Core method.
* Includes error handling to fallback to filename if path calculation fails.
* Added 'Any' to the list of valid encodings in the `ValidateSet`.
* Updated documentation to clarify that 'Any' returns null for conversion functions.
…oding

* Updated `.PARAMETER SourceEncoding` to allow 'Any' as a valid option.
* Modified encoding conversion logic to handle files with any encoding when 'Any' is specified.
* Improved examples in documentation for clarity on encoding behavior.
…for path resolution

* Replaced direct call to `[System.IO.Path]::GetRelativePath` with the new `Get-RelativePath` function.
* This change enhances code consistency and maintains compatibility with recent updates.
…path resolution

* Refactored the line ending analysis to utilize the `Get-RelativePath` function for improved path resolution.
* Enhances code maintainability and consistency across the module.
…th resolution

* Refactored the path resolution logic to utilize `Get-RelativePath` for improved clarity and consistency.
* Enhanced output messages to handle cases with no files found or no encoding information available.
* Introduced `Example.TestEncoding.ps1` for encoding analysis using `Get-ProjectEncoding`.
* Added `Example.TestEncodingConversion.ps1` with examples for converting files to UTF8BOM and UTF8.
* Created `Example.TestLineEnding.ps1` and `Example.TestLineEndingConversion.ps1` as placeholders for line ending tests.
…ions

* Added comprehensive examples for encoding and line ending analysis.
* Included conversion previews for both encoding and line endings.
* Ensured all examples provide clear output messages for user guidance.
* Updated `SignModule` configuration to enable signing only on the 'EVOMONSTER' machine.
* This change allows for more flexible build configurations across different environments.
@PrzemyslawKlys
Copy link
Member Author

I actually copied those file/folder based functions to PSSharedGoods so people can reuse it, but then added "project" related funcitons for new lines and encoding which makes more sense to pspublishmodule

…ncoding

* Refactored tests in `Convert-FileEncoding.Tests.ps1` to import the module with PassThru.
* Ensured access to private functions for accurate encoding verification.
* Improved test reliability by explicitly importing the module in each test case.
…ding`

* Enhanced examples to clarify encoding conversions.
* Updated parameter descriptions to reflect changes in default behavior.
* Improved test imports for better module loading.
* Removed the `Clear-Host` command from the beginning of the script.
* This change improves script execution without clearing the console unnecessarily.
@PrzemyslawKlys PrzemyslawKlys merged commit c6b5b8c into master Jul 7, 2025
3 checks passed
@PrzemyslawKlys PrzemyslawKlys deleted the create-encoding-conversion-function-in-public-folder branch August 13, 2025 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants