swatchkit 0.10.0 → 0.11.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.
- package/build.js +35 -5
- package/package.json +1 -1
- package/src/layout.html +1 -1
package/build.js
CHANGED
|
@@ -182,6 +182,16 @@ function resolveSettings(cliOptions, fileConfig) {
|
|
|
182
182
|
// Builds a list of all files that init manages.
|
|
183
183
|
// Each entry maps a blueprint source to a project destination.
|
|
184
184
|
// Used by both the actual init and the dry-run status report.
|
|
185
|
+
// Returns the next available backup path for a file.
|
|
186
|
+
// e.g. foo.css → foo.css.bak, then foo.css.bak2, foo.css.bak3, etc.
|
|
187
|
+
function getBackupPath(filePath) {
|
|
188
|
+
const candidate = `${filePath}.bak`;
|
|
189
|
+
if (!fs.existsSync(candidate)) return candidate;
|
|
190
|
+
let i = 2;
|
|
191
|
+
while (fs.existsSync(`${filePath}.bak${i}`)) i++;
|
|
192
|
+
return `${filePath}.bak${i}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
185
195
|
function buildInitManifest(settings) {
|
|
186
196
|
const manifest = [];
|
|
187
197
|
const blueprintsDir = path.join(__dirname, "src/blueprints");
|
|
@@ -364,6 +374,12 @@ function runInit(settings, options) {
|
|
|
364
374
|
}
|
|
365
375
|
}
|
|
366
376
|
|
|
377
|
+
// Files that are auto-generated by SwatchKit — never back these up
|
|
378
|
+
const swatchkitOwned = [
|
|
379
|
+
path.join(settings.cssDir, "global", "tokens.css"),
|
|
380
|
+
path.join(settings.cssDir, "utilities", "tokens.css"),
|
|
381
|
+
];
|
|
382
|
+
|
|
367
383
|
// Copy all manifest files
|
|
368
384
|
const manifest = buildInitManifest(settings);
|
|
369
385
|
for (const entry of manifest) {
|
|
@@ -375,6 +391,13 @@ function runInit(settings, options) {
|
|
|
375
391
|
fs.mkdirSync(parentDir, { recursive: true });
|
|
376
392
|
}
|
|
377
393
|
|
|
394
|
+
// Back up existing user-owned files before overwriting with --force
|
|
395
|
+
if (exists && options.force && !swatchkitOwned.includes(entry.dest)) {
|
|
396
|
+
const backupPath = getBackupPath(entry.dest);
|
|
397
|
+
fs.copyFileSync(entry.dest, backupPath);
|
|
398
|
+
console.log(` ~ Backed up: ${path.relative(cwd, entry.dest)} → ${path.basename(backupPath)}`);
|
|
399
|
+
}
|
|
400
|
+
|
|
378
401
|
let content = fs.readFileSync(entry.src, "utf-8");
|
|
379
402
|
if (entry.transform) content = entry.transform(content);
|
|
380
403
|
fs.writeFileSync(entry.dest, content);
|
|
@@ -675,13 +698,17 @@ function build(settings) {
|
|
|
675
698
|
const previewPath = p.sectionSlug
|
|
676
699
|
? `preview/${p.sectionSlug}/${p.id}.html`
|
|
677
700
|
: `preview/${p.id}.html`;
|
|
701
|
+
const previewLink = previewPath.replace(/\.html$/, '');
|
|
678
702
|
|
|
679
703
|
return `
|
|
680
|
-
<section id="${p.id}" class="flow">
|
|
704
|
+
<section id="${p.id}" class="region flow">
|
|
681
705
|
<h2>${p.name} <small style="font-weight: normal; opacity: 0.6; font-size: 0.7em">(${section})</small></h2>
|
|
682
|
-
<
|
|
683
|
-
<div class="swatchkit-preview-link"><a href="${
|
|
684
|
-
<
|
|
706
|
+
<iframe src="${previewPath}" style="width: 100%; border: var(--stroke); min-height: 25rem; resize: vertical; overflow: auto;"></iframe>
|
|
707
|
+
<div class="swatchkit-preview-link"><a href="${previewLink}">View full screen</a></div>
|
|
708
|
+
<details>
|
|
709
|
+
<summary>View source</summary>
|
|
710
|
+
<pre><code>${escapedContent}</code></pre>
|
|
711
|
+
</details>
|
|
685
712
|
</section>
|
|
686
713
|
`;
|
|
687
714
|
})
|
|
@@ -863,7 +890,10 @@ Options:
|
|
|
863
890
|
-c, --config Path to config file
|
|
864
891
|
-i, --input Pattern directory (default: swatchkit/)
|
|
865
892
|
-o, --outDir Output directory (default: dist/swatchkit)
|
|
866
|
-
-f, --force Overwrite all
|
|
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).
|
|
867
897
|
--dry-run Show what init would create or change, without writing
|
|
868
898
|
-h, --help Show this help message
|
|
869
899
|
-v, --version Show version number`);
|
package/package.json
CHANGED