Skip to content
54 changes: 54 additions & 0 deletions Tools/Get-LatestAddedSamples.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Define the folder containing the WinUIGallery relative to the script location
$ControlPages = Join-Path -Path $PSScriptRoot -ChildPath "..\WinUIGallery\ControlPages"

# Path to the ControlPages folder from repository root
$ControlPagesInRepo = "WinUIGallery/ControlPages"

# Retrieve the list of files in the folder with their details
$filesWithDetails = git ls-tree -r HEAD --name-only $ControlPages | ForEach-Object {
$file = $_ # Current file path from the git tree

# Check if the file is directly under the $currentFolder and not in subdirectories
if ($file -match "^$ControlPagesInRepo/[^/]+$") {
# Get the date of the first commit where the file was added (diff-filter A means "added")
$firstAddCommit = git log --diff-filter=A --reverse --format="%ai" -- $file | Select-Object -First 1

# If the file has an add commit (i.e., it's not a new file)
if ($firstAddCommit) {
# Create a custom object with file name and its first added commit date
[PSCustomObject]@{
File = $file.Substring($ControlPagesInRepo.Length + 1) # Remove the folder path to get the file name
FirstAddCommitDate = $firstAddCommit # Date of the first commit where the file was added
}
}
}
}

# Sort the files by their first add commit date in descending order (most recent first)
$sortedFiles = $filesWithDetails | Sort-Object FirstAddCommitDate -Descending

# Create a hashtable to cache processed file base names to avoid duplicates
$cachedBaseNames = @{ }

# Initialize the output string for the latest added samples
$LatestAddeddSamples = "Latest Added Samples:`n"

# Process the sorted files
$sortedFiles | ForEach-Object {
# Remove file extensions and standardize the file name
$fileName = $_.File -replace '\.xaml\.cs$', '' -replace '\.xaml$', ''
$fileName = $fileName -replace 'Page$', ''
$date = $_.FirstAddCommitDate

# Add the file to the output if it hasn't been cached yet (to avoid duplicates)
if (-not $cachedBaseNames.Contains($fileName)) {
$cachedBaseNames[$fileName] = $true # Mark the file name as cached
$LatestAddeddSamples += $fileName + " (" + $date + ")`n" # Append the file name to the output list
}
}

# Output the list of the latest added samples
Write-Output $LatestAddeddSamples

# Wait for the user to press Enter before closing the PowerShell window
Read-Host -Prompt "Press Enter to exit"
56 changes: 56 additions & 0 deletions Tools/Get-LatestUpdatedSamples.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Define the folder containing the WinUIGallery relative to the script location
$ControlPages = Join-Path -Path $PSScriptRoot -ChildPath "..\WinUIGallery\ControlPages"

# Path to the ControlPages folder from repository root
$ControlPagesInRepo = "WinUIGallery/ControlPages"

# Retrieve the list of files in the folder with their details
$filesWithDetails = git ls-tree -r HEAD --name-only $ControlPages | ForEach-Object {
$file = $_ # Current file path from the git tree

# Check if the file is directly under the $currentFolder and not in subdirectories
if ($file -match "^$ControlPagesInRepo/[^/]+$") {
# Get the last commit date for the file
$lastCommitDate = git log -1 --format="%ai" -- $file

# Get the commit status for the file (checks if it was modified in the last commit)
$commitStatus = git log -1 --name-status -- $file | Select-String -Pattern "^M" | ForEach-Object { $_.Line.Split()[0] }

# If the file was modified ("M"), create a custom object with file details
if ($commitStatus -eq "M") {
[PSCustomObject]@{
File = $file.Substring($ControlPagesInRepo.Length + 1) # Trim the folder path to get the file name
LastCommitDate = $lastCommitDate # Last commit date for the file
}
}
}
}

# Sort the files by the last commit date in descending order
$sortedFiles = $filesWithDetails | Sort-Object LastCommitDate -Descending

# Create a hashtable to cache processed file base names to avoid duplicates
$cachedBaseNames = @{ }

# Initialize the output string for the latest updated samples
$LatestUpdatedSamples = "Latest Updated Samples:`n"

# Process the sorted files
$sortedFiles | ForEach-Object {
# Remove file extensions and standardize the file name
$fileName = $_.File -replace '\.xaml\.cs$', '' -replace '\.xaml$', ''
$fileName = $fileName -replace 'Page$', ''
$date = $_.LastCommitDate

# Add the file to the output if it hasn't been cached yet
if (-not $cachedBaseNames.Contains($fileName)) {
$cachedBaseNames[$fileName] = $true # Mark the file name as cached
$LatestUpdatedSamples += $fileName + " (" + $date + ")`n" # Append the file name to the output
}
}

# Output the list of latest updated samples
Write-Output $LatestUpdatedSamples

# Wait for the user to press Enter before closing the PowerShell window
Read-Host -Prompt "Press Enter to exit"
37 changes: 37 additions & 0 deletions Tools/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Tools Folder

The Tools folder contains a set of tools and utilities that are repeatedly used by developers to assist in managing and developing the WinUI Gallery. These tools streamline various development tasks, providing functionality to track, manage, and organize files within the repository.

> **Note**: Before running any PowerShell script, you must set the execution policy to allow locally created scripts to run. Use the following command to set the policy:
>
> ```powershell
> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
> ```
> This ensures that PowerShell scripts downloaded from the internet are not run unless they are signed by a trusted publisher, while locally created scripts are allowed to run.


## Running scripts

#### 1st Way: From File Explorer
- Step 1: Navigate to the `Tools` folder.
- Step 2: Right-click the `Get-LatestAddedSamples.ps1` script and select **Run with PowerShell**.
- Step 3: The script will output a list of newly added files along with their first commit dates.

#### 2nd Way: From Visual Studio
- Step 1: Open `WinUIGallery` project in Visual Studio.
- Step 2: Navigate to the **Tools** menu and select **Open PowerShell Window**.
- Step 3: In the PowerShell window, type the following command:
```powershell
..\Tools\Get-LatestAddedSamples.ps1
```
- Step 4: The script will output the list of added files.

## Scripts

### Get-LatestAddedSamples tool

The goal of the `Get-LatestAddedSamples.ps1` script is to assist developers in identifying newly added files in the `ControlPages` directory, along with the date of their first commit. This helps in tracking the progress of new additions to the project and identifying which samples should be included on the home page, ensuring that the most recent content is always showcased.

### Get-LatestUpdatedSamples tool

The goal of the `Get-LatestUpdatedSamples.ps1` script is to help developers quickly identify files in the `ControlPages` directory that have been updated, along with their last commit dates. This information is useful for tracking changes made to the project, ensuring that developers can monitor updates to existing samples, and identifying which updated samples might need to be showcased on the home page.
Loading