swatchkit 1.0.0 → 1.1.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/build.js +62 -12
- package/package.json +1 -1
package/build.js
CHANGED
|
@@ -222,7 +222,7 @@ function buildInitManifest(settings) {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
// Template files (swatchkit/tokens/)
|
|
225
|
-
const templateFiles = ["prose.html"
|
|
225
|
+
const templateFiles = ["prose.html"];
|
|
226
226
|
for (const file of templateFiles) {
|
|
227
227
|
manifest.push({
|
|
228
228
|
src: path.join(templatesDir, file),
|
|
@@ -231,6 +231,26 @@ function buildInitManifest(settings) {
|
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
+
// Utility and composition display templates — walk each subfolder
|
|
235
|
+
for (const section of ["utilities", "compositions"]) {
|
|
236
|
+
const sectionSrc = path.join(templatesDir, section);
|
|
237
|
+
if (!fs.existsSync(sectionSrc)) continue;
|
|
238
|
+
const folders = fs.readdirSync(sectionSrc).filter(f =>
|
|
239
|
+
fs.statSync(path.join(sectionSrc, f)).isDirectory()
|
|
240
|
+
);
|
|
241
|
+
for (const folder of folders) {
|
|
242
|
+
const folderSrc = path.join(sectionSrc, folder);
|
|
243
|
+
const files = fs.readdirSync(folderSrc).filter(f => f.endsWith(".html"));
|
|
244
|
+
for (const file of files) {
|
|
245
|
+
manifest.push({
|
|
246
|
+
src: path.join(folderSrc, file),
|
|
247
|
+
dest: path.join(settings.swatchkitDir, section, folder, file),
|
|
248
|
+
transform: (content) => content.trim(),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
234
254
|
// CSS entry point
|
|
235
255
|
manifest.push({
|
|
236
256
|
src: path.join(blueprintsDir, "main.css"),
|
|
@@ -279,6 +299,8 @@ function getInitDirs(settings) {
|
|
|
279
299
|
settings.swatchkitDir,
|
|
280
300
|
settings.tokensDir,
|
|
281
301
|
path.join(settings.swatchkitDir, "tokens"),
|
|
302
|
+
path.join(settings.swatchkitDir, "utilities"),
|
|
303
|
+
path.join(settings.swatchkitDir, "compositions"),
|
|
282
304
|
settings.cssDir,
|
|
283
305
|
path.join(settings.cssDir, "global"),
|
|
284
306
|
];
|
|
@@ -350,17 +372,15 @@ function reportInitStatus(settings) {
|
|
|
350
372
|
|
|
351
373
|
// --- 5. New Command Logic ---
|
|
352
374
|
function generateConfig(cssDir) {
|
|
353
|
-
const isDefaultCssDir = cssDir === './src/css';
|
|
354
375
|
return `// swatchkit.config.js
|
|
355
376
|
module.exports = {
|
|
356
377
|
// Where your CSS lives. SwatchKit scaffolds blueprints here and reads
|
|
357
378
|
// tokens from here when building the pattern library.
|
|
358
379
|
cssDir: "${cssDir}",
|
|
359
380
|
|
|
360
|
-
// Set to
|
|
361
|
-
//
|
|
362
|
-
|
|
363
|
-
cssCopy: ${isDefaultCssDir ? 'false' : 'true'},
|
|
381
|
+
// Set to false if a build tool (Vite, Astro, Eleventy, etc.) is already
|
|
382
|
+
// handling your CSS and you don't need SwatchKit to copy it.
|
|
383
|
+
cssCopy: true,
|
|
364
384
|
|
|
365
385
|
// Where token JSON files live.
|
|
366
386
|
// tokensDir: "./tokens",
|
|
@@ -491,6 +511,23 @@ function runInit(settings, options) {
|
|
|
491
511
|
path.join(settings.cssDir, "utilities"),
|
|
492
512
|
);
|
|
493
513
|
}
|
|
514
|
+
|
|
515
|
+
const cwd2 = process.cwd();
|
|
516
|
+
const tokensDir = path.relative(cwd2, settings.tokensDir);
|
|
517
|
+
console.log(`
|
|
518
|
+
Done! Here's what to do next:
|
|
519
|
+
|
|
520
|
+
1. Edit your design tokens in ${tokensDir}/
|
|
521
|
+
colors.json — your colour palette
|
|
522
|
+
text-sizes.json — fluid type scale
|
|
523
|
+
spacing.json — fluid spacing scale
|
|
524
|
+
fonts.json — font stacks
|
|
525
|
+
text-weights.json — font weights
|
|
526
|
+
|
|
527
|
+
2. Run "swatchkit" to build the pattern library
|
|
528
|
+
|
|
529
|
+
3. Open dist/swatchkit/index.html to view it
|
|
530
|
+
`);
|
|
494
531
|
}
|
|
495
532
|
|
|
496
533
|
// --- 6. Build Logic ---
|
|
@@ -529,7 +566,7 @@ function scanSwatches(dir, scriptsCollector, exclude = []) {
|
|
|
529
566
|
const itemPath = path.join(dir, item);
|
|
530
567
|
const stat = fs.statSync(itemPath);
|
|
531
568
|
|
|
532
|
-
let name, content, id;
|
|
569
|
+
let name, content, id, description;
|
|
533
570
|
|
|
534
571
|
// Handle Component Directory
|
|
535
572
|
if (stat.isDirectory()) {
|
|
@@ -540,6 +577,12 @@ function scanSwatches(dir, scriptsCollector, exclude = []) {
|
|
|
540
577
|
id = item;
|
|
541
578
|
content = fs.readFileSync(indexFile, "utf-8");
|
|
542
579
|
|
|
580
|
+
// Optional description shown above the iframe in the main UI
|
|
581
|
+
const descriptionFile = path.join(itemPath, "description.html");
|
|
582
|
+
if (fs.existsSync(descriptionFile)) {
|
|
583
|
+
description = fs.readFileSync(descriptionFile, "utf-8");
|
|
584
|
+
}
|
|
585
|
+
|
|
543
586
|
// Find all .js files
|
|
544
587
|
const jsFiles = fs
|
|
545
588
|
.readdirSync(itemPath)
|
|
@@ -579,7 +622,7 @@ ${scriptContent}
|
|
|
579
622
|
}
|
|
580
623
|
|
|
581
624
|
if (name && content) {
|
|
582
|
-
swatches.push({ name, id, content });
|
|
625
|
+
swatches.push({ name, id, content, description: description || null });
|
|
583
626
|
}
|
|
584
627
|
});
|
|
585
628
|
|
|
@@ -776,6 +819,7 @@ function build(settings) {
|
|
|
776
819
|
return `
|
|
777
820
|
<section id="${p.id}" class="region flow">
|
|
778
821
|
<h2>${p.name} <small style="font-weight: normal; opacity: 0.6; font-size: 0.7em">(${section})</small></h2>
|
|
822
|
+
${p.description ? `<div class="swatch-description">${p.description}</div>` : ''}
|
|
779
823
|
<iframe src="${previewPath}" style="width: 100%; border: var(--stroke); min-height: 25rem; resize: vertical; overflow: auto;"></iframe>
|
|
780
824
|
<div class="swatchkit-preview-link"><a href="${previewLink}">View full screen</a></div>
|
|
781
825
|
<details>
|
|
@@ -789,13 +833,19 @@ function build(settings) {
|
|
|
789
833
|
});
|
|
790
834
|
|
|
791
835
|
// 6. Write JS Bundle
|
|
836
|
+
// Always prepend the internal token display script (resolves CSS custom
|
|
837
|
+
// property values shown in token documentation pages).
|
|
838
|
+
const tokenDisplayScript = fs.readFileSync(
|
|
839
|
+
path.join(__dirname, "src/templates/script.js"),
|
|
840
|
+
"utf-8",
|
|
841
|
+
);
|
|
842
|
+
const internalScript = `/* --- SwatchKit: token display --- */\n(function() {\n${tokenDisplayScript}\n})();`;
|
|
843
|
+
const allScripts = [internalScript, ...scripts];
|
|
844
|
+
fs.writeFileSync(settings.outputJsFile, allScripts.join("\n"));
|
|
792
845
|
if (scripts.length > 0) {
|
|
793
|
-
fs.writeFileSync(settings.outputJsFile, scripts.join("\n"));
|
|
794
846
|
console.log(
|
|
795
|
-
`Bundled ${scripts.length} scripts to ${settings.outputJsFile}`,
|
|
847
|
+
`Bundled ${scripts.length} swatch scripts to ${settings.outputJsFile}`,
|
|
796
848
|
);
|
|
797
|
-
} else {
|
|
798
|
-
fs.writeFileSync(settings.outputJsFile, "// No swatch scripts found");
|
|
799
849
|
}
|
|
800
850
|
|
|
801
851
|
// 7. Generate preview pages (standalone full-screen view of each swatch)
|