2026-11-15 13:21:53 +01:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Copies this shared repository's tracked files into every consumer project's vendored snapshot.
|
|
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
Consumers are found by scanning the workspace, so the folder names do not matter. A consumer is a
|
|
|
|
|
git repository, at most three folders below the workspace root, that has a 'shared' folder (or the
|
|
|
|
|
legacy snapshot folder). The workspace root defaults to the folder that contains this repository.
|
|
|
|
|
|
|
|
|
|
Without -Commit the changes are only staged in each consumer. -Commit commits them, and -Push pushes
|
|
|
|
|
each committed consumer's main branch.
|
|
|
|
|
|
|
|
|
|
.PARAMETER Consumers
|
|
|
|
|
Consumer paths relative to the workspace root, for example 'Central/ProjectConfigurator'.
|
|
|
|
|
|
|
|
|
|
.PARAMETER ConsumersFile
|
|
|
|
|
A JSON file of the form {"consumers": ["Central/ProjectConfigurator", ...]}.
|
|
|
|
|
#>
|
2026-08-06 16:09:41 +02:00
|
|
|
[CmdletBinding()]
|
|
|
|
|
param(
|
|
|
|
|
[string]$SourceRepository,
|
2026-11-15 13:21:53 +01:00
|
|
|
[string]$WorkspaceRoot,
|
2026-10-27 14:20:32 +00:00
|
|
|
[string[]]$Consumers,
|
|
|
|
|
[string]$ConsumersFile,
|
2026-08-06 16:09:41 +02:00
|
|
|
[switch]$Force,
|
|
|
|
|
[switch]$Commit,
|
|
|
|
|
[switch]$Push
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
|
|
|
|
|
|
if ($Push -and -not $Commit) {
|
|
|
|
|
throw 'The -Push switch requires -Commit so that only generated synchronization changes are pushed.'
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-27 14:20:32 +00:00
|
|
|
if ($Consumers -and $ConsumersFile) {
|
|
|
|
|
throw 'Pass either -Consumers or -ConsumersFile, not both.'
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
# The snapshot folder every consumer vendors, and the name older consumers used before it was renamed.
|
|
|
|
|
$snapshotFolder = 'shared'
|
|
|
|
|
$legacySnapshotFolder = ('Shared' + 'Code')
|
2026-10-27 14:20:32 +00:00
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
# How many folders below the workspace root a consumer may sit (Central/ProjectConfigurator is two).
|
|
|
|
|
$maxConsumerDepth = 3
|
2026-10-27 14:20:32 +00:00
|
|
|
|
2026-08-06 16:09:41 +02:00
|
|
|
function Invoke-GitText {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$WorkingDirectory,
|
|
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string[]]$Arguments
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$output = & git -C $WorkingDirectory @Arguments 2>&1
|
|
|
|
|
$exitCode = $LASTEXITCODE
|
|
|
|
|
if ($exitCode -ne 0) {
|
|
|
|
|
$diagnostics = @($output | ForEach-Object { [string]$_ } | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
|
|
|
|
|
$blockingDiagnostics = @($diagnostics | Where-Object { $_ -notmatch '^\s*(warning|hint):' })
|
|
|
|
|
if ($blockingDiagnostics.Count -eq 0) {
|
|
|
|
|
$diagnostics | ForEach-Object { Write-Warning $_ }
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$details = $diagnostics -join [Environment]::NewLine
|
|
|
|
|
throw "git $($Arguments -join ' ') failed in '$WorkingDirectory'. $details"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return @($output | ForEach-Object { [string]$_ })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Resolve-FullPath {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$Path
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
# Joins a relative path written with '/' onto a base path, using the platform's separator.
|
|
|
|
|
function Join-RelativePath {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$BasePath,
|
|
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$RelativePath
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return [IO.Path]::Combine($BasePath, $RelativePath.Replace('/', [IO.Path]::DirectorySeparatorChar))
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-06 16:09:41 +02:00
|
|
|
function Get-RelativePath {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$BasePath,
|
|
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$TargetPath
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$separator = [IO.Path]::DirectorySeparatorChar
|
|
|
|
|
$base = (Resolve-FullPath $BasePath).TrimEnd($separator) + $separator
|
2026-08-06 16:09:41 +02:00
|
|
|
$target = Resolve-FullPath $TargetPath
|
|
|
|
|
if (-not $target.StartsWith($base, [System.StringComparison]::OrdinalIgnoreCase)) {
|
|
|
|
|
throw "'$TargetPath' is not inside '$BasePath'."
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
return $target.Substring($base.Length).Replace($separator, '/')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Lists consumers as paths relative to $Root. Repositories are not searched inside, and the source
|
|
|
|
|
# repository is skipped.
|
|
|
|
|
function Find-ConsumerProjects {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$Root,
|
|
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$SourceRoot
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$found = New-Object 'System.Collections.Generic.List[string]'
|
|
|
|
|
$pending = New-Object 'System.Collections.Generic.Queue[object]'
|
|
|
|
|
$pending.Enqueue([pscustomobject]@{ Path = $Root; Depth = 0 })
|
|
|
|
|
|
|
|
|
|
while ($pending.Count -gt 0) {
|
|
|
|
|
$current = $pending.Dequeue()
|
|
|
|
|
$children = @(Get-ChildItem -LiteralPath $current.Path -Directory -Force -ErrorAction SilentlyContinue)
|
|
|
|
|
foreach ($child in $children) {
|
|
|
|
|
if ($child.Name.StartsWith('.') -or $child.Name -eq 'node_modules') {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if ($child.FullName -ieq $SourceRoot) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Test-Path -LiteralPath (Join-Path $child.FullName '.git')) {
|
|
|
|
|
$hasSnapshot = (Test-Path -LiteralPath (Join-RelativePath $child.FullName $snapshotFolder) -PathType Container) -or
|
|
|
|
|
(Test-Path -LiteralPath (Join-RelativePath $child.FullName $legacySnapshotFolder) -PathType Container)
|
|
|
|
|
if ($hasSnapshot) {
|
|
|
|
|
$found.Add((Get-RelativePath -BasePath $Root -TargetPath $child.FullName))
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($current.Depth + 1 -lt $maxConsumerDepth) {
|
|
|
|
|
$pending.Enqueue([pscustomobject]@{ Path = $child.FullName; Depth = $current.Depth + 1 })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return @($found | Sort-Object)
|
2026-08-06 16:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Write-Utf8NoBom {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$Path,
|
|
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$Content
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$encoding = New-Object System.Text.UTF8Encoding($false)
|
|
|
|
|
$normalizedContent = $Content.Replace("`r`n", "`n").Replace("`r", "`n")
|
|
|
|
|
[System.IO.File]::WriteAllText($Path, $normalizedContent, $encoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Convert-ToConsumerWebUiPackage {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$PackagePath
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$manifest = Get-Content -LiteralPath $PackagePath -Raw | ConvertFrom-Json
|
|
|
|
|
$manifest.files = @('src', 'README.md')
|
2026-08-10 13:10:54 +00:00
|
|
|
if ($null -ne $manifest.dependencies) {
|
|
|
|
|
$designTokensDependency = $manifest.dependencies.PSObject.Properties['@gabriel20xx/design-tokens']
|
|
|
|
|
if ($null -ne $designTokensDependency) {
|
|
|
|
|
$manifest.dependencies.PSObject.Properties.Remove('@gabriel20xx/design-tokens')
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-06 16:09:41 +02:00
|
|
|
$manifest.svelte = './src/index.ts'
|
|
|
|
|
$manifest.types = './src/index.ts'
|
|
|
|
|
|
|
|
|
|
$rootExport = $manifest.exports.PSObject.Properties | Where-Object { $_.Name -eq '.' }
|
|
|
|
|
if ($null -ne $rootExport) {
|
|
|
|
|
$rootExport.Value.types = './src/index.ts'
|
|
|
|
|
$rootExport.Value.svelte = './src/index.ts'
|
|
|
|
|
$rootExport.Value.import = './src/index.ts'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$stylesExport = $manifest.exports.PSObject.Properties | Where-Object { $_.Name -eq './styles.css' }
|
|
|
|
|
if ($null -ne $stylesExport) {
|
|
|
|
|
$stylesExport.Value = './src/lib/styles.css'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$json = $manifest | ConvertTo-Json -Depth 20
|
|
|
|
|
Write-Utf8NoBom -Path $PackagePath -Content ($json + [Environment]::NewLine)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Convert-ToConsumerWebUiSources {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$WebUiRoot
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$stylesPath = Join-RelativePath $WebUiRoot 'src/lib/styles.css'
|
2026-08-06 16:09:41 +02:00
|
|
|
if (Test-Path -LiteralPath $stylesPath) {
|
|
|
|
|
$styles = Get-Content -LiteralPath $stylesPath -Raw
|
|
|
|
|
$styles = $styles.Replace("@import '@gabriel20xx/design-tokens/theme.css';", "@import '../../../design-tokens/theme.css';")
|
2026-08-10 13:10:54 +00:00
|
|
|
$styles = $styles.Replace('@import "@gabriel20xx/design-tokens/theme.css";', "@import '../../../design-tokens/theme.css';")
|
2026-08-06 16:09:41 +02:00
|
|
|
Write-Utf8NoBom -Path $stylesPath -Content $styles
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$svelteConfigPath = Join-RelativePath $WebUiRoot 'svelte.config.js'
|
2026-08-06 16:09:41 +02:00
|
|
|
if (Test-Path -LiteralPath $svelteConfigPath) {
|
|
|
|
|
Write-Utf8NoBom -Path $svelteConfigPath -Content "export default {};`n"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Test-LocalSharedDependency {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
$PackageManifest
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$localPackageNames = @(
|
|
|
|
|
'@gabriel20xx/web-ui',
|
|
|
|
|
'@gabriel20xx/node-backend'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
foreach ($sectionName in @('dependencies', 'devDependencies', 'optionalDependencies')) {
|
|
|
|
|
$sectionProperty = $PackageManifest.PSObject.Properties[$sectionName]
|
|
|
|
|
if ($null -eq $sectionProperty -or $null -eq $sectionProperty.Value) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($dependency in $sectionProperty.Value.PSObject.Properties) {
|
|
|
|
|
if ($dependency.Name -in $localPackageNames -and ([string]$dependency.Value).StartsWith('file:')) {
|
|
|
|
|
return $true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $false
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
# The source must be the root of its own git repository. A consumer's snapshot is copied from this
|
|
|
|
|
# repository and has no .git folder, so running the script from inside a snapshot fails here.
|
2026-08-06 16:09:41 +02:00
|
|
|
if ([string]::IsNullOrWhiteSpace($SourceRepository)) {
|
2026-11-15 13:21:53 +01:00
|
|
|
$SourceRepository = Join-Path $PSScriptRoot '..'
|
2026-08-06 16:09:41 +02:00
|
|
|
}
|
|
|
|
|
$sourceRoot = Resolve-FullPath $SourceRepository
|
2026-11-15 13:21:53 +01:00
|
|
|
if (-not (Test-Path -LiteralPath (Join-Path $sourceRoot '.git'))) {
|
|
|
|
|
throw "'$sourceRoot' is not the root of a git repository. Pass -SourceRepository with the root of the shared repository."
|
2026-08-31 22:06:29 +02:00
|
|
|
}
|
2026-11-15 13:21:53 +01:00
|
|
|
|
|
|
|
|
# By default the workspace is the folder that holds the shared repository.
|
|
|
|
|
if ([string]::IsNullOrWhiteSpace($WorkspaceRoot)) {
|
|
|
|
|
$WorkspaceRoot = Split-Path -Parent $sourceRoot
|
|
|
|
|
}
|
|
|
|
|
$workspaceRoot = Resolve-FullPath $WorkspaceRoot
|
|
|
|
|
|
2026-08-06 16:09:41 +02:00
|
|
|
$sourceCommit = (Invoke-GitText -WorkingDirectory $sourceRoot -Arguments @('rev-parse', '--short', 'HEAD') | Select-Object -First 1).Trim()
|
|
|
|
|
$sourceFiles = @(Invoke-GitText -WorkingDirectory $sourceRoot -Arguments @('ls-files') | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
|
|
|
|
|
|
|
|
|
|
$sourceFileSet = @{}
|
|
|
|
|
foreach ($sourceFile in $sourceFiles) {
|
|
|
|
|
$sourceFileSet[$sourceFile.Replace('\', '/')] = $true
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$discoveredConsumers = @(Find-ConsumerProjects -Root $workspaceRoot -SourceRoot $sourceRoot)
|
|
|
|
|
if ($discoveredConsumers.Count -eq 0) {
|
|
|
|
|
throw "No consumer repositories with a '$snapshotFolder' folder were found under '$workspaceRoot' (searched $maxConsumerDepth folders deep)."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$requestedConsumers = $null
|
|
|
|
|
if ($ConsumersFile) {
|
|
|
|
|
$targetFile = Get-Content -LiteralPath $ConsumersFile -Raw | ConvertFrom-Json
|
|
|
|
|
if ($null -eq $targetFile.consumers) {
|
|
|
|
|
throw "'$ConsumersFile' has no 'consumers' array."
|
|
|
|
|
}
|
|
|
|
|
$requestedConsumers = @($targetFile.consumers)
|
|
|
|
|
}
|
|
|
|
|
elseif ($Consumers) {
|
|
|
|
|
$requestedConsumers = @($Consumers)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$selectedConsumers = $discoveredConsumers
|
|
|
|
|
if ($null -ne $requestedConsumers) {
|
|
|
|
|
$requestedConsumers = @($requestedConsumers | ForEach-Object { ([string]$_).Replace('\', '/').Trim('/') })
|
|
|
|
|
$unknownConsumers = @($requestedConsumers | Where-Object { $discoveredConsumers -notcontains $_ })
|
|
|
|
|
if ($unknownConsumers.Count -gt 0) {
|
|
|
|
|
throw "Unknown consumer(s): $($unknownConsumers -join ', '). Found: $($discoveredConsumers -join ', ')."
|
|
|
|
|
}
|
|
|
|
|
$selectedConsumers = @($discoveredConsumers | Where-Object { $requestedConsumers -contains $_ })
|
|
|
|
|
if ($selectedConsumers.Count -eq 0) {
|
|
|
|
|
throw 'No consumers selected; nothing to synchronize.'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Write-Host "Workspace: $workspaceRoot"
|
|
|
|
|
Write-Host "Synchronizing $($sourceFiles.Count) tracked shared files from $sourceCommit into $($selectedConsumers.Count) consumer(s):"
|
|
|
|
|
$selectedConsumers | ForEach-Object { Write-Host " $_" }
|
2026-08-06 16:09:41 +02:00
|
|
|
|
|
|
|
|
$failures = New-Object 'System.Collections.Generic.List[string]'
|
2026-11-15 13:21:53 +01:00
|
|
|
$changedConsumers = New-Object 'System.Collections.Generic.List[string]'
|
|
|
|
|
$unchangedConsumers = New-Object 'System.Collections.Generic.List[string]'
|
2026-08-06 16:09:41 +02:00
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
foreach ($relativeProject in $selectedConsumers) {
|
2026-08-06 16:09:41 +02:00
|
|
|
try {
|
2026-11-15 13:21:53 +01:00
|
|
|
$projectRoot = Resolve-FullPath (Join-RelativePath $workspaceRoot $relativeProject)
|
|
|
|
|
$destinationRoot = Join-RelativePath $projectRoot $snapshotFolder
|
|
|
|
|
|
2026-08-06 16:55:51 +02:00
|
|
|
$projectDirectories = @(Get-ChildItem -LiteralPath $projectRoot -Directory -Force)
|
2026-11-15 13:21:53 +01:00
|
|
|
$destinationEntry = $projectDirectories | Where-Object { $_.Name -ceq $snapshotFolder }
|
|
|
|
|
$legacyEntry = $projectDirectories | Where-Object { $_.Name -ceq $legacySnapshotFolder }
|
2026-08-06 16:55:51 +02:00
|
|
|
if ($null -ne $destinationEntry -and $null -ne $legacyEntry) {
|
2026-11-15 13:21:53 +01:00
|
|
|
throw "Both $snapshotFolder and the legacy snapshot directory exist. Remove the legacy directory before synchronizing."
|
2026-08-06 16:55:51 +02:00
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$dirtyDestination = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $snapshotFolder))
|
|
|
|
|
$dirtyLegacy = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $legacySnapshotFolder))
|
2026-10-19 21:14:31 +00:00
|
|
|
$hasLocalChanges = $dirtyDestination.Count -gt 0 -or $dirtyLegacy.Count -gt 0
|
|
|
|
|
if ($hasLocalChanges -and -not $Force) {
|
2026-11-15 13:21:53 +01:00
|
|
|
throw "$snapshotFolder has local changes. Commit them or rerun with -Force."
|
2026-08-06 16:55:51 +02:00
|
|
|
}
|
2026-10-19 21:14:31 +00:00
|
|
|
if ($hasLocalChanges) {
|
|
|
|
|
# -Force replaces the snapshot, so keep a copy of what it replaces first.
|
|
|
|
|
$backupRoot = Join-Path ([IO.Path]::GetTempPath()) ('shared-sync-backup-' + [Guid]::NewGuid().ToString('N'))
|
|
|
|
|
New-Item -ItemType Directory -Force -Path $backupRoot | Out-Null
|
|
|
|
|
foreach ($existingEntry in @($destinationEntry, $legacyEntry) | Where-Object { $null -ne $_ }) {
|
|
|
|
|
Copy-Item -LiteralPath $existingEntry.FullName -Destination (Join-Path $backupRoot $existingEntry.Name) -Recurse -Force
|
|
|
|
|
}
|
2026-11-15 13:21:53 +01:00
|
|
|
Write-Host " Backed up the local $snapshotFolder changes in $relativeProject to $backupRoot before overwriting."
|
2026-10-19 21:14:31 +00:00
|
|
|
}
|
2026-08-06 16:55:51 +02:00
|
|
|
|
|
|
|
|
if ($null -ne $legacyEntry) {
|
|
|
|
|
$temporaryRenamePath = Join-Path $projectRoot ('.shared-sync-rename-' + [Guid]::NewGuid().ToString('N'))
|
|
|
|
|
Move-Item -LiteralPath $legacyEntry.FullName -Destination $temporaryRenamePath
|
|
|
|
|
Move-Item -LiteralPath $temporaryRenamePath -Destination $destinationRoot
|
2026-08-06 16:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
New-Item -ItemType Directory -Force -Path $destinationRoot | Out-Null
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$existingDestinationFiles = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', $snapshotFolder) |
|
|
|
|
|
Where-Object { $_.StartsWith("$snapshotFolder/", [System.StringComparison]::Ordinal) })
|
2026-09-01 11:21:21 +02:00
|
|
|
foreach ($existingDestinationFile in $existingDestinationFiles) {
|
2026-11-15 13:21:53 +01:00
|
|
|
$relativeDestinationFile = $existingDestinationFile.Substring($snapshotFolder.Length + 1).Replace('\', '/')
|
2026-09-01 11:21:21 +02:00
|
|
|
if (-not $sourceFileSet.ContainsKey($relativeDestinationFile)) {
|
2026-11-15 13:21:53 +01:00
|
|
|
$stalePath = Join-RelativePath $destinationRoot $relativeDestinationFile
|
2026-08-06 16:09:41 +02:00
|
|
|
if (Test-Path -LiteralPath $stalePath -PathType Leaf) {
|
|
|
|
|
Remove-Item -LiteralPath $stalePath -Force
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($sourceFile in $sourceFiles) {
|
2026-11-15 13:21:53 +01:00
|
|
|
$sourcePath = Join-RelativePath $sourceRoot $sourceFile
|
|
|
|
|
$destinationPath = Join-RelativePath $destinationRoot $sourceFile
|
2026-08-06 16:09:41 +02:00
|
|
|
$destinationDirectory = Split-Path -Parent $destinationPath
|
|
|
|
|
New-Item -ItemType Directory -Force -Path $destinationDirectory | Out-Null
|
|
|
|
|
Copy-Item -LiteralPath $sourcePath -Destination $destinationPath -Force
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$webUiPackagePath = Join-RelativePath $destinationRoot 'packages/web-ui/package.json'
|
2026-08-06 16:09:41 +02:00
|
|
|
if (Test-Path -LiteralPath $webUiPackagePath) {
|
|
|
|
|
Convert-ToConsumerWebUiPackage -PackagePath $webUiPackagePath
|
2026-11-15 13:21:53 +01:00
|
|
|
Convert-ToConsumerWebUiSources -WebUiRoot (Join-RelativePath $destinationRoot 'packages/web-ui')
|
2026-08-06 16:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$lockFiles = @()
|
2026-11-15 13:21:53 +01:00
|
|
|
$separator = [IO.Path]::DirectorySeparatorChar
|
|
|
|
|
$sharedPrefix = (Resolve-FullPath $destinationRoot).TrimEnd($separator) + $separator
|
2026-08-06 16:09:41 +02:00
|
|
|
$packageFiles = @(Get-ChildItem -LiteralPath $projectRoot -Recurse -File -Filter 'package.json' -Force |
|
|
|
|
|
Where-Object {
|
2026-11-15 13:21:53 +01:00
|
|
|
-not $_.FullName.StartsWith($sharedPrefix, [System.StringComparison]::OrdinalIgnoreCase) -and
|
|
|
|
|
$_.FullName -notmatch '[\\/]node_modules[\\/]'
|
2026-08-06 16:09:41 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
foreach ($packageFile in $packageFiles) {
|
|
|
|
|
$packageManifest = Get-Content -LiteralPath $packageFile.FullName -Raw | ConvertFrom-Json
|
|
|
|
|
if (-not (Test-LocalSharedDependency -PackageManifest $packageManifest)) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$lockPath = Join-Path $packageFile.DirectoryName 'package-lock.json'
|
|
|
|
|
if (-not (Test-Path -LiteralPath $lockPath -PathType Leaf)) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$relativeLockPath = Get-RelativePath -BasePath $projectRoot -TargetPath $lockPath
|
|
|
|
|
$trackedLock = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', $relativeLockPath))
|
|
|
|
|
$shouldStageLock = $trackedLock.Count -gt 0
|
2026-11-15 13:21:53 +01:00
|
|
|
Write-Host " Updating $relativeProject/$relativeLockPath"
|
2026-08-06 16:09:41 +02:00
|
|
|
Push-Location -LiteralPath $packageFile.DirectoryName
|
|
|
|
|
try {
|
|
|
|
|
& npm install --package-lock-only --ignore-scripts --prefer-offline
|
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
|
throw "npm install --package-lock-only failed with exit code $LASTEXITCODE."
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
Pop-Location
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($shouldStageLock -and $lockFiles -notcontains $relativeLockPath) {
|
|
|
|
|
$lockFiles += $relativeLockPath
|
|
|
|
|
}
|
|
|
|
|
elseif (-not $shouldStageLock) {
|
|
|
|
|
Write-Host " Leaving untracked/ignored lockfile out of the generated commit: $relativeLockPath"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $snapshotFolder)
|
2026-08-06 16:09:41 +02:00
|
|
|
foreach ($lockFile in $lockFiles) {
|
|
|
|
|
$null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $lockFile)
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
$targetPaths = @($snapshotFolder) + $lockFiles
|
2026-08-06 16:09:41 +02:00
|
|
|
$stagedChanges = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments (@('diff', '--cached', '--name-only', '--') + $targetPaths))
|
|
|
|
|
if ($Commit -and $stagedChanges.Count -gt 0) {
|
2026-11-15 13:21:53 +01:00
|
|
|
$commitMessage = "Sync $snapshotFolder snapshot from $sourceCommit"
|
2026-08-06 16:09:41 +02:00
|
|
|
$commitArguments = @('commit', '--only', '-m', $commitMessage, '--') + $targetPaths
|
|
|
|
|
$commitOutput = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments $commitArguments)
|
|
|
|
|
$commitOutput | ForEach-Object { Write-Host " $_" }
|
|
|
|
|
$remainingStagedChanges = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments (@('diff', '--cached', '--name-only', '--') + $targetPaths))
|
|
|
|
|
if ($remainingStagedChanges.Count -gt 0) {
|
|
|
|
|
throw 'The generated synchronization changes remain staged after the commit.'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($Push) {
|
|
|
|
|
$pushOutput = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('push', 'origin', 'main'))
|
|
|
|
|
$pushOutput | ForEach-Object { Write-Host " $_" }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($stagedChanges.Count -gt 0) {
|
2026-11-15 13:21:53 +01:00
|
|
|
$changedConsumers.Add($relativeProject)
|
2026-08-06 16:09:41 +02:00
|
|
|
Write-Host "Synced $relativeProject."
|
|
|
|
|
}
|
|
|
|
|
else {
|
2026-11-15 13:21:53 +01:00
|
|
|
$unchangedConsumers.Add($relativeProject)
|
2026-08-06 16:09:41 +02:00
|
|
|
Write-Host "$relativeProject is already synchronized."
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
$message = "${relativeProject}: $($_.Exception.Message)"
|
|
|
|
|
$failures.Add($message)
|
|
|
|
|
Write-Warning $message
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-15 13:21:53 +01:00
|
|
|
Write-Host ''
|
|
|
|
|
Write-Host "Changed: $($changedConsumers.Count); already synchronized: $($unchangedConsumers.Count); failed: $($failures.Count)."
|
|
|
|
|
|
2026-08-06 16:09:41 +02:00
|
|
|
if ($failures.Count -gt 0) {
|
2026-08-06 16:55:51 +02:00
|
|
|
throw "shared synchronization failed for $($failures.Count) project(s): $($failures -join '; ')"
|
2026-08-06 16:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-06 16:55:51 +02:00
|
|
|
Write-Host 'shared synchronization completed.'
|