swatchkit 0.12.0 → 1.0.1

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 -28
  2. package/build.js +112 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -9,10 +9,13 @@ It follows the "Magic Folder" principle: drop files in, and a library comes out.
9
9
  Try it instantly in any project:
10
10
 
11
11
  ```bash
12
- # 1. Initialize the layout and design tokens
13
- npx swatchkit init
12
+ # 1. Create a config (sets your CSS location and preferences)
13
+ npx swatchkit new
14
14
 
15
- # 2. Build the library
15
+ # 2. Scaffold layout, tokens, and CSS blueprints
16
+ npx swatchkit scaffold
17
+
18
+ # 3. Build the library
16
19
  npx swatchkit
17
20
  ```
18
21
 
@@ -101,7 +104,7 @@ SwatchKit scaffolds a design system for you. Edit the JSON files in `tokens/`, a
101
104
  - **Modular Leading** (`text-leading.json`): Generates line-heights using `pow()` modular scales.
102
105
  - **Fonts & Weights**: Manages font families and weights.
103
106
 
104
- Visual documentation patterns for these tokens live in `swatchkit/tokens/` and are created during init.
107
+ Visual documentation patterns for these tokens live in `swatchkit/tokens/` and are created during scaffold.
105
108
 
106
109
  ### 3. Intelligent Fluid Logic (New!)
107
110
 
@@ -180,7 +183,7 @@ The sidebar and documentation layout are styled by `css/swatchkit-ui.css`. This
180
183
 
181
184
  ### 6. Custom Layouts
182
185
 
183
- When you run `swatchkit init`, we create `swatchkit/_layout.html`.
186
+ When you run `swatchkit scaffold`, we create `swatchkit/_layout.html`.
184
187
  **You own this file.**
185
188
 
186
189
  - Link to your own stylesheets.
@@ -203,12 +206,12 @@ SwatchKit automatically bundles your JS files, wraps them in a safety scope (IIF
203
206
 
204
207
  Understanding the build pipeline helps you know which files to edit and which are generated.
205
208
 
206
- ### 1. `swatchkit init` (Scaffolding)
207
- Copies "blueprints" into your project to get you started. Init tracks a manifest of every file it manages (token JSONs, CSS blueprints, layout templates) so it can report what's new, changed, or up to date.
209
+ ### 1. `swatchkit scaffold` (Scaffolding)
210
+ Copies "blueprints" into your project to get you started. Scaffold tracks a manifest of every file it manages (token JSONs, CSS blueprints, layout templates) so it can report what's new, changed, or up to date.
208
211
 
209
212
  * **Fresh project:** Creates directories and copies all blueprint files.
210
- * **Already initialized:** Prints a status report comparing your files to the latest blueprints. Suggests `--force` if anything has changed.
211
- * **`--force`:** Overwrites all init-managed files with the latest blueprints. Your custom swatch HTML files and any CSS files without blueprint counterparts are never touched.
213
+ * **Already scaffolded:** Prints a status report comparing your files to the latest blueprints. Suggests `--force` if anything has changed.
214
+ * **`--force`:** Overwrites all scaffold-managed files with the latest blueprints. Your custom swatch HTML files and any CSS files without blueprint counterparts are never touched.
212
215
  * **`--dry-run`:** Shows what would happen without writing anything.
213
216
 
214
217
  Files created:
@@ -227,7 +230,7 @@ Compiles your documentation site into `dist/swatchkit/`.
227
230
 
228
231
  ### Global Styles & Variables
229
232
  SwatchKit includes sensible defaults in `css/global/variables.css` and `css/global/elements.css`.
230
- * These are **static files** copied to your project during `init` and **enabled by default**.
233
+ * These are **static files** copied to your project during `scaffold` and **enabled by default**.
231
234
  * Variable references use the default token names from `tokens/*.json`. If you rename any tokens, update the `var()` references in these files to match.
232
235
  * Both files are yours to edit — add your own variables and element styles freely.
233
236
 
@@ -239,9 +242,9 @@ SwatchKit includes sensible defaults in `css/global/variables.css` and `css/glob
239
242
  | `css/main.css` | ✅ **YES** | Your entry point. Safe. |
240
243
  | `css/global/variables.css` | ✅ **YES** | You own this. Update var() references if you rename tokens. |
241
244
  | `css/global/elements.css` | ✅ **YES** | You own this. Update var() references if you rename tokens. |
242
- | `css/tokens.css` | 🚫 **NO** | Overwritten by **every** `swatchkit build` and `swatchkit init`. |
243
- | `swatchkit/_layout.html`| ✅ **YES** | Safe during normal use. `init --force` overwrites all init-managed files, including this one. |
244
- | `swatchkit/_preview.html`| ✅ **YES** | Same as `_layout.html` — safe unless you run `init --force`. |
245
+ | `css/tokens.css` | 🚫 **NO** | Overwritten by every build and `swatchkit scaffold`. |
246
+ | `swatchkit/_layout.html`| ✅ **YES** | Safe during normal use. `scaffold --force` overwrites all scaffold-managed files, including this one. |
247
+ | `swatchkit/_preview.html`| ✅ **YES** | Same as `_layout.html` — safe unless you run `scaffold --force`. |
245
248
  | `swatchkit/tokens/*.html`| 🚫 **NO** | Overwritten by `swatchkit build` (visual previews). |
246
249
 
247
250
  ## CLI Reference
@@ -252,27 +255,31 @@ swatchkit [command] [options]
252
255
 
253
256
  ### Commands
254
257
 
255
- - `swatchkit` (Default): Builds the library.
256
- - `swatchkit init`: Scaffolds the layout and token files. If the project is already initialized, prints a status report showing which files differ from their blueprints (auto dry-run).
257
- - `swatchkit init --force`: Overwrites all init-managed files with the latest blueprints. Custom swatch files and CSS files without blueprint counterparts are never touched.
258
- - `swatchkit init --dry-run`: Shows what would be created or changed without writing anything.
258
+ - `swatchkit new`: Creates `swatchkit.config.js`. Prompts for your CSS directory location. Run this first in any new project.
259
+ - `swatchkit new --cssDir ./src/css`: Non-interactive creates config without prompting.
260
+ - `swatchkit new --force`: Overwrites an existing config (backs up the old one).
261
+ - `swatchkit scaffold`: Copies CSS blueprints, token JSON files, and layout templates into your project using the settings from `swatchkit.config.js`. If already scaffolded, prints a status report.
262
+ - `swatchkit scaffold --force`: Overwrites all scaffold-managed files with the latest blueprints (with backups).
263
+ - `swatchkit scaffold --dry-run`: Shows what would be created or changed without writing anything.
264
+ - `swatchkit` (Default): Builds the pattern library.
259
265
 
260
266
  ### Flags
261
267
 
262
- | Flag | Short | Description |
263
- | :---------- | :---- | :-------------------------------------------------------------- |
264
- | `--watch` | `-w` | Watch files and rebuild on change. |
265
- | `--config` | `-c` | Path to config file. |
266
- | `--input` | `-i` | Pattern directory (Default: `swatchkit/`). |
267
- | `--outDir` | `-o` | Output directory (Default: `dist/swatchkit`). |
268
- | `--force` | `-f` | Overwrite all init-managed files with latest blueprints. |
269
- | `--dry-run` | | Show what init would create or change, without writing anything.|
270
- | `--help` | `-h` | Show help message. |
271
- | `--version` | `-v` | Show version number. |
268
+ | Flag | Short | Description |
269
+ | :---------- | :---- | :----------------------------------------------------------------- |
270
+ | `--watch` | `-w` | Watch files and rebuild on change. |
271
+ | `--config` | `-c` | Path to config file. |
272
+ | `--input` | `-i` | Pattern directory (Default: `swatchkit/`). |
273
+ | `--outDir` | `-o` | Output directory (Default: `dist/swatchkit`). |
274
+ | `--cssDir` | | CSS directory, for use with `new` (Default: `src/css`). |
275
+ | `--force` | `-f` | Overwrite existing files (`new`: config, `scaffold`: blueprints). |
276
+ | `--dry-run` | | Show what scaffold would create or change, without writing. |
277
+ | `--help` | `-h` | Show help message. |
278
+ | `--version` | `-v` | Show version number. |
272
279
 
273
280
  ## Configuration
274
281
 
275
- Optional. Create `swatchkit.config.js` in your root for persistent settings.
282
+ `swatchkit.config.js` is created by `swatchkit new`. You can also create it manually in your project root.
276
283
 
277
284
  ```javascript
278
285
  module.exports = {
package/build.js CHANGED
@@ -18,14 +18,17 @@ function parseArgs(args) {
18
18
  config: null,
19
19
  input: null,
20
20
  outDir: null,
21
+ cssDir: null,
21
22
  force: false,
22
23
  dryRun: false,
23
24
  };
24
25
 
25
26
  for (let i = 2; i < args.length; i++) {
26
27
  const arg = args[i];
27
- if (arg === "init") {
28
- options.command = "init";
28
+ if (arg === "new") {
29
+ options.command = "new";
30
+ } else if (arg === "scaffold") {
31
+ options.command = "scaffold";
29
32
  } else if (arg === "-w" || arg === "--watch") {
30
33
  options.watch = true;
31
34
  } else if (arg === "-h" || arg === "--help") {
@@ -49,6 +52,10 @@ function parseArgs(args) {
49
52
  if (i + 1 < args.length) {
50
53
  options.outDir = args[++i];
51
54
  }
55
+ } else if (arg === "--cssDir") {
56
+ if (i + 1 < args.length) {
57
+ options.cssDir = args[++i];
58
+ }
52
59
  }
53
60
  }
54
61
  return options;
@@ -215,7 +222,7 @@ function buildInitManifest(settings) {
215
222
  }
216
223
 
217
224
  // Template files (swatchkit/tokens/)
218
- const templateFiles = ["prose.html", "script.js"];
225
+ const templateFiles = ["prose.html"];
219
226
  for (const file of templateFiles) {
220
227
  manifest.push({
221
228
  src: path.join(templatesDir, file),
@@ -336,12 +343,76 @@ function reportInitStatus(settings) {
336
343
 
337
344
  if (changed.length > 0 || created.length > 0 || newDirs.length > 0) {
338
345
  console.log(
339
- " Run 'swatchkit init --force' to update all files to latest blueprints.\n",
346
+ " Run 'swatchkit scaffold --force' to update all files to latest blueprints.\n",
340
347
  );
341
348
  }
342
349
  }
343
350
 
344
- // --- 5. Init Command Logic ---
351
+ // --- 5. New Command Logic ---
352
+ function generateConfig(cssDir) {
353
+ return `// swatchkit.config.js
354
+ module.exports = {
355
+ // Where your CSS lives. SwatchKit scaffolds blueprints here and reads
356
+ // tokens from here when building the pattern library.
357
+ cssDir: "${cssDir}",
358
+
359
+ // Set to false if a build tool (Vite, Astro, Eleventy, etc.) is already
360
+ // handling your CSS and you don't need SwatchKit to copy it.
361
+ cssCopy: true,
362
+
363
+ // Where token JSON files live.
364
+ // tokensDir: "./tokens",
365
+
366
+ // Where the built pattern library is output.
367
+ // outDir: "./dist/swatchkit",
368
+
369
+ // Files or folders to exclude from the pattern library (supports globs).
370
+ // exclude: [],
371
+ };
372
+ `;
373
+ }
374
+
375
+ function runNew(cliOptions) {
376
+ const cwd = process.cwd();
377
+ const configPath = path.join(cwd, 'swatchkit.config.js');
378
+
379
+ if (fs.existsSync(configPath) && !cliOptions.force) {
380
+ console.log('[SwatchKit] swatchkit.config.js already exists.');
381
+ console.log(' Run "swatchkit new --force" to overwrite it.');
382
+ return;
383
+ }
384
+
385
+ // Non-interactive mode: --cssDir flag provided
386
+ if (cliOptions.cssDir) {
387
+ const content = generateConfig(cliOptions.cssDir);
388
+ fs.writeFileSync(configPath, content);
389
+ console.log(`+ Created: swatchkit.config.js (cssDir: ${cliOptions.cssDir})`);
390
+ console.log(' Next: run "swatchkit scaffold" to set up your project.');
391
+ return;
392
+ }
393
+
394
+ // Interactive mode: prompt for CSS directory
395
+ const readline = require('readline');
396
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
397
+
398
+ rl.question('Where does your CSS live? [src/css]: ', (answer) => {
399
+ rl.close();
400
+ const cssDir = answer.trim() ? `./${answer.trim().replace(/^\.\//, '')}` : './src/css';
401
+ const content = generateConfig(cssDir);
402
+
403
+ if (fs.existsSync(configPath) && cliOptions.force) {
404
+ const backupPath = getBackupPath(configPath);
405
+ fs.copyFileSync(configPath, backupPath);
406
+ console.log(` ~ Backed up: swatchkit.config.js → ${path.basename(backupPath)}`);
407
+ }
408
+
409
+ fs.writeFileSync(configPath, content);
410
+ console.log(`+ Created: swatchkit.config.js (cssDir: ${cssDir})`);
411
+ console.log(' Next: run "swatchkit scaffold" to set up your project.');
412
+ });
413
+ }
414
+
415
+ // --- 6. Scaffold Command Logic (formerly init) ---
345
416
  function runInit(settings, options) {
346
417
  const isInitialized = fs.existsSync(settings.swatchkitDir);
347
418
 
@@ -418,6 +489,23 @@ function runInit(settings, options) {
418
489
  path.join(settings.cssDir, "utilities"),
419
490
  );
420
491
  }
492
+
493
+ const cwd2 = process.cwd();
494
+ const tokensDir = path.relative(cwd2, settings.tokensDir);
495
+ console.log(`
496
+ Done! Here's what to do next:
497
+
498
+ 1. Edit your design tokens in ${tokensDir}/
499
+ colors.json — your colour palette
500
+ text-sizes.json — fluid type scale
501
+ spacing.json — fluid spacing scale
502
+ fonts.json — font stacks
503
+ text-weights.json — font weights
504
+
505
+ 2. Run "swatchkit" to build the pattern library
506
+
507
+ 3. Open dist/swatchkit/index.html to view it
508
+ `);
421
509
  }
422
510
 
423
511
  // --- 6. Build Logic ---
@@ -716,13 +804,19 @@ function build(settings) {
716
804
  });
717
805
 
718
806
  // 6. Write JS Bundle
807
+ // Always prepend the internal token display script (resolves CSS custom
808
+ // property values shown in token documentation pages).
809
+ const tokenDisplayScript = fs.readFileSync(
810
+ path.join(__dirname, "src/templates/script.js"),
811
+ "utf-8",
812
+ );
813
+ const internalScript = `/* --- SwatchKit: token display --- */\n(function() {\n${tokenDisplayScript}\n})();`;
814
+ const allScripts = [internalScript, ...scripts];
815
+ fs.writeFileSync(settings.outputJsFile, allScripts.join("\n"));
719
816
  if (scripts.length > 0) {
720
- fs.writeFileSync(settings.outputJsFile, scripts.join("\n"));
721
817
  console.log(
722
- `Bundled ${scripts.length} scripts to ${settings.outputJsFile}`,
818
+ `Bundled ${scripts.length} swatch scripts to ${settings.outputJsFile}`,
723
819
  );
724
- } else {
725
- fs.writeFileSync(settings.outputJsFile, "// No swatch scripts found");
726
820
  }
727
821
 
728
822
  // 7. Generate preview pages (standalone full-screen view of each swatch)
@@ -882,19 +976,19 @@ function printHelp() {
882
976
  Usage: swatchkit [command] [options]
883
977
 
884
978
  Commands:
979
+ new Create a swatchkit.config.js for your project
980
+ scaffold Set up CSS blueprints, token files, and layout templates
885
981
  (default) Build the pattern library
886
- init Scaffold layout, tokens, and CSS blueprints
887
982
 
888
983
  Options:
889
984
  -w, --watch Watch files and rebuild on change
890
985
  -c, --config Path to config file
891
986
  -i, --input Pattern directory (default: swatchkit/)
892
987
  -o, --outDir Output directory (default: dist/swatchkit)
893
- -f, --force Overwrite all blueprint files with latest SwatchKit versions.
894
- Your existing files are backed up as .bak/.bak2 etc. before
895
- overwriting. Only css/global/tokens.css and
896
- css/utilities/tokens.css are excluded (auto-generated).
897
- --dry-run Show what init would create or change, without writing
988
+ --cssDir CSS directory, for use with "new" (default: src/css)
989
+ -f, --force Overwrite existing files (new: overwrites config,
990
+ scaffold: overwrites all blueprint files with backups)
991
+ --dry-run Show what scaffold would create or change, without writing
898
992
  -h, --help Show this help message
899
993
  -v, --version Show version number`);
900
994
  }
@@ -915,7 +1009,9 @@ try {
915
1009
  const fileConfig = loadConfig(cliOptions.config);
916
1010
  const settings = resolveSettings(cliOptions, fileConfig);
917
1011
 
918
- if (cliOptions.command === "init") {
1012
+ if (cliOptions.command === "new") {
1013
+ runNew(cliOptions);
1014
+ } else if (cliOptions.command === "scaffold") {
919
1015
  runInit(settings, cliOptions);
920
1016
  } else {
921
1017
  build(settings);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swatchkit",
3
- "version": "0.12.0",
3
+ "version": "1.0.1",
4
4
  "description": "A lightweight tool for creating HTML pattern libraries.",
5
5
  "main": "build.js",
6
6
  "bin": {