swatchkit 0.9.4 → 0.11.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.
Files changed (2) hide show
  1. package/build.js +27 -1
  2. package/package.json +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);
@@ -863,7 +886,10 @@ Options:
863
886
  -c, --config Path to config file
864
887
  -i, --input Pattern directory (default: swatchkit/)
865
888
  -o, --outDir Output directory (default: dist/swatchkit)
866
- -f, --force Overwrite all init-managed files with latest blueprints
889
+ -f, --force Overwrite all blueprint files with latest SwatchKit versions.
890
+ Your existing files are backed up as .bak/.bak2 etc. before
891
+ overwriting. Only css/global/tokens.css and
892
+ css/utilities/tokens.css are excluded (auto-generated).
867
893
  --dry-run Show what init would create or change, without writing
868
894
  -h, --help Show this help message
869
895
  -v, --version Show version number`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swatchkit",
3
- "version": "0.9.4",
3
+ "version": "0.11.0",
4
4
  "description": "A lightweight tool for creating HTML pattern libraries.",
5
5
  "main": "build.js",
6
6
  "bin": {