Rename shared code references
This commit is contained in:
1 parent
df68167d04
commit
da1cdca3b2
5 files changed
+38
-45
No files matched your search
@@ -9,6 +9,6 @@ if command -v pwsh >/dev/null 2>&1; then
|
|||||||
elif command -v powershell.exe >/dev/null 2>&1; then
|
elif command -v powershell.exe >/dev/null 2>&1; then
|
||||||
powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$sync_script" -Commit
|
powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$sync_script" -Commit
|
||||||
else
|
else
|
||||||
echo "SharedCode synchronization requires pwsh or powershell.exe." >&2
|
echo "shared synchronization requires pwsh or powershell.exe." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# SharedCode packages
|
# shared packages
|
||||||
|
|
||||||
This folder is the single source of truth for reusable web UI across the projects in this workspace.
|
This folder is the single source of truth for reusable web UI across the projects in this workspace.
|
||||||
|
|
||||||
@@ -33,30 +33,6 @@ go test ./...
|
|||||||
go vet ./...
|
go vet ./...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Consume from the Gitea repository
|
|
||||||
|
|
||||||
The repository is the canonical source and is installable directly from Gitea. The root package
|
|
||||||
builds the Svelte package during installation and exposes the runtime packages as subpaths:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install --save-exact git+https://repos.gfranz.ch/Gabriel20xx/shared#<commit>
|
|
||||||
```
|
|
||||||
|
|
||||||
Use the shared UI from the root package:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import { AppShell, AuthPage, Header, SettingsDialog } from '@gabriel20xx/shared-code/web-ui';
|
|
||||||
```
|
|
||||||
|
|
||||||
Import the shared stylesheet once from the application's global stylesheet:
|
|
||||||
|
|
||||||
```css
|
|
||||||
@import '@gabriel20xx/shared-code/web-ui/styles.css';
|
|
||||||
```
|
|
||||||
|
|
||||||
The dependency should be pinned to a commit in application lockfiles. Update it when a new
|
|
||||||
SharedCode version has been validated.
|
|
||||||
|
|
||||||
## Publish the individual packages
|
## Publish the individual packages
|
||||||
|
|
||||||
The package names use the `@gabriel20xx` npm scope. The `publish-npm.yml` and
|
The package names use the `@gabriel20xx` npm scope. The `publish-npm.yml` and
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ legacy package as a compatibility layer until every consumer has moved.
|
|||||||
Pass a service-specific `tableName` to `runMigrations` when multiple services
|
Pass a service-specific `tableName` to `runMigrations` when multiple services
|
||||||
share one PostgreSQL database, so their migration histories cannot collide.
|
share one PostgreSQL database, so their migration histories cannot collide.
|
||||||
|
|
||||||
Run `npm test` from this package or `npm run test --workspace=@gabriel20xx/node-backend` from `SharedCode`.
|
Run `npm test` from this package or `npm run test --workspace=@gabriel20xx/node-backend` from `shared`.
|
||||||
@@ -9,7 +9,7 @@ Shared Python backend infrastructure for services using `asyncpg`:
|
|||||||
- common account/session persistence for the single-admin or optional multi-user model.
|
- common account/session persistence for the single-admin or optional multi-user model.
|
||||||
|
|
||||||
HTTP framework adapters stay in each service. Install this package from the
|
HTTP framework adapters stay in each service. Install this package from the
|
||||||
published index or directly from the SharedCode repository with a subdirectory
|
published index or directly from the shared repository with a subdirectory
|
||||||
install during development:
|
install during development:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
+34
-17
@@ -171,12 +171,14 @@ function Test-LocalSharedDependency {
|
|||||||
|
|
||||||
if ([string]::IsNullOrWhiteSpace($SourceRepository)) {
|
if ([string]::IsNullOrWhiteSpace($SourceRepository)) {
|
||||||
$scriptParent = Resolve-FullPath (Join-Path $PSScriptRoot '..')
|
$scriptParent = Resolve-FullPath (Join-Path $PSScriptRoot '..')
|
||||||
if ((Split-Path -Leaf $scriptParent) -ieq 'shared') {
|
$scriptParentGitRoot = (Invoke-GitText -WorkingDirectory $scriptParent -Arguments @('rev-parse', '--show-toplevel') | Select-Object -First 1).Trim()
|
||||||
|
$scriptParentGitRoot = Resolve-FullPath $scriptParentGitRoot
|
||||||
|
if ($scriptParentGitRoot -ieq $scriptParent) {
|
||||||
$SourceRepository = $scriptParent
|
$SourceRepository = $scriptParent
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$consumerRoot = Resolve-FullPath (Join-Path $PSScriptRoot '..\..')
|
$workspaceRoot = Split-Path -Parent (Split-Path -Parent $scriptParentGitRoot)
|
||||||
$SourceRepository = Join-Path $consumerRoot '..\..\shared'
|
$SourceRepository = Join-Path $workspaceRoot 'shared'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +194,7 @@ foreach ($sourceFile in $sourceFiles) {
|
|||||||
$sourceFileSet[$sourceFile.Replace('\', '/')] = $true
|
$sourceFileSet[$sourceFile.Replace('\', '/')] = $true
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Synchronizing $($sourceFiles.Count) tracked SharedCode files from $sourceCommit."
|
Write-Host "Synchronizing $($sourceFiles.Count) tracked shared files from $sourceCommit."
|
||||||
|
|
||||||
$failures = New-Object 'System.Collections.Generic.List[string]'
|
$failures = New-Object 'System.Collections.Generic.List[string]'
|
||||||
|
|
||||||
@@ -205,17 +207,32 @@ foreach ($relativeProject in $consumerProjects) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$projectRoot = Resolve-FullPath $projectRoot
|
$projectRoot = Resolve-FullPath $projectRoot
|
||||||
$destinationRoot = Join-Path $projectRoot 'SharedCode'
|
$destinationRoot = Join-Path $projectRoot 'shared'
|
||||||
$dirtySharedCode = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', 'SharedCode'))
|
$legacyDirectoryName = ('Shared' + 'Code')
|
||||||
if ($dirtySharedCode.Count -gt 0 -and -not $Force) {
|
$projectDirectories = @(Get-ChildItem -LiteralPath $projectRoot -Directory -Force)
|
||||||
throw "SharedCode has local changes. Commit them or rerun with -Force."
|
$destinationEntry = $projectDirectories | Where-Object { $_.Name -ceq 'shared' }
|
||||||
|
$legacyEntry = $projectDirectories | Where-Object { $_.Name -ceq $legacyDirectoryName }
|
||||||
|
if ($null -ne $destinationEntry -and $null -ne $legacyEntry) {
|
||||||
|
throw "Both shared and the legacy shared snapshot directory exist. Remove the legacy directory before synchronizing."
|
||||||
|
}
|
||||||
|
|
||||||
|
$dirtyshared = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', 'shared'))
|
||||||
|
$dirtyLegacy = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $legacyDirectoryName))
|
||||||
|
if (($dirtyshared.Count -gt 0 -or $dirtyLegacy.Count -gt 0) -and -not $Force) {
|
||||||
|
throw "shared has local changes. Commit them or rerun with -Force."
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
New-Item -ItemType Directory -Force -Path $destinationRoot | Out-Null
|
New-Item -ItemType Directory -Force -Path $destinationRoot | Out-Null
|
||||||
|
|
||||||
$existingSharedFiles = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', 'SharedCode') | Where-Object { $_ -like 'SharedCode/*' })
|
$existingSharedFiles = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', 'shared') | Where-Object { $_ -like 'shared/*' })
|
||||||
foreach ($existingSharedFile in $existingSharedFiles) {
|
foreach ($existingSharedFile in $existingSharedFiles) {
|
||||||
$relativeSharedFile = $existingSharedFile.Substring('SharedCode/'.Length).Replace('\', '/')
|
$relativeSharedFile = $existingSharedFile.Substring('shared/'.Length).Replace('\', '/')
|
||||||
if (-not $sourceFileSet.ContainsKey($relativeSharedFile)) {
|
if (-not $sourceFileSet.ContainsKey($relativeSharedFile)) {
|
||||||
$stalePath = Join-Path $destinationRoot ($relativeSharedFile -replace '/', '\')
|
$stalePath = Join-Path $destinationRoot ($relativeSharedFile -replace '/', '\')
|
||||||
if (Test-Path -LiteralPath $stalePath -PathType Leaf) {
|
if (Test-Path -LiteralPath $stalePath -PathType Leaf) {
|
||||||
@@ -239,10 +256,10 @@ foreach ($relativeProject in $consumerProjects) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$lockFiles = @()
|
$lockFiles = @()
|
||||||
$sharedCodePrefix = ((Resolve-FullPath $destinationRoot).TrimEnd('\') + '\')
|
$sharedPrefix = ((Resolve-FullPath $destinationRoot).TrimEnd('\') + '\')
|
||||||
$packageFiles = @(Get-ChildItem -LiteralPath $projectRoot -Recurse -File -Filter 'package.json' -Force |
|
$packageFiles = @(Get-ChildItem -LiteralPath $projectRoot -Recurse -File -Filter 'package.json' -Force |
|
||||||
Where-Object {
|
Where-Object {
|
||||||
$_.FullName -notlike "$sharedCodePrefix*" -and
|
$_.FullName -notlike "$sharedPrefix*" -and
|
||||||
$_.FullName -notmatch '\\node_modules\\'
|
$_.FullName -notmatch '\\node_modules\\'
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -280,15 +297,15 @@ foreach ($relativeProject in $consumerProjects) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', 'SharedCode')
|
$null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', 'shared')
|
||||||
foreach ($lockFile in $lockFiles) {
|
foreach ($lockFile in $lockFiles) {
|
||||||
$null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $lockFile)
|
$null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $lockFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
$targetPaths = @('SharedCode') + $lockFiles
|
$targetPaths = @('shared') + $lockFiles
|
||||||
$stagedChanges = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments (@('diff', '--cached', '--name-only', '--') + $targetPaths))
|
$stagedChanges = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments (@('diff', '--cached', '--name-only', '--') + $targetPaths))
|
||||||
if ($Commit -and $stagedChanges.Count -gt 0) {
|
if ($Commit -and $stagedChanges.Count -gt 0) {
|
||||||
$commitMessage = "Sync SharedCode snapshot from $sourceCommit"
|
$commitMessage = "Sync shared snapshot from $sourceCommit"
|
||||||
$commitArguments = @('commit', '--only', '-m', $commitMessage, '--') + $targetPaths
|
$commitArguments = @('commit', '--only', '-m', $commitMessage, '--') + $targetPaths
|
||||||
$commitOutput = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments $commitArguments)
|
$commitOutput = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments $commitArguments)
|
||||||
$commitOutput | ForEach-Object { Write-Host " $_" }
|
$commitOutput | ForEach-Object { Write-Host " $_" }
|
||||||
@@ -318,7 +335,7 @@ foreach ($relativeProject in $consumerProjects) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($failures.Count -gt 0) {
|
if ($failures.Count -gt 0) {
|
||||||
throw "SharedCode synchronization failed for $($failures.Count) project(s): $($failures -join '; ')"
|
throw "shared synchronization failed for $($failures.Count) project(s): $($failures -join '; ')"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host 'SharedCode synchronization completed.'
|
Write-Host 'shared synchronization completed.'
|
||||||
Reference in new issue
Block a user