Skip to content

Commit a66e078

Browse files
committed
refactor: consume @tiny-ui/tokens from react package and docs app
Remove duplicated style sources (fonts, themes, normalise) from the react package in favour of the new tokens package. Update build script, dependencies, lint-staged config, and add DEVELOPMENT.md.
1 parent aea5f42 commit a66e078

21 files changed

Lines changed: 85 additions & 3320 deletions

DEVELOPMENT.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Development Workflow
2+
3+
## Local Development
4+
5+
```bash
6+
pnpm dev # Start the Vite docs site
7+
pnpm build # Build all packages (via turborepo)
8+
pnpm test # Run tests across all packages
9+
pnpm lint # Lint all packages
10+
pnpm lint:style # Lint SCSS files
11+
```
12+
13+
A **pre-commit hook** (husky) runs `lint-staged`, which auto-fixes SCSS via stylelint.
14+
15+
## Build Pipeline
16+
17+
Turborepo handles the dependency graph via `"dependsOn": ["^build"]`:
18+
19+
```
20+
@tiny-ui/tokens → @tiny-ui/react → @tiny-ui/docs
21+
```
22+
23+
Each package's build step:
24+
25+
| Package | Build Steps |
26+
|---------|-------------|
27+
| **@tiny-ui/tokens** | `node scripts/build.js` — sass compiles `scss/base.scss` into `css/base.css` |
28+
| **@tiny-ui/react** | `tsdown` (TS to JS) → `build-styles.js` (copies base.css from tokens, compiles 78 component SCSS files) → `inject-style-imports.js` (adds CSS imports into JS entry files) |
29+
| **@tiny-ui/docs** | `vite build` |
30+
31+
## CI (GitHub Actions)
32+
33+
Three workflows triggered on push/PR to `master`:
34+
35+
1. **CI** (`ci.yml`) — install → lint → build → test with coverage
36+
2. **Release** (`release.yml`) — uses `changesets/action` to either create a "Version Packages" PR or publish to npm. The docs package is excluded from publishing.
37+
3. **Deploy Site** (`deploy-site.yml`) — builds docs with `--base /tiny-ui/`, deploys to GitHub Pages with SPA routing support.
38+
39+
## Release Flow
40+
41+
1. Add a changeset: `pnpm changeset`
42+
2. Merge to `master`
43+
3. The Release workflow creates a version PR (bumps versions, updates changelogs)
44+
4. Merging that PR triggers publish to npm and site deploy

apps/docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"dependencies": {
1111
"@tiny-ui/react": "workspace:*",
12+
"@tiny-ui/tokens": "workspace:*",
1213
"@mdx-js/react": "^3.1.1",
1314
"react": "^18.2.0",
1415
"react-dom": "^18.2.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"typescript-eslint": "^8.0.0"
4545
},
4646
"lint-staged": {
47-
"packages/react/src/**/*.scss": [
47+
"packages/{react/src,tokens/scss}/**/*.scss": [
4848
"stylelint --fix"
4949
]
5050
},

packages/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
},
6161
"dependencies": {
6262
"@popperjs/core": "^2.11.4",
63+
"@tiny-ui/tokens": "workspace:*",
6364
"classnames": "^2.3.1",
6465
"react-transition-group": "^4.4.2",
6566
"tslib": "^2.3.1"

packages/react/scripts/build-styles.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const ROOT = path.resolve(__dirname, '..');
88
const COMPONENTS = path.join(ROOT, 'src');
99
const ES_DIR = path.join(ROOT, 'es');
1010
const LIB_DIR = path.join(ROOT, 'lib');
11+
const NODE_MODULES = path.join(ROOT, 'node_modules');
1112

1213
function mkdirp(dir) {
1314
fs.mkdirSync(dir, { recursive: true });
@@ -18,19 +19,15 @@ async function processWithPostcss(css) {
1819
return result.css;
1920
}
2021

21-
// 1. Base CSS: components/style/base.scss → es/style/base.css + lib/style/base.css
22-
async function buildBaseCss() {
23-
const result = sass.compile(path.join(COMPONENTS, 'style/base.scss'), {
24-
loadPaths: [COMPONENTS],
25-
});
26-
const css = await processWithPostcss(result.css);
27-
22+
// 1. Base CSS: copy pre-built base.css from @tiny-ui/tokens
23+
function copyBaseCss() {
24+
const src = require.resolve('@tiny-ui/tokens/css/base.css');
2825
for (const dir of [ES_DIR, LIB_DIR]) {
2926
const outDir = path.join(dir, 'style');
3027
mkdirp(outDir);
31-
fs.writeFileSync(path.join(outDir, 'base.css'), css);
28+
fs.copyFileSync(src, path.join(outDir, 'base.css'));
3229
}
33-
console.log(' es/style/base.css + lib/style/base.css');
30+
console.log(' es/style/base.css + lib/style/base.css (copied from @tiny-ui/tokens)');
3431
}
3532

3633
// 2. Per-component CSS: compile each component's _index.scss partial
@@ -50,13 +47,13 @@ async function buildComponentCss() {
5047
if (fs.existsSync(partialPath)) {
5148
// Sass partial: compile via @use
5249
const result = sass.compileString("@use 'index';", {
53-
loadPaths: [styleDir, COMPONENTS],
50+
loadPaths: [styleDir, COMPONENTS, NODE_MODULES],
5451
});
5552
css = await processWithPostcss(result.css);
5653
} else if (fs.existsSync(directPath)) {
5754
// Direct scss file (e.g. tabs)
5855
const result = sass.compile(directPath, {
59-
loadPaths: [COMPONENTS],
56+
loadPaths: [COMPONENTS, NODE_MODULES],
6057
});
6158
css = await processWithPostcss(result.css);
6259
} else {
@@ -115,7 +112,8 @@ function copyDirRecursive(src, dest) {
115112

116113
async function main() {
117114
console.log('Building styles...\n');
118-
await Promise.all([buildBaseCss(), buildComponentCss()]);
115+
copyBaseCss();
116+
await buildComponentCss();
119117
copyScss();
120118
console.log('\nStyles done.');
121119
}

packages/react/src/style/_animation.scss

100755100644
Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1 @@
1-
@keyframes ty-rotate {
2-
0% {
3-
transform: rotate(0deg);
4-
}
5-
6-
100% {
7-
transform: rotate(360deg);
8-
}
9-
}
10-
11-
@keyframes ty-rotate-reverse {
12-
from {
13-
transform: rotate(0);
14-
}
15-
16-
to {
17-
transform: rotate(-360deg);
18-
}
19-
}
20-
21-
@keyframes ty-processing {
22-
0% {
23-
transform: scale(0.8);
24-
opacity: 0.5;
25-
}
26-
27-
100% {
28-
transform: scale(2.8);
29-
opacity: 0;
30-
}
31-
}
1+
@forward '@tiny-ui/tokens/scss/animation';

0 commit comments

Comments
 (0)