-
Notifications
You must be signed in to change notification settings - Fork 5
Improved Copy-ProjectResource function to copy only folder contents #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
We will merge once README is updated. |
Hi,
|
|
With the help of Copilot, I was able to figure out how to update the branch and commit the changes. Let me know what you think. The Readme.md file has been updated. Also incremented the build version. |
|
In a weird way, ModuleTools is the build tool for ModuleTools. Merging this change means I will need to rearrange the resource folder or else build will fail. I will do this soon. Also, this is a breaking change for anyone already using resources already. Need to highlight it so that they can find the info. |
|
I see the dilemma. I have a suggestion / solution. How about adding a property "CopyMode" to the project.json file to control the behavior of how the resources folder will be copied to the dist folder. The "CopyMode" behaviors are:
This way the current default behavior support the current approach required for building "ModuleTools" and provides the flexibility for using "ModuleTools" to creating personal modules that doesn't need a resources subfolder in the OutputModuleDir If the "CopyMode" property is missing or not "Content", then it defaults to the original Copy Folder. Here is what the modified Copy-ProjectResource function would look like: function Copy-ProjectResource {
$data = Get-MTProjectInfo
$resFolder = [System.IO.Path]::Join($data.ProjectRoot, 'src', 'resources')
if (Test-Path $resFolder) {
if ($data.CopyMode -eq 'Content') {
# Copy the resources folder content to the OutputModuleDir
$items = Get-ChildItem -Path $resFolder -ErrorAction SilentlyContinue
if ($items) {
Write-Verbose 'Files found in resource folder, copying resource folder content'
foreach ($item in $items) {
Copy-Item -Path $item.FullName -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop
}
}
} else {
# Copy the resources folder to the OutputModuleDir
if (Get-ChildItem $resFolder -ErrorAction SilentlyContinue) {
Write-Verbose 'Files found in resource folder, Copying resource folder'
Copy-Item -Path $resFolder -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop
}
}
}
}I will make the changes and update the documentation
|
This is event better. Way to improvise. Let me review the code and take it further. |
|
This is great work. Couple of suggestions.
Lastly, I want to handle this as a branch as this is some major changes and has potential to break production copy. Unfortunately there is no easy way to convert your pull request into branch (even chatGPT couldnt help). If you dont mind I will create a branch and you resubmit the same changes to that branch? |
|
This looks great. I have some more improvements in mind. I will simply merge these changes to main branch but wont publish the updated version to PowerShell Gallery yet. Will create another branch just to track these changes before we are ready for prod release. If you want to make any changes I recommend doing in it better |
Updated ./src/private/CopyProjectResource.ps1 by recursively copying the contents of the ./src/resources folder to the ./dist/ folder instead of copying the ./src/resources folder with it's contents.