Add Git-installable shared code package
Lint / Lint (Go) (push) Successful in 31s
Lint / Lint (Python) (push) Successful in 9s
Tests / Test (Node/Svelte) (push) Successful in 14s
Tests / Test (Go) (push) Successful in 14s
Tests / Test (Python) (push) Successful in 16s
Lint / Lint (Node/Svelte) (push) Successful in 13s

This commit is contained in:
Gabriel20xx committed 2026-08-04 15:38:26 +02:00
1 parent fbbdab49bc
commit 4baa4dccd7
5 files changed
+654 -6

No files matched your search

+26 -2
View File
@@ -33,7 +33,31 @@ go test ./...
go vet ./... go vet ./...
``` ```
## Publish the packages ## 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/SharedCode.git#<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
The package names use the `@gabriel20xx` npm scope. That scope must belong to the npm account used to publish. If a different scope is preferred, replace the scope consistently in both package manifests and imports before publishing. The package names use the `@gabriel20xx` npm scope. That scope must belong to the npm account used to publish. If a different scope is preferred, replace the scope consistently in both package manifests and imports before publishing.
@@ -48,7 +72,7 @@ npm publish --workspace=@gabriel20xx/node-backend --access public
For a private registry, configure that registry and omit `--access public` if the registry does not use npm's public scoped-package rules. For a private registry, configure that registry and omit `--access public` if the registry does not use npm's public scoped-package rules.
## Install in a project ## Install individual packages from a registry
From a project's frontend directory, install the published UI package: From a project's frontend directory, install the published UI package:
+8 -2
View File
@@ -1,13 +1,19 @@
{ {
"name": "@gabriel20xx/shared-workspace", "name": "@gabriel20xx/shared-code",
"version": "0.1.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@gabriel20xx/shared-workspace", "name": "@gabriel20xx/shared-code",
"version": "0.1.0",
"license": "MIT",
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
], ],
"dependencies": {
"pg": "^8.17.2"
},
"devDependencies": { "devDependencies": {
"@changesets/cli": "^2.29.8" "@changesets/cli": "^2.29.8"
} }
+35 -2
View File
@@ -1,7 +1,36 @@
{ {
"name": "@gabriel20xx/shared-workspace", "name": "@gabriel20xx/shared-code",
"private": true, "version": "0.1.0",
"description": "Shared UI and backend packages for Gabriel20xx projects.",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://repos.gfranz.ch/Gabriel20xx/SharedCode.git"
},
"type": "module", "type": "module",
"files": [
"README.md",
"shared-styles.css",
"packages/web-ui/dist",
"packages/design-tokens",
"packages/node-backend/src"
],
"exports": {
".": "./README.md",
"./web-ui": {
"types": "./packages/web-ui/dist/index.d.ts",
"svelte": "./packages/web-ui/dist/index.js",
"import": "./packages/web-ui/dist/index.js"
},
"./web-ui/styles.css": "./shared-styles.css",
"./design-tokens": "./packages/design-tokens/theme.css",
"./design-tokens/theme.css": "./packages/design-tokens/theme.css",
"./node-backend": "./packages/node-backend/src/index.js",
"./node-backend/config": "./packages/node-backend/src/config.js",
"./node-backend/db": "./packages/node-backend/src/db.js",
"./node-backend/auth": "./packages/node-backend/src/auth.js",
"./node-backend/migrate": "./packages/node-backend/src/migrate.js"
},
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
], ],
@@ -13,10 +42,14 @@
"lint:node": "node scripts/check-node-syntax.mjs", "lint:node": "node scripts/check-node-syntax.mjs",
"test": "npm run build && npm run test:node-backend", "test": "npm run build && npm run test:node-backend",
"test:node-backend": "npm test --workspace=@gabriel20xx/node-backend", "test:node-backend": "npm test --workspace=@gabriel20xx/node-backend",
"prepare": "npm run build && node scripts/build-root-styles.mjs",
"changeset": "changeset", "changeset": "changeset",
"version-packages": "changeset version", "version-packages": "changeset version",
"release": "npm run build && npm run test:node-backend && changeset publish" "release": "npm run build && npm run test:node-backend && changeset publish"
}, },
"dependencies": {
"pg": "^8.17.2"
},
"devDependencies": { "devDependencies": {
"@changesets/cli": "^2.29.8" "@changesets/cli": "^2.29.8"
} }
+11
View File
@@ -0,0 +1,11 @@
import { readFile, writeFile } from 'node:fs/promises';
const source = await readFile(new URL('../packages/web-ui/dist/styles.css', import.meta.url), 'utf8');
const tokenImport = "@import '@gabriel20xx/design-tokens/theme.css';";
const componentStyles = source.replace(`${tokenImport}\n`, '');
await writeFile(
new URL('../shared-styles.css', import.meta.url),
`@import './packages/design-tokens/theme.css';\n\n${componentStyles}`,
'utf8'
);
+574
View File
@@ -0,0 +1,574 @@
@import './packages/design-tokens/theme.css';
:where(.sc-root, .sc-root *) {
box-sizing: border-box;
}
.sc-root {
min-height: 100%;
color: var(--sc-fg);
background: var(--sc-bg);
font-family: var(--sc-font-sans);
}
.sc-root button,
.sc-root input,
.sc-root textarea,
.sc-root select {
font: inherit;
}
.sc-root a {
color: inherit;
}
.sc-app-shell {
min-height: 100vh;
color: var(--sc-fg);
background: var(--sc-bg);
}
.sc-main {
width: min(100% - 2rem, 90rem);
margin: 0 auto;
padding: 2rem 0 3rem;
}
.sc-header {
position: sticky;
z-index: 20;
top: 0;
display: flex;
align-items: center;
gap: 1.25rem;
min-height: 4rem;
padding: 0 1rem;
color: var(--sc-fg);
background: color-mix(in srgb, var(--sc-surface) 92%, transparent);
border-bottom: 1px solid var(--sc-border);
backdrop-filter: blur(14px);
}
.sc-brand {
display: inline-flex;
flex: 0 0 auto;
align-items: center;
gap: 0.625rem;
color: var(--sc-fg);
font-size: 1rem;
font-weight: 750;
text-decoration: none;
letter-spacing: -0.01em;
}
.sc-brand-mark {
display: grid;
width: 2rem;
height: 2rem;
place-items: center;
color: var(--sc-primary-fg);
background: var(--sc-primary);
border-radius: var(--sc-radius-md);
font-size: 0.875rem;
font-weight: 800;
}
.sc-nav {
display: flex;
flex: 1 1 auto;
align-items: center;
gap: 0.25rem;
}
.sc-nav-link,
.sc-profile-button,
.sc-icon-button {
border: 1px solid transparent;
border-radius: var(--sc-radius-md);
transition: color 140ms ease, background 140ms ease, border-color 140ms ease;
}
.sc-nav-link {
padding: 0.5rem 0.75rem;
color: var(--sc-muted-fg);
font-size: 0.9rem;
text-decoration: none;
}
.sc-nav-link:hover,
.sc-nav-link[data-active='true'] {
color: var(--sc-fg);
background: var(--sc-surface-hover);
border-color: var(--sc-border);
}
.sc-header-actions {
display: flex;
align-items: center;
gap: 0.5rem;
margin-left: auto;
}
.sc-icon-button,
.sc-profile-button {
color: var(--sc-muted-fg);
background: transparent;
cursor: pointer;
}
.sc-icon-button {
display: grid;
width: 2.25rem;
height: 2.25rem;
place-items: center;
font-size: 1.15rem;
}
.sc-profile-button {
padding: 0.5rem 0.75rem;
font-size: 0.875rem;
}
.sc-icon-button:hover,
.sc-profile-button:hover {
color: var(--sc-fg);
background: var(--sc-surface-hover);
border-color: var(--sc-border);
}
.sc-mobile-menu-button {
display: none;
}
.sc-page-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1.5rem;
}
.sc-page-header h1,
.sc-page-header h2,
.sc-dialog-title,
.sc-auth-card h1 {
margin: 0;
color: var(--sc-fg);
font-weight: 750;
letter-spacing: -0.025em;
}
.sc-page-header h1 {
font-size: clamp(1.5rem, 3vw, 2.25rem);
}
.sc-page-header p,
.sc-dialog-description,
.sc-auth-subtitle,
.sc-muted {
margin: 0.5rem 0 0;
color: var(--sc-muted-fg);
line-height: 1.55;
}
.sc-card {
padding: 1.25rem;
color: var(--sc-fg);
background: var(--sc-surface);
border: 1px solid var(--sc-border);
border-radius: var(--sc-radius-lg);
box-shadow: var(--sc-shadow-sm);
}
.sc-card-header {
margin-bottom: 1rem;
}
.sc-card-header h2,
.sc-card-header h3 {
margin: 0;
font-size: 1.05rem;
}
.sc-card-header p {
margin: 0.375rem 0 0;
color: var(--sc-muted-fg);
font-size: 0.9rem;
}
.sc-badge {
display: inline-flex;
align-items: center;
min-height: 1.5rem;
padding: 0.125rem 0.5rem;
color: var(--sc-secondary-fg);
background: var(--sc-secondary);
border: 1px solid var(--sc-border);
border-radius: 999px;
font-size: 0.75rem;
font-weight: 650;
}
.sc-badge[data-variant='success'] {
color: var(--sc-success-fg);
background: var(--sc-success);
border-color: transparent;
}
.sc-badge[data-variant='warning'] {
color: var(--sc-warning-fg);
background: var(--sc-warning);
border-color: transparent;
}
.sc-badge[data-variant='danger'] {
color: var(--sc-danger-fg);
background: var(--sc-danger);
border-color: transparent;
}
.sc-button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
min-height: 2.5rem;
padding: 0.625rem 1rem;
border: 1px solid transparent;
border-radius: var(--sc-radius-md);
font-size: 0.9rem;
font-weight: 650;
line-height: 1;
cursor: pointer;
transition: color 140ms ease, background 140ms ease, border-color 140ms ease, opacity 140ms ease;
}
.sc-button:hover:not(:disabled) {
transform: translateY(-1px);
}
.sc-button:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.sc-button:focus-visible,
.sc-icon-button:focus-visible,
.sc-profile-button:focus-visible,
.sc-nav-link:focus-visible,
.sc-dialog-close:focus-visible {
outline: 3px solid color-mix(in srgb, var(--sc-ring) 45%, transparent);
outline-offset: 2px;
}
.sc-button-primary {
color: var(--sc-primary-fg);
background: var(--sc-primary);
}
.sc-button-primary:hover:not(:disabled) {
background: var(--sc-primary-hover);
}
.sc-button-secondary {
color: var(--sc-secondary-fg);
background: var(--sc-secondary);
border-color: var(--sc-border);
}
.sc-button-secondary:hover:not(:disabled) {
background: var(--sc-secondary-hover);
}
.sc-button-ghost {
color: var(--sc-muted-fg);
background: transparent;
}
.sc-button-ghost:hover:not(:disabled) {
color: var(--sc-fg);
background: var(--sc-surface-hover);
}
.sc-button-danger {
color: var(--sc-danger-fg);
background: var(--sc-danger);
}
.sc-button-danger:hover:not(:disabled) {
background: var(--sc-danger-hover);
}
.sc-button-sm {
min-height: 2rem;
padding: 0.45rem 0.75rem;
font-size: 0.8125rem;
}
.sc-button-lg {
min-height: 2.875rem;
padding: 0.75rem 1.25rem;
}
.sc-button-full {
width: 100%;
}
.sc-form {
display: grid;
gap: 1rem;
}
.sc-field {
display: grid;
gap: 0.4rem;
}
.sc-label {
color: var(--sc-fg);
font-size: 0.85rem;
font-weight: 650;
}
.sc-input,
.sc-select,
.sc-textarea {
width: 100%;
min-height: 2.6rem;
padding: 0.625rem 0.75rem;
color: var(--sc-fg);
background: var(--sc-bg);
border: 1px solid var(--sc-border);
border-radius: var(--sc-radius-md);
outline: none;
transition: border-color 140ms ease, box-shadow 140ms ease;
}
.sc-textarea {
min-height: 7rem;
resize: vertical;
}
.sc-input::placeholder,
.sc-textarea::placeholder {
color: var(--sc-subtle-fg);
}
.sc-input:focus,
.sc-select:focus,
.sc-textarea:focus {
border-color: var(--sc-ring);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--sc-ring) 22%, transparent);
}
.sc-form-actions,
.sc-dialog-footer {
display: flex;
justify-content: flex-end;
gap: 0.625rem;
margin-top: 0.5rem;
}
.sc-error {
padding: 0.75rem;
color: var(--sc-danger);
background: color-mix(in srgb, var(--sc-danger) 12%, transparent);
border: 1px solid color-mix(in srgb, var(--sc-danger) 35%, transparent);
border-radius: var(--sc-radius-md);
font-size: 0.875rem;
line-height: 1.45;
}
.sc-success {
color: var(--sc-success);
}
.sc-auth-page {
display: grid;
min-height: 100vh;
place-items: center;
padding: 1.5rem;
color: var(--sc-fg);
background:
radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--sc-primary) 18%, transparent), transparent 35%),
var(--sc-bg);
}
.sc-auth-card {
width: min(100%, 28rem);
padding: clamp(1.5rem, 5vw, 2.5rem);
background: var(--sc-surface);
border: 1px solid var(--sc-border);
border-radius: var(--sc-radius-xl);
box-shadow: var(--sc-shadow-lg);
}
.sc-auth-brand {
display: flex;
align-items: center;
gap: 0.75rem;
margin-bottom: 1.5rem;
font-weight: 750;
}
.sc-auth-card h1 {
font-size: 1.7rem;
}
.sc-auth-form {
margin-top: 1.5rem;
}
.sc-dialog-backdrop {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
padding: 1rem;
background: var(--sc-backdrop);
backdrop-filter: blur(5px);
}
.sc-dialog {
width: min(100%, 34rem);
max-height: min(90vh, 48rem);
overflow: auto;
color: var(--sc-fg);
background: var(--sc-surface-raised);
border: 1px solid var(--sc-border);
border-radius: var(--sc-radius-xl);
box-shadow: var(--sc-shadow-lg);
}
.sc-dialog-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
padding: 1.25rem 1.25rem 0;
}
.sc-dialog-title {
font-size: 1.25rem;
}
.sc-dialog-close {
display: grid;
width: 2rem;
height: 2rem;
place-items: center;
color: var(--sc-muted-fg);
background: transparent;
border: 1px solid transparent;
border-radius: var(--sc-radius-sm);
font-size: 1.35rem;
line-height: 1;
cursor: pointer;
}
.sc-dialog-close:hover {
color: var(--sc-fg);
background: var(--sc-surface-hover);
border-color: var(--sc-border);
}
.sc-dialog-body {
padding: 1.25rem;
}
.sc-dialog-footer {
padding: 0 1.25rem 1.25rem;
}
.sc-about-links {
display: grid;
gap: 0.5rem;
margin-top: 1rem;
}
.sc-about-links a {
color: var(--sc-primary);
text-decoration: none;
}
.sc-about-links a:hover {
color: var(--sc-primary-hover);
text-decoration: underline;
}
.sc-profile-summary {
display: grid;
gap: 0.25rem;
margin-bottom: 1.25rem;
padding: 0.875rem;
background: var(--sc-bg);
border: 1px solid var(--sc-border);
border-radius: var(--sc-radius-md);
}
.sc-profile-summary strong {
color: var(--sc-fg);
}
.sc-profile-summary span {
color: var(--sc-muted-fg);
font-size: 0.875rem;
}
@media (max-width: 45rem) {
.sc-header {
flex-wrap: wrap;
gap: 0.75rem;
padding: 0.75rem 1rem;
}
.sc-mobile-menu-button {
display: grid;
order: 3;
width: 2.25rem;
height: 2.25rem;
margin-left: auto;
place-items: center;
}
.sc-nav {
display: none;
flex-basis: 100%;
order: 4;
flex-direction: column;
align-items: stretch;
padding-bottom: 0.25rem;
}
.sc-nav[data-open='true'] {
display: flex;
}
.sc-nav-link {
width: 100%;
}
.sc-header-actions {
margin-left: 0;
}
.sc-profile-button {
max-width: 9rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
@media (max-width: 30rem) {
.sc-main {
width: min(100% - 1.25rem, 90rem);
padding-top: 1.25rem;
}
.sc-page-header {
flex-direction: column;
}
}