diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5aeb3ea --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,30 @@ +# Changelog + +All notable changes to Tansy UI are recorded here. The format follows +[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses +[Semantic Versioning](https://semver.org/spec/v2.0.0.html). While the version is +`0.x`, a minor release may include breaking changes. + +## [Unreleased] + +## [0.2.0] - 2026-09-28 + +First tagged release. + +### Added + +- 15 components with colocated tokens and stories: Button, LinkButton, Accordion, + TextField, Input, FeaturedInput, Select, Checkbox, Radio, Switch, TextArea, + Alert, Spinner, Badge, Card and Tooltip. +- Seven palettes (Classic Blue, Emerald, Violet, Amber, Crimson, Slate, Teal) + applied at runtime with `applyPalette()`. +- Landing page built only from Tansy components, with five featured parts and a + palette-switching playground form. +- Storybook workshop with Tansy branding, a Welcome page and a palette toolbar. +- Tansy mark and favicon. +- `version.json` on every deploy, recording the version and commit that were shipped. + +### Fixed + +- `Switch` now honours `defaultChecked`, including after a form reset. +- Button, Accordion and TextField follow the active palette. diff --git a/README.md b/README.md index 70e02c4..3d9e113 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Every part ships with: - **Its states.** Error, disabled, loading and required are part of the component, and each has its own story. - **Tokens, not hex codes.** Colours come from a 50–900 palette ramp, so switching the palette re-themes every part without a code change. -> **Status:** pre-release (v0.2). Tansy UI is not published to npm yet. It is developed in this repository, with a landing page and a Storybook workshop as its showcase. +> **Status:** pre-release (v0.2.0). Tansy UI is not published to npm yet. It is developed in this repository, with a landing page and a Storybook workshop as its showcase. ## Components @@ -95,6 +95,23 @@ npm run build-storybook # workshop -> storybook-static/ 3. Read colours from the palette ramps (`bg-primary-500`) so the palette switcher reaches it. 4. Run `npm run build-storybook && python3 scripts/gen_catalogue.py --patch` to refresh the landing page catalogue. +## Versioning + +Tansy UI follows [Semantic Versioning](https://semver.org). While the version is `0.x`, a minor release may include breaking changes. + +- `package.json` holds the version. The build injects it into the landing page and Storybook through `src/version.ts`, so it is never typed by hand. +- Every release gets an entry in [`CHANGELOG.md`](CHANGELOG.md) and an annotated git tag such as `v0.2.0`. +- Every deploy publishes `/version.json`, which records the version and commit that are live. + +To cut a release: + +```bash +# 1. Move the [Unreleased] notes in CHANGELOG.md under the new version, then: +npm version minor -m "Release v%s" # or patch / major; bumps package.json, commits and tags +git push origin main --follow-tags +python3 scripts/deploy.py # builds that commit and deploys it +``` + ## Project structure ```text @@ -103,6 +120,7 @@ src/ ├── components/ # Components, their tokens and their stories ├── data/catalogue.ts # Landing page catalogue (regenerated by scripts/gen_catalogue.py) ├── theme/ # Palettes and applyPalette() +├── version.ts # VERSION, injected from package.json ├── Welcome.mdx # Storybook welcome page ├── App.tsx # Landing page, built only from Tansy components └── index.css # Tailwind entry, palette tokens, landing styles diff --git a/package-lock.json b/package-lock.json index 879acc6..9ace2de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tansy-ui", - "version": "0.0.0", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tansy-ui", - "version": "0.0.0", + "version": "0.2.0", "dependencies": { "clsx": "^2.1.1", "lucide-react": "^0.460.0", diff --git a/package.json b/package.json index a016414..1ef0c33 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tansy-ui", "private": true, - "version": "0.0.0", + "version": "0.2.0", "type": "module", "scripts": { "dev": "vite", diff --git a/scripts/README.md b/scripts/README.md index 7a95f1b..0331aef 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -8,11 +8,15 @@ archive as the complete truth for the docroot and prunes everything else. ```bash python3 scripts/deploy.py # build + package + upload + verify -python3 scripts/deploy.py --deploy-only # upload the existing build +python3 scripts/deploy.py --deploy-only # upload the existing build (must be built from HEAD) python3 scripts/deploy.py --build-only # build and package, upload nothing python3 scripts/deploy.py --dry-run # package and report, upload nothing ``` +Commit before deploying. The script refuses to upload while the working tree +has uncommitted changes, so what is live always matches a commit. Pass +`--allow-dirty` to override. + ## One-time setup ```bash @@ -33,7 +37,29 @@ environment instead, which is what CI should do. 4. POST the base64 payload to it with a `Host` header for the subdomain, pointed at the origin IP so Cloudflare is bypassed 5. The PHP extracts, then deletes anything the archive did not contain -6. Rewrite the hardened `.htaccess` and verify the site +6. Rewrite the hardened `.htaccess` (always, even if a step above failed), + confirm PHP is off again, and verify the site, including `/version.json` + +## Caching + +The root `.htaccess` sends `Cache-Control: no-cache`, so browsers revalidate +`index.html`, `docs/index.json` and Storybook's fixed-name manager bundles on +every visit. `package()` adds an `.htaccess` to `assets/` and `docs/assets/` +that caches those content-hashed files for a year. Missing asset URLs return +404 instead of falling back to `index.html`. A stale page that asks for a pruned +bundle then fails visibly, instead of receiving HTML and rendering an empty +Storybook canvas. + +## Version stamp + +Each deploy writes `version.json` at the docroot: + +```json +{ "version": "0.2.0", "commit": "abc1234", "dirty": false, "built_at": "…" } +``` + +`verify()` checks that the live stamp matches the one just uploaded. To see +what is running, open `https:///version.json`. ## Why the archive can be authoritative diff --git a/scripts/deploy.py b/scripts/deploy.py index 85ec7f9..174ee50 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -42,6 +42,11 @@ ENV_FILE = REPO / "scripts" / "deploy.env" # writes them, and removing .htaccess would take the site offline. KEEP_TOP = ["cgi-bin", ".well-known", "php.ini", ".user.ini", ".htaccess"] +# The probe prints the marker only when PHP runs it: the source splits the +# string, so a copy served as plain text never contains PROBE_MARK. +PROBE_MARK = "PHPEXEC-OK" +PROBE_PHP = " Header set X-Content-Type-Options "nosniff" Header set Referrer-Policy "strict-origin-when-cross-origin" + # Revalidate everything by default: HTML, index.json and Storybook's + # fixed-name manager bundles change on every deploy. Content-hashed files + # get a long cache from the .htaccess that package() puts in each assets/. + Header set Cache-Control "no-cache" +""" - - ExpiresActive On - ExpiresByType text/css "access plus 1 year" - ExpiresByType application/javascript "access plus 1 year" - ExpiresByType image/svg+xml "access plus 1 year" - ExpiresByType font/woff2 "access plus 1 year" +# Written into assets/ and docs/assets/, whose files are all content-hashed, +# so they can be cached for good. It overrides the root no-cache. +HTACCESS_ASSETS = """ + Header set Cache-Control "public, max-age=31536000, immutable" """ @@ -144,9 +158,32 @@ def build() -> None: run(["npm", "ci"]) run(["npm", "run", "lint"]) run(["npm", "run", "build"]) - if not (REPO / "storybook-static" / "index.json").exists(): - die("storybook-static/index.json missing - run: npm run build-storybook") run(["npm", "run", "build-storybook"]) + if not (REPO / "storybook-static" / "index.json").exists(): + die("storybook-static/index.json missing after build-storybook") + + +def git(*args: str) -> str: + return subprocess.run(["git", *args], cwd=REPO, capture_output=True, + text=True, check=True).stdout.strip() + + +def require_clean_tree() -> None: + """Refuse to ship work that is not committed, so every deploy is a commit.""" + dirty = git("status", "--porcelain") + if dirty: + die("uncommitted changes - commit them first, or pass --allow-dirty:\n" + + dirty) + + +def build_stamp() -> dict: + version = json.loads((REPO / "package.json").read_text())["version"] + return { + "version": version, + "commit": git("rev-parse", "--short", "HEAD"), + "dirty": bool(git("status", "--porcelain")), + "built_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), + } def package() -> dict: @@ -162,6 +199,11 @@ def package() -> dict: shutil.copytree(dist, STAGE, dirs_exist_ok=True) (STAGE / "docs").mkdir(exist_ok=True) shutil.copytree(sb, STAGE / "docs", dirs_exist_ok=True) + for assets in (STAGE / "assets", STAGE / "docs" / "assets"): + if assets.is_dir(): + (assets / ".htaccess").write_text(HTACCESS_ASSETS) + stamp = build_stamp() + (STAGE / "version.json").write_text(json.dumps(stamp, indent=2) + "\n") files = [p for p in STAGE.rglob("*") if p.is_file()] if ZIP.exists(): @@ -182,10 +224,13 @@ def package() -> dict: "zip_bytes": len(raw), "b64_bytes": len(b64), "sha256": hashlib.sha256(raw).hexdigest(), + "stamp": stamp, } log(f"packaged {entries} files, {len(raw)/1024/1024:.2f} MB zip, " f"{len(b64)/1024/1024:.2f} MB base64") log(f"sha256 {info['sha256'][:32]}") + log(f"version {stamp['version']} at {stamp['commit']}" + + (" (dirty)" if stamp["dirty"] else "")) (STAGE.parent / "tansy-payload.json").write_text(json.dumps(info, indent=2)) return info @@ -224,7 +269,7 @@ class Panel: self.token = json.loads(out)["security_token"] except Exception: die(f"login failed: {out[:200]}") - log(f"logged in, token {self.token}") + log("logged in") def uapi(self, module: str, fn: str, params: dict | None = None) -> dict: url = f"{self.base}{self.token}/execute/{module}/{fn}" @@ -244,6 +289,26 @@ class Panel: die(f"failed to write {name}: {out[:200]}") log(f"wrote {name} ({len(content)} bytes)") + def delete_file(self, name: str) -> None: + """Permanently delete one file from the docroot (API 2 Fileman::fileop).""" + params = { + "cpanel_jsonapi_apiversion": 2, + "cpanel_jsonapi_module": "Fileman", + "cpanel_jsonapi_func": "fileop", + "op": "unlink", + "sourcefiles": f"{self.docroot}/{name}", + "doubledecode": 1, + } + out = self._http(f"{self.base}{self.token}/json-api/cpanel?" + + urllib.parse.urlencode(params)) + try: + ok = json.loads(out)["cpanelresult"]["data"][0]["result"] == 1 + except Exception: + ok = False + if not ok: + die(f"failed to delete {name}: {out[:200]}") + log(f"deleted {name}") + def read_file(self, name: str) -> str: out = self._http(f"{self.base}{self.token}/execute/Fileman/get_file_content", {"dir": self.docroot, "file": name}) @@ -290,6 +355,15 @@ def verify(panel: Panel) -> None: import hashlib as _h log("verifying…") + local_stamp = json.loads((STAGE / "version.json").read_text()) + try: + live_stamp = json.loads(panel.get_from_origin("/version.json")) + except Exception: + live_stamp = {} + if live_stamp != local_stamp: + die(f"version.json mismatch\n live {live_stamp}\n local {local_stamp}") + log(f"live version {live_stamp['version']} at {live_stamp['commit']}") + idx = panel.get_from_origin("/index.html") live_sha = _h.sha256(idx.encode()).hexdigest() local_sha = _h.sha256((REPO / "dist" / "index.html").read_bytes()).hexdigest() @@ -347,10 +421,16 @@ def main() -> None: ap.add_argument("--dry-run", action="store_true") ap.add_argument("--skip-php-lint", action="store_true", help="ship cpanel-deploy.php without `php -l`") + ap.add_argument("--allow-dirty", action="store_true", + help="deploy even with uncommitted changes") args = ap.parse_args() global SKIP_PHP_LINT SKIP_PHP_LINT = args.skip_php_lint + uploading = not (args.build_only or args.dry_run) + if uploading and not args.allow_dirty: + require_clean_tree() + if not args.deploy_only: build() info = package() @@ -377,45 +457,50 @@ def main() -> None: "to check it. Install php-cli or run the deploy with " "--skip-php-lint if you are certain the file parses.") - # 1. PHP must be on for the uploader to run. + # 1. PHP must be on for the uploader to run. From here on, any exit + # (an error, a timeout, Ctrl-C) must put the hardened file back. panel.write_file(".htaccess", htaccess_deploy) - time.sleep(2) - - # 2. Prove PHP actually executes before relying on it. - panel.write_file("_probe.php", "

React component kit - v0.2 · {documentation.length} parts · {totalStories} stories + v{VERSION} · {documentation.length} parts · {totalStories} stories

Small parts, @@ -362,7 +363,7 @@ function App() {
- Tansy UI · a React component kit by OpenKhalix + Tansy UI v{VERSION} · a React component kit by OpenKhalix