swatchkit 0.6.1 → 0.7.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 +72 -0
- package/build.js +30 -6
- package/package.json +1 -1
- package/src/layout.html +2 -2
package/README.md
CHANGED
|
@@ -270,11 +270,83 @@ module.exports = {
|
|
|
270
270
|
// Override tokens directory (JSON token definitions)
|
|
271
271
|
tokensDir: "./src/tokens",
|
|
272
272
|
|
|
273
|
+
// Skip copying CSS into SwatchKit's output directory.
|
|
274
|
+
// When false, SwatchKit references CSS at cssPath instead of copying it.
|
|
275
|
+
// See "Common Workflows" below for when to use this.
|
|
276
|
+
cssCopy: false,
|
|
277
|
+
|
|
278
|
+
// Relative path from SwatchKit's HTML to your CSS files.
|
|
279
|
+
// Only relevant when cssCopy is false.
|
|
280
|
+
// Defaults to "../<basename of cssDir>/" (e.g., "../css/" if cssDir is "./src/css").
|
|
281
|
+
// Set explicitly if your deployed CSS lives at a different path.
|
|
282
|
+
cssPath: "../css/",
|
|
283
|
+
|
|
273
284
|
// Exclude files (supports glob patterns)
|
|
274
285
|
exclude: ["*.test.js", "temp*"],
|
|
275
286
|
};
|
|
276
287
|
```
|
|
277
288
|
|
|
289
|
+
## Common Workflows
|
|
290
|
+
|
|
291
|
+
### Deploy alongside your project
|
|
292
|
+
|
|
293
|
+
If your build tool (Vite, Astro, etc.) already outputs CSS to `dist/`, you don't need SwatchKit to copy it again. Set `cssCopy: false` and SwatchKit's HTML will reference your existing CSS.
|
|
294
|
+
|
|
295
|
+
```javascript
|
|
296
|
+
// swatchkit.config.js
|
|
297
|
+
module.exports = {
|
|
298
|
+
cssDir: "./src/css",
|
|
299
|
+
cssCopy: false,
|
|
300
|
+
};
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
```
|
|
304
|
+
dist/
|
|
305
|
+
├── css/ # Your build tool puts CSS here
|
|
306
|
+
│ ├── main.css
|
|
307
|
+
│ └── tokens.css
|
|
308
|
+
├── index.html # Your project
|
|
309
|
+
└── swatchkit/
|
|
310
|
+
└── index.html # References ../css/main.css
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
SwatchKit derives the default `cssPath` from your `cssDir` name. If `cssDir` is `"./src/css"`, it defaults to `"../css/"`. If `cssDir` is `"./styles"`, it defaults to `"../styles/"`.
|
|
314
|
+
|
|
315
|
+
If your deployed CSS ends up somewhere else (e.g., Vite hashes it into `dist/assets/`), set `cssPath` explicitly:
|
|
316
|
+
|
|
317
|
+
```javascript
|
|
318
|
+
module.exports = {
|
|
319
|
+
cssDir: "./src/css",
|
|
320
|
+
cssCopy: false,
|
|
321
|
+
cssPath: "../assets/",
|
|
322
|
+
};
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Local dev only (self-contained)
|
|
326
|
+
|
|
327
|
+
If SwatchKit is just a development tool and you don't want it in `dist/`, set `outDir` to a separate directory. Keep `cssCopy` enabled (the default) so the output is fully self-contained.
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
// swatchkit.config.js
|
|
331
|
+
module.exports = {
|
|
332
|
+
cssDir: "./src/css",
|
|
333
|
+
outDir: "swatchkit-dist",
|
|
334
|
+
};
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
```
|
|
338
|
+
my-project/
|
|
339
|
+
├── dist/ # Your production build (no SwatchKit)
|
|
340
|
+
│ └── ...
|
|
341
|
+
└── swatchkit-dist/ # Self-contained, serve locally during dev
|
|
342
|
+
├── css/
|
|
343
|
+
│ ├── main.css
|
|
344
|
+
│ └── tokens.css
|
|
345
|
+
└── index.html
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
You can serve `swatchkit-dist/` locally during development without affecting your production build.
|
|
349
|
+
|
|
278
350
|
## Using with a Framework
|
|
279
351
|
|
|
280
352
|
SwatchKit outputs to `dist/swatchkit/` by default. If your framework (Vite, Astro, etc.) cleans the `dist/` directory during its build, run SwatchKit **after** your framework build:
|
package/build.js
CHANGED
|
@@ -132,12 +132,24 @@ function resolveSettings(cliOptions, fileConfig) {
|
|
|
132
132
|
// Exclude patterns
|
|
133
133
|
const exclude = fileConfig.exclude || [];
|
|
134
134
|
|
|
135
|
+
// CSS copy behavior
|
|
136
|
+
// When true (default), copies cssDir into outDir/css/ for a self-contained build.
|
|
137
|
+
// When false, skips the copy — expects CSS to already exist at cssPath relative to output.
|
|
138
|
+
const cssCopy = fileConfig.cssCopy !== undefined ? fileConfig.cssCopy : true;
|
|
139
|
+
|
|
140
|
+
// Relative path from SwatchKit HTML output to the user's CSS directory.
|
|
141
|
+
// Only used when cssCopy is false. Derived from cssDir basename by default
|
|
142
|
+
// (e.g., cssDir: "./src/css" -> "../css/", cssDir: "./styles" -> "../styles/").
|
|
143
|
+
const cssPath = fileConfig.cssPath || (cssCopy ? "css/" : `../${path.basename(cssDir)}/`);
|
|
144
|
+
|
|
135
145
|
return {
|
|
136
146
|
swatchkitDir,
|
|
137
147
|
outDir,
|
|
138
148
|
cssDir,
|
|
139
149
|
tokensDir,
|
|
140
150
|
exclude,
|
|
151
|
+
cssCopy,
|
|
152
|
+
cssPath,
|
|
141
153
|
fileConfig, // Expose config to init
|
|
142
154
|
// Internal layout templates (relative to this script)
|
|
143
155
|
internalLayout: path.join(__dirname, "src/layout.html"),
|
|
@@ -467,7 +479,9 @@ function build(settings) {
|
|
|
467
479
|
}
|
|
468
480
|
|
|
469
481
|
// 3. Ensure dist directories exist
|
|
470
|
-
[settings.outDir, settings.
|
|
482
|
+
const distDirs = [settings.outDir, settings.distJsDir];
|
|
483
|
+
if (settings.cssCopy) distDirs.push(settings.distCssDir);
|
|
484
|
+
distDirs.forEach((dir) => {
|
|
471
485
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
472
486
|
});
|
|
473
487
|
|
|
@@ -490,10 +504,12 @@ function build(settings) {
|
|
|
490
504
|
}
|
|
491
505
|
}
|
|
492
506
|
|
|
493
|
-
// 3. Copy CSS files (recursively)
|
|
494
|
-
if (fs.existsSync(settings.cssDir)) {
|
|
507
|
+
// 3. Copy CSS files (recursively) — skip if cssCopy is disabled
|
|
508
|
+
if (settings.cssCopy && fs.existsSync(settings.cssDir)) {
|
|
495
509
|
console.log("Copying static CSS assets (css/*)...");
|
|
496
510
|
copyDir(settings.cssDir, settings.distCssDir, true);
|
|
511
|
+
} else if (!settings.cssCopy) {
|
|
512
|
+
console.log(`Skipping CSS copy (cssCopy: false). CSS referenced at: ${settings.cssPath}`);
|
|
497
513
|
}
|
|
498
514
|
|
|
499
515
|
// 4. Read swatches & JS
|
|
@@ -651,25 +667,32 @@ function build(settings) {
|
|
|
651
667
|
sortedKeys.forEach((section) => {
|
|
652
668
|
const swatches = sections[section];
|
|
653
669
|
swatches.forEach((p) => {
|
|
654
|
-
// Determine output path and relative CSS path
|
|
670
|
+
// Determine output path and relative CSS path.
|
|
671
|
+
// Preview pages need to navigate up to the swatchkit output root,
|
|
672
|
+
// then follow cssPath to reach the CSS files.
|
|
655
673
|
let previewFile, cssPath;
|
|
656
674
|
if (p.sectionSlug) {
|
|
657
675
|
const sectionDir = path.join(settings.distPreviewDir, p.sectionSlug);
|
|
658
676
|
if (!fs.existsSync(sectionDir))
|
|
659
677
|
fs.mkdirSync(sectionDir, { recursive: true });
|
|
660
678
|
previewFile = path.join(sectionDir, `${p.id}.html`);
|
|
661
|
-
cssPath = "../../"; // preview/section/file.html -> ../../
|
|
679
|
+
cssPath = "../../" + settings.cssPath; // preview/section/file.html -> ../../ + cssPath
|
|
662
680
|
} else {
|
|
663
681
|
if (!fs.existsSync(settings.distPreviewDir))
|
|
664
682
|
fs.mkdirSync(settings.distPreviewDir, { recursive: true });
|
|
665
683
|
previewFile = path.join(settings.distPreviewDir, `${p.id}.html`);
|
|
666
|
-
cssPath = "../"; // preview/file.html -> ../
|
|
684
|
+
cssPath = "../" + settings.cssPath; // preview/file.html -> ../ + cssPath
|
|
667
685
|
}
|
|
668
686
|
|
|
687
|
+
// JS always lives in the swatchkit output dir, so jsPath just
|
|
688
|
+
// navigates back to the output root (not to the user's CSS dir).
|
|
689
|
+
const jsPath = p.sectionSlug ? "../../" : "../";
|
|
690
|
+
|
|
669
691
|
const previewHtml = previewLayoutContent
|
|
670
692
|
.replace("<!-- PREVIEW_TITLE -->", p.name)
|
|
671
693
|
.replace("<!-- PREVIEW_CONTENT -->", p.content)
|
|
672
694
|
.replaceAll("<!-- CSS_PATH -->", cssPath)
|
|
695
|
+
.replaceAll("<!-- JS_PATH -->", jsPath)
|
|
673
696
|
.replace("<!-- HEAD_EXTRAS -->", "");
|
|
674
697
|
|
|
675
698
|
fs.writeFileSync(previewFile, previewHtml);
|
|
@@ -697,6 +720,7 @@ function build(settings) {
|
|
|
697
720
|
const finalHtml = layoutContent
|
|
698
721
|
.replace("<!-- SIDEBAR_LINKS -->", sidebarLinks)
|
|
699
722
|
.replace("<!-- SWATCHES -->", swatchBlocks)
|
|
723
|
+
.replaceAll("<!-- CSS_PATH -->", settings.cssPath)
|
|
700
724
|
.replace("<!-- HEAD_EXTRAS -->", headExtras);
|
|
701
725
|
|
|
702
726
|
// 9. Write output
|
package/package.json
CHANGED
package/src/layout.html
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
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="
|
|
8
|
-
<link rel="stylesheet" href="
|
|
7
|
+
<link rel="stylesheet" href="<!-- CSS_PATH -->main.css" />
|
|
8
|
+
<link rel="stylesheet" href="<!-- CSS_PATH -->swatchkit-ui.css" />
|
|
9
9
|
<!-- HEAD_EXTRAS -->
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|