Skip to content

Conversation

@BrooksV
Copy link
Contributor

@BrooksV BrooksV commented Feb 2, 2025

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.

@belibug
Copy link
Owner

belibug commented Feb 4, 2025

We will merge once README is updated.

@BrooksV
Copy link
Contributor Author

BrooksV commented Feb 4, 2025

We will merge once README is updated.

Hi,
I am relatively new at git and github. Not sure how to add changes to the pull request. Do I create a new branch for the changes to the readme file and merge with the "update-copy-projectresource" branch then create a new Pull Request?

  • Brooks

@BrooksV
Copy link
Contributor Author

BrooksV commented Feb 4, 2025

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.

@belibug
Copy link
Owner

belibug commented Feb 20, 2025

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.

@BrooksV
Copy link
Contributor Author

BrooksV commented Feb 20, 2025

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:

  • "Folder" -- Copies the resources folder and its content to the OutputModuleDir
  • "Content" -- Copies the resources folder content to the OutputModuleDir

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

  • Brooks

@belibug
Copy link
Owner

belibug commented Feb 21, 2025

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.

This is event better. Way to improvise. Let me review the code and take it further.

@belibug
Copy link
Owner

belibug commented Feb 21, 2025

This is great work. Couple of suggestions.

  • Change CopyMode to ResourceCopyMode to make it more descriptive
  • Did you validate what happens when data.CopyMode field is not defined in project.json? So that older projects doesn't break if this field is not defined.

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?

@belibug
Copy link
Owner

belibug commented Feb 25, 2025

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 resource-handling branch once its created.

@belibug belibug merged commit 0b19ead into belibug:main Feb 25, 2025
1 check passed
belibug added a commit that referenced this pull request Feb 25, 2025
This reverts commit 0b19ead, reversing
changes made to ebcd978.

Tracking these changes as new branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants