swatchkit 0.0.5 → 0.0.7
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 +48 -14
- package/build.js +38 -22
- package/package.json +1 -1
- package/src/layout.html +1 -1
package/README.md
CHANGED
|
@@ -16,10 +16,23 @@ npx swatchkit init
|
|
|
16
16
|
npx swatchkit
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
This will:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
This will create:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
my-project/
|
|
23
|
+
├── css/
|
|
24
|
+
│ ├── tokens.css # Generated design tokens (CSS custom properties)
|
|
25
|
+
│ └── styles.css # Starter stylesheet (imports tokens.css)
|
|
26
|
+
├── swatches/
|
|
27
|
+
│ ├── _layout.html # Layout template (you own this)
|
|
28
|
+
│ └── tokens/ # Token definitions + documentation patterns
|
|
29
|
+
│ ├── colors.json
|
|
30
|
+
│ ├── colors.html
|
|
31
|
+
│ └── ...
|
|
32
|
+
└── public/
|
|
33
|
+
└── swatchkit/ # Built pattern library
|
|
34
|
+
└── index.html
|
|
35
|
+
```
|
|
23
36
|
|
|
24
37
|
---
|
|
25
38
|
|
|
@@ -47,7 +60,7 @@ By default, SwatchKit looks for a `swatches/` folder in your project root.
|
|
|
47
60
|
* **Component Folder:** Drop a folder like `swatches/carousel/` containing `index.html`. It works the same way.
|
|
48
61
|
|
|
49
62
|
### 2. Design Token Engine
|
|
50
|
-
SwatchKit scaffolds a
|
|
63
|
+
SwatchKit scaffolds a design system for you. Edit the JSON files in `swatches/tokens/`, and SwatchKit auto-generates `css/tokens.css`.
|
|
51
64
|
|
|
52
65
|
**Supported Tokens:**
|
|
53
66
|
* **Colors** (`colors.json`): Generates palettes.
|
|
@@ -56,18 +69,35 @@ SwatchKit scaffolds a powerful, CUBE CSS-friendly design system for you. Edit th
|
|
|
56
69
|
* **Modular Leading** (`text-leading.json`): Generates line-heights using `pow()` modular scales.
|
|
57
70
|
* **Fonts & Weights**: Manages font families and weights.
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
Documentation patterns for these are automatically created alongside the JSON files.
|
|
73
|
+
|
|
74
|
+
### 3. CSS Workflow
|
|
75
|
+
|
|
76
|
+
SwatchKit generates `css/tokens.css` with your design tokens as CSS custom properties. The starter `css/styles.css` imports this file:
|
|
77
|
+
|
|
78
|
+
```css
|
|
79
|
+
@import 'tokens.css';
|
|
60
80
|
|
|
61
|
-
|
|
81
|
+
body {
|
|
82
|
+
font-family: var(--font-base);
|
|
83
|
+
color: var(--color-dark);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* Add your app styles here */
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The pattern library uses **your stylesheet**, so components render exactly as they will in your app.
|
|
90
|
+
|
|
91
|
+
### 4. Custom Layouts
|
|
62
92
|
When you run `swatchkit init`, we create `swatches/_layout.html`.
|
|
63
93
|
**You own this file.**
|
|
64
|
-
*
|
|
94
|
+
* Link to your own stylesheets.
|
|
65
95
|
* Add custom fonts, scripts, or meta tags.
|
|
66
96
|
* Change the HTML structure, logo, or classes.
|
|
67
97
|
|
|
68
|
-
SwatchKit
|
|
98
|
+
SwatchKit injects content into the `<!-- PATTERNS -->`, `<!-- SIDEBAR_LINKS -->`, and `<!-- HEAD_EXTRAS -->` placeholders.
|
|
69
99
|
|
|
70
|
-
###
|
|
100
|
+
### 5. JavaScript Bundling
|
|
71
101
|
If your component needs client-side JS:
|
|
72
102
|
1. Create a folder: `swatches/carousel/`.
|
|
73
103
|
2. Add `index.html` (Markup).
|
|
@@ -100,15 +130,19 @@ Optional. Create `swatchkit.config.js` in your root for persistent settings.
|
|
|
100
130
|
```javascript
|
|
101
131
|
module.exports = {
|
|
102
132
|
// Override default pattern directory
|
|
103
|
-
input: './
|
|
133
|
+
input: './patterns',
|
|
104
134
|
|
|
105
135
|
// Override default output directory
|
|
106
|
-
outDir: './dist/
|
|
136
|
+
outDir: './dist/patterns',
|
|
137
|
+
|
|
138
|
+
// Override CSS directory
|
|
139
|
+
css: './assets/css',
|
|
107
140
|
|
|
108
|
-
// Override
|
|
141
|
+
// Override token settings
|
|
109
142
|
tokens: {
|
|
143
|
+
input: './design-tokens', // Where token JSON files live
|
|
110
144
|
leading: {
|
|
111
|
-
ratio: 1.25,
|
|
145
|
+
ratio: 1.25, // Modular scale ratio
|
|
112
146
|
base: 1
|
|
113
147
|
}
|
|
114
148
|
}
|
package/build.js
CHANGED
|
@@ -97,12 +97,23 @@ function resolveSettings(cliOptions, fileConfig) {
|
|
|
97
97
|
? path.resolve(cwd, fileConfig.outDir)
|
|
98
98
|
: path.join(cwd, "public/swatchkit");
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
// CSS directory - where tokens.css and user's styles.css live
|
|
101
|
+
// Default: css/ at project root (not src/css/)
|
|
102
|
+
const cssDir = fileConfig.css
|
|
103
|
+
? path.resolve(cwd, fileConfig.css)
|
|
104
|
+
: path.join(cwd, "css");
|
|
105
|
+
|
|
106
|
+
// Token definitions directory
|
|
107
|
+
// Default: swatches/tokens/ (not src/tokens/)
|
|
108
|
+
const tokensDir = fileConfig.tokens?.input
|
|
109
|
+
? path.resolve(cwd, fileConfig.tokens.input)
|
|
110
|
+
: path.join(patternsDir, "tokens");
|
|
101
111
|
|
|
102
112
|
return {
|
|
103
113
|
patternsDir,
|
|
104
114
|
outDir,
|
|
105
115
|
cssDir,
|
|
116
|
+
tokensDir,
|
|
106
117
|
fileConfig, // Expose config to init
|
|
107
118
|
// Internal layout template (relative to this script)
|
|
108
119
|
internalLayout: path.join(__dirname, "src/layout.html"),
|
|
@@ -116,6 +127,7 @@ function resolveSettings(cliOptions, fileConfig) {
|
|
|
116
127
|
outputFile: path.join(outDir, "index.html"),
|
|
117
128
|
outputJsFile: path.join(outDir, "js/patterns.js"),
|
|
118
129
|
tokensCssFile: path.join(cssDir, "tokens.css"),
|
|
130
|
+
stylesCssFile: path.join(cssDir, "styles.css"),
|
|
119
131
|
};
|
|
120
132
|
}
|
|
121
133
|
|
|
@@ -129,27 +141,26 @@ function runInit(settings, options) {
|
|
|
129
141
|
fs.mkdirSync(settings.patternsDir, { recursive: true });
|
|
130
142
|
}
|
|
131
143
|
|
|
132
|
-
// Create
|
|
133
|
-
const
|
|
134
|
-
if (!fs.existsSync(patternsTokensDir)) {
|
|
135
|
-
console.log(`Creating patterns/tokens directory: ${patternsTokensDir}`);
|
|
136
|
-
fs.mkdirSync(patternsTokensDir, { recursive: true });
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Create src/tokens directory and sample colors.json
|
|
140
|
-
const tokensDir = path.join(process.cwd(), "src/tokens");
|
|
144
|
+
// Create swatches/tokens directory (for both JSON definitions and HTML patterns)
|
|
145
|
+
const tokensDir = settings.tokensDir;
|
|
141
146
|
if (!fs.existsSync(tokensDir)) {
|
|
142
147
|
console.log(`Creating tokens directory: ${tokensDir}`);
|
|
143
148
|
fs.mkdirSync(tokensDir, { recursive: true });
|
|
144
149
|
}
|
|
145
150
|
|
|
151
|
+
// Create css/ directory at project root
|
|
152
|
+
if (!fs.existsSync(settings.cssDir)) {
|
|
153
|
+
console.log(`Creating CSS directory: ${settings.cssDir}`);
|
|
154
|
+
fs.mkdirSync(settings.cssDir, { recursive: true });
|
|
155
|
+
}
|
|
156
|
+
|
|
146
157
|
const copyDefault = (srcFilename, destFilename) => {
|
|
147
158
|
const destPath = path.join(tokensDir, destFilename);
|
|
148
159
|
if (!fs.existsSync(destPath)) {
|
|
149
160
|
const srcPath = path.join(__dirname, 'src/blueprints', srcFilename);
|
|
150
161
|
const content = fs.readFileSync(srcPath, 'utf-8');
|
|
151
162
|
fs.writeFileSync(destPath, content);
|
|
152
|
-
console.log(`Created
|
|
163
|
+
console.log(`Created token file at ${destPath}`);
|
|
153
164
|
}
|
|
154
165
|
};
|
|
155
166
|
|
|
@@ -188,12 +199,12 @@ function runInit(settings, options) {
|
|
|
188
199
|
copyDefault('fonts.json', 'fonts.json');
|
|
189
200
|
|
|
190
201
|
const copyTemplate = (srcFilename, destFilename) => {
|
|
191
|
-
const destPath = path.join(
|
|
202
|
+
const destPath = path.join(tokensDir, destFilename);
|
|
192
203
|
if (!fs.existsSync(destPath)) {
|
|
193
204
|
const srcPath = path.join(__dirname, 'src/templates', srcFilename);
|
|
194
205
|
const content = fs.readFileSync(srcPath, 'utf-8');
|
|
195
206
|
fs.writeFileSync(destPath, content.trim());
|
|
196
|
-
console.log(`Created
|
|
207
|
+
console.log(`Created pattern at ${destPath}`);
|
|
197
208
|
}
|
|
198
209
|
};
|
|
199
210
|
|
|
@@ -206,7 +217,7 @@ function runInit(settings, options) {
|
|
|
206
217
|
copyTemplate('fonts.html', 'fonts.html');
|
|
207
218
|
|
|
208
219
|
// Create shared script for tokens
|
|
209
|
-
const tokensScriptFile = path.join(
|
|
220
|
+
const tokensScriptFile = path.join(tokensDir, "script.js");
|
|
210
221
|
if (!fs.existsSync(tokensScriptFile)) {
|
|
211
222
|
const srcPath = path.join(__dirname, 'src/templates/script.js');
|
|
212
223
|
const content = fs.readFileSync(srcPath, 'utf-8');
|
|
@@ -214,8 +225,16 @@ function runInit(settings, options) {
|
|
|
214
225
|
console.log(`Created tokens script at ${tokensScriptFile}`);
|
|
215
226
|
}
|
|
216
227
|
|
|
217
|
-
//
|
|
218
|
-
|
|
228
|
+
// Create starter styles.css
|
|
229
|
+
if (!fs.existsSync(settings.stylesCssFile)) {
|
|
230
|
+
const srcPath = path.join(__dirname, 'src/blueprints/styles.css');
|
|
231
|
+
const content = fs.readFileSync(srcPath, 'utf-8');
|
|
232
|
+
fs.writeFileSync(settings.stylesCssFile, content);
|
|
233
|
+
console.log(`Created starter stylesheet at ${settings.stylesCssFile}`);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Generate initial tokens.css
|
|
237
|
+
processTokens(settings.tokensDir, settings.cssDir);
|
|
219
238
|
|
|
220
239
|
const targetLayout = settings.projectLayout;
|
|
221
240
|
|
|
@@ -329,7 +348,7 @@ function build(settings) {
|
|
|
329
348
|
});
|
|
330
349
|
|
|
331
350
|
// 2.5 Process Tokens
|
|
332
|
-
processTokens(
|
|
351
|
+
processTokens(settings.tokensDir, settings.cssDir);
|
|
333
352
|
|
|
334
353
|
// 3. Copy CSS files
|
|
335
354
|
if (fs.existsSync(settings.cssDir)) {
|
|
@@ -418,11 +437,8 @@ function build(settings) {
|
|
|
418
437
|
layoutContent = fs.readFileSync(settings.internalLayout, "utf-8");
|
|
419
438
|
}
|
|
420
439
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (fs.existsSync(settings.distTokensCssFile)) {
|
|
424
|
-
headExtras = '<link rel="stylesheet" href="css/tokens.css">';
|
|
425
|
-
}
|
|
440
|
+
// HEAD_EXTRAS placeholder available for future use (e.g., custom fonts)
|
|
441
|
+
const headExtras = "";
|
|
426
442
|
|
|
427
443
|
const finalHtml = layoutContent
|
|
428
444
|
.replace("<!-- SIDEBAR_LINKS -->", sidebarLinks)
|
package/package.json
CHANGED
package/src/layout.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>SwatchKit</title>
|
|
7
|
-
<link rel="stylesheet" href="
|
|
7
|
+
<link rel="stylesheet" href="css/styles.css" />
|
|
8
8
|
<!-- HEAD_EXTRAS -->
|
|
9
9
|
<style>
|
|
10
10
|
body {
|