swatchkit 0.12.0 → 1.0.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.
- package/README.md +35 -28
- package/build.js +86 -11
- 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.
|
|
13
|
-
npx swatchkit
|
|
12
|
+
# 1. Create a config (sets your CSS location and preferences)
|
|
13
|
+
npx swatchkit new
|
|
14
14
|
|
|
15
|
-
# 2.
|
|
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
|
|
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
|
|
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
|
|
207
|
-
Copies "blueprints" into your project to get you started.
|
|
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
|
|
211
|
-
* **`--force`:** Overwrites all
|
|
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 `
|
|
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
|
|
243
|
-
| `swatchkit/_layout.html`| ✅ **YES** | Safe during normal use. `
|
|
244
|
-
| `swatchkit/_preview.html`| ✅ **YES** | Same as `_layout.html` — safe unless you run `
|
|
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`
|
|
256
|
-
- `swatchkit
|
|
257
|
-
- `swatchkit
|
|
258
|
-
- `swatchkit
|
|
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
|
-
| `--
|
|
269
|
-
| `--
|
|
270
|
-
| `--
|
|
271
|
-
| `--
|
|
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
|
-
|
|
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 === "
|
|
28
|
-
options.command = "
|
|
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;
|
|
@@ -336,12 +343,78 @@ function reportInitStatus(settings) {
|
|
|
336
343
|
|
|
337
344
|
if (changed.length > 0 || created.length > 0 || newDirs.length > 0) {
|
|
338
345
|
console.log(
|
|
339
|
-
" Run 'swatchkit
|
|
346
|
+
" Run 'swatchkit scaffold --force' to update all files to latest blueprints.\n",
|
|
340
347
|
);
|
|
341
348
|
}
|
|
342
349
|
}
|
|
343
350
|
|
|
344
|
-
// --- 5.
|
|
351
|
+
// --- 5. New Command Logic ---
|
|
352
|
+
function generateConfig(cssDir) {
|
|
353
|
+
const isDefaultCssDir = cssDir === './src/css';
|
|
354
|
+
return `// swatchkit.config.js
|
|
355
|
+
module.exports = {
|
|
356
|
+
// Where your CSS lives. SwatchKit scaffolds blueprints here and reads
|
|
357
|
+
// tokens from here when building the pattern library.
|
|
358
|
+
cssDir: "${cssDir}",
|
|
359
|
+
|
|
360
|
+
// Set to true if SwatchKit should copy your CSS into its output directory,
|
|
361
|
+
// making the pattern library self-contained. Set to false if a build tool
|
|
362
|
+
// (Vite, Astro, Eleventy, etc.) is already handling your CSS.
|
|
363
|
+
cssCopy: ${isDefaultCssDir ? 'false' : 'true'},
|
|
364
|
+
|
|
365
|
+
// Where token JSON files live.
|
|
366
|
+
// tokensDir: "./tokens",
|
|
367
|
+
|
|
368
|
+
// Where the built pattern library is output.
|
|
369
|
+
// outDir: "./dist/swatchkit",
|
|
370
|
+
|
|
371
|
+
// Files or folders to exclude from the pattern library (supports globs).
|
|
372
|
+
// exclude: [],
|
|
373
|
+
};
|
|
374
|
+
`;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function runNew(cliOptions) {
|
|
378
|
+
const cwd = process.cwd();
|
|
379
|
+
const configPath = path.join(cwd, 'swatchkit.config.js');
|
|
380
|
+
|
|
381
|
+
if (fs.existsSync(configPath) && !cliOptions.force) {
|
|
382
|
+
console.log('[SwatchKit] swatchkit.config.js already exists.');
|
|
383
|
+
console.log(' Run "swatchkit new --force" to overwrite it.');
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Non-interactive mode: --cssDir flag provided
|
|
388
|
+
if (cliOptions.cssDir) {
|
|
389
|
+
const content = generateConfig(cliOptions.cssDir);
|
|
390
|
+
fs.writeFileSync(configPath, content);
|
|
391
|
+
console.log(`+ Created: swatchkit.config.js (cssDir: ${cliOptions.cssDir})`);
|
|
392
|
+
console.log(' Next: run "swatchkit scaffold" to set up your project.');
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Interactive mode: prompt for CSS directory
|
|
397
|
+
const readline = require('readline');
|
|
398
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
399
|
+
|
|
400
|
+
rl.question('Where does your CSS live? [src/css]: ', (answer) => {
|
|
401
|
+
rl.close();
|
|
402
|
+
const cssDir = answer.trim() ? `./${answer.trim().replace(/^\.\//, '')}` : './src/css';
|
|
403
|
+
const content = generateConfig(cssDir);
|
|
404
|
+
|
|
405
|
+
if (fs.existsSync(configPath) && cliOptions.force) {
|
|
406
|
+
const backupPath = getBackupPath(configPath);
|
|
407
|
+
fs.copyFileSync(configPath, backupPath);
|
|
408
|
+
console.log(` ~ Backed up: swatchkit.config.js → ${path.basename(backupPath)}`);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
fs.writeFileSync(configPath, content);
|
|
412
|
+
console.log(`+ Created: swatchkit.config.js (cssDir: ${cssDir})`);
|
|
413
|
+
console.log(' Next: run "swatchkit scaffold" to set up your project.');
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// --- 6. Scaffold Command Logic (formerly init) ---
|
|
345
418
|
function runInit(settings, options) {
|
|
346
419
|
const isInitialized = fs.existsSync(settings.swatchkitDir);
|
|
347
420
|
|
|
@@ -882,19 +955,19 @@ function printHelp() {
|
|
|
882
955
|
Usage: swatchkit [command] [options]
|
|
883
956
|
|
|
884
957
|
Commands:
|
|
958
|
+
new Create a swatchkit.config.js for your project
|
|
959
|
+
scaffold Set up CSS blueprints, token files, and layout templates
|
|
885
960
|
(default) Build the pattern library
|
|
886
|
-
init Scaffold layout, tokens, and CSS blueprints
|
|
887
961
|
|
|
888
962
|
Options:
|
|
889
963
|
-w, --watch Watch files and rebuild on change
|
|
890
964
|
-c, --config Path to config file
|
|
891
965
|
-i, --input Pattern directory (default: swatchkit/)
|
|
892
966
|
-o, --outDir Output directory (default: dist/swatchkit)
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
--dry-run Show what init would create or change, without writing
|
|
967
|
+
--cssDir CSS directory, for use with "new" (default: src/css)
|
|
968
|
+
-f, --force Overwrite existing files (new: overwrites config,
|
|
969
|
+
scaffold: overwrites all blueprint files with backups)
|
|
970
|
+
--dry-run Show what scaffold would create or change, without writing
|
|
898
971
|
-h, --help Show this help message
|
|
899
972
|
-v, --version Show version number`);
|
|
900
973
|
}
|
|
@@ -915,7 +988,9 @@ try {
|
|
|
915
988
|
const fileConfig = loadConfig(cliOptions.config);
|
|
916
989
|
const settings = resolveSettings(cliOptions, fileConfig);
|
|
917
990
|
|
|
918
|
-
if (cliOptions.command === "
|
|
991
|
+
if (cliOptions.command === "new") {
|
|
992
|
+
runNew(cliOptions);
|
|
993
|
+
} else if (cliOptions.command === "scaffold") {
|
|
919
994
|
runInit(settings, cliOptions);
|
|
920
995
|
} else {
|
|
921
996
|
build(settings);
|