swatchkit 0.0.23 → 0.2.0

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.
Files changed (3) hide show
  1. package/README.md +35 -0
  2. package/build.js +48 -30
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -196,6 +196,41 @@ If your component needs client-side JS:
196
196
 
197
197
  SwatchKit automatically bundles your JS files, wraps them in a safety scope (IIFE), and injects them into the final build.
198
198
 
199
+ ## How It Works
200
+
201
+ Understanding the build pipeline helps you know which files to edit and which are generated.
202
+
203
+ ### 1. `swatchkit init` (Scaffolding)
204
+ Copies "blueprints" into your project to get you started.
205
+ * **`tokens/*.json`**: These are your **Source of Truth**. You edit these files.
206
+ * **`css/`**: Copies static CSS files (`main.css`, `reset.css`, etc.). **You own these files**.
207
+ * **`swatchkit/`**: Sets up the documentation structure and layout.
208
+
209
+ ### 2. `swatchkit` (Build Process)
210
+ Compiles your documentation site into `public/swatchkit/`.
211
+
212
+ 1. **Reads JSON Tokens**: Scans `tokens/*.json` and calculates fluid typography/spacing.
213
+ 2. **Generates CSS**: Creates `css/tokens.css`. **Do not edit this file**; it is overwritten every build.
214
+ 3. **Copies Assets**: Copies your `css/` folder (including your manually edited `global-styles.css` and `main.css`) to the output folder.
215
+ 4. **Scans Patterns**: Finds all HTML files in `swatchkit/` and stitches them into the documentation site.
216
+
217
+ ### Global Styles & Variables
218
+ SwatchKit includes sensible defaults in `css/variables.css` and `css/global-styles.css`.
219
+ * These are **static files** copied to your project during `init`.
220
+ * They are **disabled by default** (commented out in `main.css`).
221
+ * **Action Required:** Open these files, verify that the variable names match your `tokens/*.json` names, and then uncomment the imports in `main.css` to enable them.
222
+
223
+ ### What is Safe to Edit?
224
+
225
+ | File / Folder | Safe to Edit? | Notes |
226
+ | :--- | :--- | :--- |
227
+ | `tokens/*.json` | ✅ **YES** | Your source of truth. Safe. |
228
+ | `css/main.css` | ✅ **YES** | Your entry point. Safe. |
229
+ | `css/global-styles.css` | ✅ **YES** | You own this. Manually update if you rename tokens. |
230
+ | `css/tokens.css` | 🚫 **NO** | Overwritten by **every** `swatchkit build` and `swatchkit init`. |
231
+ | `swatchkit/_layout.html`| ✅ **YES** | Safe. **Warning:** `swatchkit init --force` WILL overwrite this. |
232
+ | `swatchkit/tokens/*.html`| 🚫 **NO** | Overwritten by `swatchkit build` (visual previews). |
233
+
199
234
  ## CLI Reference
200
235
 
201
236
  ```bash
package/build.js CHANGED
@@ -160,31 +160,31 @@ function resolveSettings(cliOptions, fileConfig) {
160
160
 
161
161
  // --- 4. Init Command Logic ---
162
162
  function runInit(settings, options) {
163
- console.log("[SwatchKit] Initializing...");
163
+ console.log("[SwatchKit] Scaffolding project structure...");
164
164
 
165
165
  // Ensure swatchkit directory exists
166
166
  if (!fs.existsSync(settings.swatchkitDir)) {
167
- console.log(`Creating swatchkit directory: ${settings.swatchkitDir}`);
167
+ console.log(`+ Directory: ${settings.swatchkitDir}`);
168
168
  fs.mkdirSync(settings.swatchkitDir, { recursive: true });
169
169
  }
170
170
 
171
171
  // Create tokens/ directory at project root (JSON token definitions)
172
172
  const tokensDir = settings.tokensDir;
173
173
  if (!fs.existsSync(tokensDir)) {
174
- console.log(`Creating tokens directory: ${tokensDir}`);
174
+ console.log(`+ Directory: ${tokensDir}`);
175
175
  fs.mkdirSync(tokensDir, { recursive: true });
176
176
  }
177
177
 
178
178
  // Create swatchkit/tokens/ directory (HTML/JS visual previews)
179
179
  const tokensUiDir = path.join(settings.swatchkitDir, "tokens");
180
180
  if (!fs.existsSync(tokensUiDir)) {
181
- console.log(`Creating tokens UI directory: ${tokensUiDir}`);
181
+ console.log(`+ Directory: ${tokensUiDir}`);
182
182
  fs.mkdirSync(tokensUiDir, { recursive: true });
183
183
  }
184
184
 
185
185
  // Create css/ directory at project root
186
186
  if (!fs.existsSync(settings.cssDir)) {
187
- console.log(`Creating CSS directory: ${settings.cssDir}`);
187
+ console.log(`+ Directory: ${settings.cssDir}`);
188
188
  fs.mkdirSync(settings.cssDir, { recursive: true });
189
189
  }
190
190
 
@@ -195,7 +195,7 @@ function runInit(settings, options) {
195
195
  const srcPath = path.join(__dirname, "src/blueprints", srcFilename);
196
196
  const content = fs.readFileSync(srcPath, "utf-8");
197
197
  fs.writeFileSync(destPath, content);
198
- console.log(`Created token file at ${destPath}`);
198
+ console.log(`+ Token Blueprint: ${destFilename}`);
199
199
  }
200
200
  };
201
201
 
@@ -216,7 +216,7 @@ function runInit(settings, options) {
216
216
  const srcPath = path.join(__dirname, "src/templates", srcFilename);
217
217
  const content = fs.readFileSync(srcPath, "utf-8");
218
218
  fs.writeFileSync(destPath, content.trim());
219
- console.log(`Created pattern at ${destPath}`);
219
+ console.log(`+ Pattern Template: ${destFilename}`);
220
220
  }
221
221
  };
222
222
 
@@ -229,15 +229,34 @@ function runInit(settings, options) {
229
229
  const srcPath = path.join(__dirname, "src/templates/script.js");
230
230
  const content = fs.readFileSync(srcPath, "utf-8");
231
231
  fs.writeFileSync(tokensScriptFile, content.trim());
232
- console.log(`Created tokens script at ${tokensScriptFile}`);
232
+ console.log(`+ Script: ${path.basename(tokensScriptFile)}`);
233
233
  }
234
234
 
235
235
  // Create main.css entry point
236
236
  if (!fs.existsSync(settings.mainCssFile)) {
237
237
  const srcPath = path.join(__dirname, "src/blueprints/main.css");
238
- const content = fs.readFileSync(srcPath, "utf-8");
238
+ let content = fs.readFileSync(srcPath, "utf-8");
239
+
240
+ // Default: Copy the files
241
+ const copyCssBlueprint = (filename) => {
242
+ const src = path.join(__dirname, "src/blueprints", filename);
243
+ // Ensure destination path (cssDir) exists
244
+ if (!fs.existsSync(settings.cssDir)) {
245
+ fs.mkdirSync(settings.cssDir, { recursive: true });
246
+ }
247
+ const dest = path.join(settings.cssDir, filename);
248
+ // Only copy if destination doesn't exist
249
+ if (fs.existsSync(src) && !fs.existsSync(dest)) {
250
+ fs.copyFileSync(src, dest);
251
+ console.log(`+ CSS Blueprint: ${filename}`);
252
+ }
253
+ };
254
+
255
+ copyCssBlueprint("variables.css");
256
+ copyCssBlueprint("global-styles.css");
257
+
239
258
  fs.writeFileSync(settings.mainCssFile, content);
240
- console.log(`Created main stylesheet at ${settings.mainCssFile}`);
259
+ console.log(`+ CSS Blueprint: main.css`);
241
260
  }
242
261
 
243
262
  // Copy CSS Reset
@@ -245,7 +264,7 @@ function runInit(settings, options) {
245
264
  const resetDest = path.join(settings.cssDir, "reset.css");
246
265
  if (fs.existsSync(resetSrc) && !fs.existsSync(resetDest)) {
247
266
  fs.copyFileSync(resetSrc, resetDest);
248
- console.log(`Created CSS reset at ${resetDest}`);
267
+ console.log(`+ CSS Blueprint: reset.css`);
249
268
  }
250
269
 
251
270
  // Copy Compositions
@@ -260,7 +279,7 @@ function runInit(settings, options) {
260
279
  const uiDest = path.join(settings.cssDir, "swatchkit-ui.css");
261
280
  if (fs.existsSync(uiSrc) && !fs.existsSync(uiDest)) {
262
281
  fs.copyFileSync(uiSrc, uiDest);
263
- console.log(`Created UI styles at ${uiDest}`);
282
+ console.log(`+ CSS Blueprint: swatchkit-ui.css`);
264
283
  }
265
284
 
266
285
  // Generate initial tokens.css
@@ -269,20 +288,18 @@ function runInit(settings, options) {
269
288
  const targetLayout = settings.projectLayout;
270
289
 
271
290
  if (fs.existsSync(targetLayout) && !options.force) {
272
- console.warn(`Warning: Layout file already exists at ${targetLayout}`);
273
- console.warn("Use --force to overwrite.");
274
- return;
275
- }
276
-
277
- if (fs.existsSync(settings.internalLayout)) {
278
- const layoutContent = fs.readFileSync(settings.internalLayout, "utf-8");
279
- fs.writeFileSync(targetLayout, layoutContent);
280
- console.log(`Created layout file at ${targetLayout}`);
291
+ console.warn(`! Layout already exists: ${targetLayout} (Use --force to overwrite)`);
281
292
  } else {
282
- console.error(
283
- `Error: Internal layout file not found at ${settings.internalLayout}`,
284
- );
285
- process.exit(1);
293
+ if (fs.existsSync(settings.internalLayout)) {
294
+ const layoutContent = fs.readFileSync(settings.internalLayout, "utf-8");
295
+ fs.writeFileSync(targetLayout, layoutContent);
296
+ console.log(`+ Layout: ${path.basename(targetLayout)}`);
297
+ } else {
298
+ console.error(
299
+ `Error: Internal layout file not found at ${settings.internalLayout}`,
300
+ );
301
+ process.exit(1);
302
+ }
286
303
  }
287
304
 
288
305
  // Copy preview layout template (standalone page for individual swatches)
@@ -294,7 +311,7 @@ function runInit(settings, options) {
294
311
  "utf-8",
295
312
  );
296
313
  fs.writeFileSync(targetPreview, previewContent);
297
- console.log(`Created preview layout at ${targetPreview}`);
314
+ console.log(`+ Layout: ${path.basename(targetPreview)}`);
298
315
  }
299
316
  }
300
317
  }
@@ -313,7 +330,7 @@ function copyDir(src, dest, force = false) {
313
330
  } else {
314
331
  if (force || !fs.existsSync(destPath)) {
315
332
  fs.copyFileSync(srcPath, destPath);
316
- if (!force) console.log(`Created file at ${destPath}`);
333
+ if (!force) console.log(`+ Copied: ${entry.name}`);
317
334
  }
318
335
  }
319
336
  }
@@ -412,6 +429,7 @@ function build(settings) {
412
429
  });
413
430
 
414
431
  // 2.5 Process Tokens
432
+ console.log("Reading JSON tokens (tokens/*.json)...");
415
433
  processTokens(settings.tokensDir, settings.cssDir);
416
434
 
417
435
  // 2.6 Generate token display HTML from JSON
@@ -419,18 +437,18 @@ function build(settings) {
419
437
  if (fs.existsSync(tokensUiDir)) {
420
438
  const generated = generateTokenSwatches(settings.tokensDir, tokensUiDir);
421
439
  if (generated > 0) {
422
- console.log(`Generated ${generated} token display files`);
440
+ console.log(`Generated ${generated} token documentation files (swatchkit/tokens/*.html)`);
423
441
  }
424
442
  }
425
443
 
426
444
  // 3. Copy CSS files (recursively)
427
445
  if (fs.existsSync(settings.cssDir)) {
428
- console.log("Copying CSS...");
446
+ console.log("Copying static CSS assets (css/*)...");
429
447
  copyDir(settings.cssDir, settings.distCssDir, true);
430
448
  }
431
449
 
432
450
  // 4. Read swatches & JS
433
- console.log("Processing swatches...");
451
+ console.log("Scanning HTML patterns (swatchkit/**/*.html)...");
434
452
  const scripts = [];
435
453
  const sections = {}; // Map<SectionName, Array<Swatch>>
436
454
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swatchkit",
3
- "version": "0.0.23",
3
+ "version": "0.2.0",
4
4
  "description": "A lightweight tool for creating HTML pattern libraries.",
5
5
  "main": "build.js",
6
6
  "bin": {