@hkdigital/lib-core 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -67
- package/dist/config/README.md +7 -37
- package/dist/config/vite.d.ts +1 -1
- package/dist/config/vite.js +1 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,39 +9,120 @@ It contains common code, base components and documentation that help you with se
|
|
|
9
9
|
|
|
10
10
|
### Install
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
**For projects/applications:**
|
|
14
13
|
```bash
|
|
15
14
|
pnpm add @hkdigital/lib-core
|
|
16
15
|
```
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
This library requires certain peer dependencies depending on which features you use:
|
|
21
|
-
|
|
22
|
-
**For development logging:**
|
|
23
|
-
```bash
|
|
24
|
-
pnpm add -D pino-pretty
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**For Vite config generators with imagetools:**
|
|
17
|
+
**For other libraries:**
|
|
28
18
|
```bash
|
|
29
|
-
pnpm add -D
|
|
19
|
+
pnpm add -D --save-peer @hkdigital/lib-core
|
|
30
20
|
```
|
|
31
21
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Components in this package use [tailwindcss](https://tailwindcss.com/).
|
|
35
|
-
|
|
36
|
-
To compile tailwind classes inside this package, you must add the package location to your tailwindcss plugin configuration.
|
|
22
|
+
### Peer Dependencies
|
|
37
23
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
Install peer dependencies:
|
|
25
|
+
```bash
|
|
26
|
+
# Core framework and utilities
|
|
27
|
+
pnpm add @sveltejs/kit svelte svelte-preprocess runed valibot
|
|
28
|
+
|
|
29
|
+
# UI components and icons
|
|
30
|
+
pnpm add @steeze-ui/heroicons
|
|
31
|
+
|
|
32
|
+
# Logging
|
|
33
|
+
pnpm add pino pino-pretty
|
|
34
|
+
|
|
35
|
+
# Linting
|
|
36
|
+
pnpm add @eslint/js eslint-plugin-import
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Design System & Configuration
|
|
40
|
+
|
|
41
|
+
This library includes a complete design system with Tailwind CSS integration. Basic setup requires:
|
|
42
|
+
|
|
43
|
+
1. **Tailwind config** - Include library files in content scanning:
|
|
44
|
+
```js
|
|
45
|
+
// tailwind.config.js
|
|
46
|
+
import {
|
|
47
|
+
generateTailwindThemeExtensions,
|
|
48
|
+
designTokens,
|
|
49
|
+
customUtilitiesPlugin
|
|
50
|
+
} from '@hkdigital/lib-core/design/index.js';
|
|
51
|
+
|
|
52
|
+
const themeExtensions = generateTailwindThemeExtensions(designTokens);
|
|
53
|
+
|
|
54
|
+
/** @type {import('tailwindcss').Config} */
|
|
55
|
+
export default {
|
|
56
|
+
// Include @hkdigital libraries in content so Tailwind processes
|
|
57
|
+
// their design system classes and components for proper styling
|
|
58
|
+
content: [
|
|
59
|
+
'./node_modules/@hkdigital/**/*.{html,js,svelte}',
|
|
60
|
+
'./src/**/*.{html,js,svelte}'
|
|
61
|
+
],
|
|
62
|
+
theme: {
|
|
63
|
+
// Extend Tailwind's default theme using the design system tokens
|
|
64
|
+
extend: themeExtensions
|
|
65
|
+
},
|
|
66
|
+
plugins: [
|
|
67
|
+
// Generate custom utility classes like 'type-heading-h2'
|
|
68
|
+
customUtilitiesPlugin
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
2. **Design tokens** - Apply CSS variables in your layout:
|
|
74
|
+
```html
|
|
75
|
+
<!-- src/routes/+layout.svelte -->
|
|
76
|
+
<script>
|
|
77
|
+
import { designTokens, designTokensToRootCssVars } from '@hkdigital/lib-core/design/index.js';
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<svelte:head>
|
|
81
|
+
{@html designTokensToRootCssVars(designTokens)}
|
|
82
|
+
</svelte:head>
|
|
83
|
+
|
|
84
|
+
{@render children()}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
3. **Vite configuration** - Use the provided config generator:
|
|
88
|
+
```js
|
|
89
|
+
// vite.config.js
|
|
90
|
+
import { defineConfig } from 'vitest/config';
|
|
91
|
+
import { generateViteConfig } from '@hkdigital/lib-core/config/vite.js';
|
|
92
|
+
|
|
93
|
+
export default defineConfig(
|
|
94
|
+
await generateViteConfig({
|
|
95
|
+
enableImagetools: true,
|
|
96
|
+
enableVitest: true
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
4. **Svelte configuration** - Configure preprocessing and useful path aliases:
|
|
102
|
+
```js
|
|
103
|
+
// svelte.config.js
|
|
104
|
+
import { sveltePreprocess } from 'svelte-preprocess';
|
|
105
|
+
import adapter from '@sveltejs/adapter-auto';
|
|
106
|
+
|
|
107
|
+
/** @type {import('@sveltejs/kit').Config} */
|
|
108
|
+
const config = {
|
|
109
|
+
// Enable preprocessing for external CSS files in Svelte components
|
|
110
|
+
preprocess: sveltePreprocess({}),
|
|
111
|
+
kit: {
|
|
112
|
+
adapter: adapter(),
|
|
113
|
+
alias: {
|
|
114
|
+
$src: 'src',
|
|
115
|
+
$examples: 'src/routes/examples'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default config;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
For detailed setup guides see:
|
|
124
|
+
- **Design system**: [src/lib/design/README.md](./src/lib/design/README.md)
|
|
125
|
+
- **Vite configuration**: [src/lib/config/README.md](./src/lib/config/README.md)
|
|
45
126
|
|
|
46
127
|
### Update
|
|
47
128
|
|
|
@@ -52,40 +133,18 @@ in the '@hkdigital' namespace.
|
|
|
52
133
|
pnpm upgrade:hk
|
|
53
134
|
```
|
|
54
135
|
|
|
55
|
-
###
|
|
136
|
+
### Available scripts
|
|
56
137
|
|
|
57
138
|
```bash
|
|
58
|
-
pnpm
|
|
59
|
-
pnpm
|
|
139
|
+
pnpm run dev # Start development server
|
|
140
|
+
pnpm run build # Build the library
|
|
141
|
+
pnpm run check # Type checking and validation
|
|
142
|
+
pnpm run test # Run unit tests
|
|
143
|
+
pnpm run upgrade:hk # Update all @hkdigital/... packages
|
|
144
|
+
pnpm run upgrade:all # Update all packages
|
|
145
|
+
pnpm run publish:npm # Version bump and publish to npm
|
|
60
146
|
```
|
|
61
147
|
|
|
62
|
-
```js
|
|
63
|
-
"scripts": {
|
|
64
|
-
"upgrade:hk": "run-s upgrade:hk:update pnpm:install",
|
|
65
|
-
"upgrade:hk:update": "ncu --dep dev,optional,peer,prod '@hkdigital/*' -u",
|
|
66
|
-
"pnpm:install": "pnpm install"
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Vite Configuration
|
|
71
|
-
|
|
72
|
-
The library provides configuration generators for Vite that include common HKdigital project settings:
|
|
73
|
-
|
|
74
|
-
```javascript
|
|
75
|
-
// vite.config.js
|
|
76
|
-
import { defineConfig } from 'vitest/config';
|
|
77
|
-
import { generateViteConfig } from '@hkdigital/lib-core/config/vite.js';
|
|
78
|
-
|
|
79
|
-
export default defineConfig(
|
|
80
|
-
await generateViteConfig({
|
|
81
|
-
enableImagetools: true,
|
|
82
|
-
enableVitest: true
|
|
83
|
-
})
|
|
84
|
-
);
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
For detailed configuration options, see the [config documentation](./src/lib/config/README.md).
|
|
88
|
-
|
|
89
148
|
### Import JS, Svelte files and Typedefs
|
|
90
149
|
|
|
91
150
|
Main folders in lib have an index.js, but may also have a more specific export file e.g. http.js or cache.js (@see $lib/network).
|
|
@@ -114,18 +173,6 @@ For example:
|
|
|
114
173
|
@import '../node_modules/@hkdigital/lib-core/dist/css/utilities.css';
|
|
115
174
|
```
|
|
116
175
|
|
|
117
|
-
### Enable tailwind processing
|
|
118
|
-
|
|
119
|
-
Allow the tailwind CSS processor to work on the library inside node_modules
|
|
120
|
-
|
|
121
|
-
```js
|
|
122
|
-
// tailwind.config.js
|
|
123
|
-
export default {
|
|
124
|
-
content: [
|
|
125
|
-
'./node_modules/@hkdigital/**/*.{html,js,svelte,ts}',
|
|
126
|
-
'./src/**/*.{html,js,svelte,ts}',
|
|
127
|
-
```
|
|
128
|
-
|
|
129
176
|
## Building the library
|
|
130
177
|
|
|
131
178
|
To build your library:
|
package/dist/config/README.md
CHANGED
|
@@ -56,51 +56,21 @@ export default defineConfig(
|
|
|
56
56
|
);
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
#### `generateViteDefines(options)`
|
|
60
|
-
|
|
61
|
-
Generates only the define configuration (no plugins).
|
|
62
|
-
|
|
63
|
-
**Options:**
|
|
64
|
-
- `packageJsonPath` (string, default: `'./package.json'`) - Path to package.json
|
|
65
|
-
- `customDefines` (object, default: `{}`) - Additional define values
|
|
66
|
-
|
|
67
|
-
**Example:**
|
|
68
|
-
```javascript
|
|
69
|
-
export default defineConfig({
|
|
70
|
-
plugins: [sveltekit()],
|
|
71
|
-
define: generateViteDefines({
|
|
72
|
-
customDefines: {
|
|
73
|
-
'import.meta.env.VITE_API_URL': JSON.stringify(process.env.API_URL)
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
#### `generateVitestConfig(options)`
|
|
80
|
-
|
|
81
|
-
Generates only the Vitest test configuration.
|
|
82
|
-
|
|
83
|
-
**Options:**
|
|
84
|
-
- `additionalPatterns` (array, default: `[]`) - Additional test file patterns
|
|
85
|
-
|
|
86
|
-
**Example:**
|
|
87
|
-
```javascript
|
|
88
|
-
export default defineConfig({
|
|
89
|
-
plugins: [sveltekit()],
|
|
90
|
-
test: generateVitestConfig({
|
|
91
|
-
additionalPatterns: ['tests/**/*.integration.js']
|
|
92
|
-
})
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
59
|
|
|
96
60
|
## Imagetools Configuration
|
|
97
61
|
|
|
98
|
-
When `enableImagetools: true`, the
|
|
62
|
+
When `enableImagetools: true`, install the imagetools dependency:
|
|
99
63
|
|
|
64
|
+
**For projects/applications:**
|
|
100
65
|
```bash
|
|
101
66
|
pnpm add -D vite-imagetools
|
|
102
67
|
```
|
|
103
68
|
|
|
69
|
+
**For other libraries:**
|
|
70
|
+
```bash
|
|
71
|
+
pnpm add -D --save-peer vite-imagetools
|
|
72
|
+
```
|
|
73
|
+
|
|
104
74
|
### TypeScript Support
|
|
105
75
|
|
|
106
76
|
For TypeScript and JavaScript projects using VS Code or other TypeScript-aware editors, add to your `app.d.ts`:
|
package/dist/config/vite.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { generateViteConfig
|
|
1
|
+
export { generateViteConfig } from "./generators/vite.js";
|
package/dist/config/vite.js
CHANGED