You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🩹 [Patch]: Don't require the source code to be in a folder with name of module (#44)
## Description
- Don't require the source code to be in a folder with name of module
- Fixes #43
## Type of change
<!-- Use the check-boxes [x] on the options that are relevant. -->
- [ ] 📖 [Docs]
- [ ] 🪲 [Fix]
- [x] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [Feature]
- [ ] 🌟 [Breaking change]
## Checklist
<!-- Use the check-boxes [x] on the options that are relevant. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
Copy file name to clipboardExpand all lines: README.md
+29-35Lines changed: 29 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,41 +33,42 @@ During the build process the following steps are performed:
33
33
34
34
## Root module
35
35
36
+
The `src` folder may contain a 'root module' file. If present, the build function will disregard this file
37
+
and build a new root module file based on the source code in the module folder.
38
+
36
39
The root module file is the main file that is loaded when the module is imported.
37
40
It is built from the source code files in the module folder in the following order:
38
41
39
-
1. Adds module headers from `header.ps1`.
42
+
1. Adds module headers from `header.ps1` if it exists and removes the file from the module folder.
40
43
1. Adds data loader automation that loads files from the `data` folder as variables in the module scope, if it exists. The variables are available using the ´$script:<filename>´ syntax.
41
-
1. Adds content from subfolders, in the order:
42
-
- Init
43
-
- Private
44
-
- Public
45
-
-*.ps1 on module root
46
-
1. Adds the Export-ModuleMember function to the end of the file, to make sure that only the functions, cmdlets, variables and aliases that are defined in the module are exported.
47
-
48
-
### The root module in the `src` folder
49
-
50
-
The root module file that is included in the source files contains the same functionality but is not optimized for performance.
51
-
The goal with this is to have a quick way to import and test the module without having to build it.
44
+
1. Adds content from subfolders, if they exists, and removes them from the module folder in the following order:
45
+
-`init`
46
+
-`classes`
47
+
-`private`
48
+
-`public`
49
+
-`*.ps1` on module root
50
+
1. Adds a `class` and `enum` exporter that exports all classes and enums in the module to the caller session, using TypeAccelerators.
51
+
1. Adds the `Export-ModuleMember` function to the end of the file, to make sure that only the functions, cmdlets, variables and aliases that are defined in the module are exported.
52
52
53
53
## Module manifest
54
54
55
55
The module manifest file is the file that describes the module and its content. It is used by PowerShell to load the module and its prerequisites.
56
-
The file also contains important metadata that is used by the PowerShell Gallery.
56
+
The file also contains important metadata that is used by the PowerShell Gallery. If a file exists in the source code folder `src` it will be used as a base for the module manifest file.
57
+
Most of the values in the module manifest file are calculated during the build process however some of these will not be touched if specified in the source manifest file.
57
58
58
59
During the module manifest build process the following steps are performed:
59
60
60
-
1. Get the manifest file from the source code. Content from this file overrides any value that would be calculated based on the source code.
61
-
1.Find and set the `RootModule` based on filename and extension.
61
+
1. Get the manifest file from the source code. If it does not exist, a new manifest file is created.
62
+
1.Generate and set the `RootModule` based module name.
62
63
1. Set a temporary `ModuleVersion`, as this is set during the release process by [Publish-PSModule](https://github.com/PSModule/Publish-PSModule).
63
-
1. Set the `Author` and `CompanyName` based on GitHub Owner.
64
-
1. Set the `Copyright` information based on a default text (`(c) 2024 >>OwnerName<<. All rights reserved.`) and adds either the `Author`, `CompanyName` or both (`Author | CompanyName`) when these are different.
65
-
1. Set the `Description` based on the GitHub repository description.
66
-
1. Set various properties in the manifest such as `PowerShellHostName`, `PowerShellHostVersion`, `DotNetFrameworkVersion`, `ClrVersion`, and `ProcessorArchitecture`. There is currently no automation for these properties.
64
+
1. Set the `Author` and `CompanyName` based on GitHub Owner. If a value exists in the source manifest file, this value is used.
65
+
1. Set the `Copyright` information based on a default text (`(c) 2024 >>OwnerName<<. All rights reserved.`) and adds either the `Author`, `CompanyName` or both (`Author | CompanyName`) when these are different. If a value exists in the source manifest file, this value is used.
66
+
1. Set the `Description` based on the GitHub repository description. If a value exists in the source manifest file, this value is used.
67
+
1. Set various properties in the manifest such as `PowerShellHostName`, `PowerShellHostVersion`, `DotNetFrameworkVersion`, `ClrVersion`, and `ProcessorArchitecture`. There is currently no automation for these properties. If a value exists in the source manifest file, this value is used.
67
68
1. Get the list of files in the module source folder and set the `FileList` property in the manifest.
68
69
1. Get the list of required assemblies (`*.dll` files) from the `assemblies` folder and set the `RequiredAssemblies` property in the manifest.
69
70
1. Get the list of nested modules (`*.psm1` files) from the `modules` folder and set the `NestedModules` property in the manifest.
70
-
1. Get the list of scripts to process (`*.ps1` files) from the `classes` and `scripts` folders and set the `ScriptsToProcess` property in the manifest. This ensures that the scripts are loaded to the caller session (parent of module session).
71
+
1. Get the list of scripts to process (`*.ps1` files) from the `scripts` folders and set the `ScriptsToProcess` property in the manifest. This ensures that the scripts are loaded to the caller session (parent of module session).
71
72
1. Get the list of types to process by searching for `*.Types.ps1xml` files in the entire module source folder and set the `TypesToProcess` property in the manifest.
72
73
1. Get the list of formats to process by searching for `*.Format.ps1xml` files in the entire module source folder and set the `FormatsToProcess` property in the manifest.
73
74
1. Get the list of DSC resources to export by searching for `*.psm1` files in the `resources` folder and set the `DscResourcesToExport` property in the manifest.
@@ -76,22 +77,22 @@ During the module manifest build process the following steps are performed:
76
77
1. Gather information from source files to update `RequiredModules`, `PowerShellVersion`, and `CompatiblePSEditions` properties.
77
78
1. The following values are gathered from the GitHub repository:
78
79
-`Tags` are generated from Repository topics in addition to compatability tags gathered from the source code.
79
-
-`LicenseUri` is generated assuming there is a `LICENSE` file on the root of the repository.
80
-
-`ProjectUri` is the URL to the GitHub repository
81
-
-`IconUri` is generated assuming there is a `icon.png` file in the `icon` folder on the repository root.
80
+
-`LicenseUri` is generated assuming there is a `LICENSE` file on the root of the repository. If a value exists in the source manifest file, this value is used.
81
+
-`ProjectUri` is the URL to the GitHub repository. If a value exists in the source manifest file, this value is used.
82
+
-`IconUri` is generated assuming there is a `icon.png` file in the `icon` folder on the repository root. If a value exists in the source manifest file, this value is used.
82
83
1.`ReleaseNotes` currently not automated, but could be the PR description or release description.
83
84
1.`PreRelease` is not managed here, but is managed from [Publish-PSModule](https://github.com/PSModule/Publish-PSModule)
84
-
1.`RequireLicenseAcceptance` is not automated and defaults to `false`, and
85
-
1.`ExternalModuleDependencies` is currenlty not automated.
86
-
1.`HelpInfoURI` is not automated.
85
+
1.`RequireLicenseAcceptance` is not automated and defaults to `false`. If a value exists in the source manifest file, this value is used.
86
+
1.`ExternalModuleDependencies` is currenlty not automated. If a value exists in the source manifest file, this value is used.
87
+
1.`HelpInfoURI` is not automated. If a value exists in the source manifest file, this value is used.
87
88
1. Create a new manifest file in the output folder with the gathered info above. This also generates a new `GUID` for the module.
88
89
1. Format the manifest file using the `Set-ModuleManifest` function from the [Utilities](https://github.com/PSModule/Utilities) module.
89
90
90
91
Linking the description to the module manifest file might show more how this works:
91
92
92
93
```powershell
93
94
@{
94
-
RootModule = 'Utilities.psm1' # Get files from root of folder wher name is same as the folder and file extension is .psm1, .ps1, .psd1, .dll, .cdxml, .xaml. Error if there are multiple files that meet the criteria.
95
+
RootModule = 'Utilities.psm1' # Generated from the module name, <moduleName>.psm1
95
96
ModuleVersion = '0.0.1' # Set during release using Publish-PSModule.
96
97
CompatiblePSEditions = @() # Get from source files, REQUIRES -PSEdition <PSEdition-Name>, null if not provided.
97
98
GUID = '<GUID>' # Generated when finally saving the manifest using New-ModuleManifest.
@@ -142,16 +143,9 @@ Linking the description to the module manifest file might show more how this wor
142
143
}
143
144
```
144
145
145
-
### The module manifest in the `src` folder
146
-
147
-
The module manifest file that is included in the source files contains the same functionality but is not optimized for performance and does not automatically gather all the information that is gathered during the build process.
148
-
The goal with this is to have a quick way to import and test the module without having to build it.
149
-
150
-
The source module manifest is also the only place where some of the values can be controlled. These values are typically difficult to calculate and are not automated.
151
-
152
146
## Module documentation
153
147
154
-
The module documentation is built using platyPS and comment based help in the source code.
148
+
The module documentation is built using `platyPS` and comment based help in the source code.
155
149
The documentation is currently not published anywhere, but should be published to GitHub Pages in a future release.
0 commit comments