sonance-brand-mcp 1.3.26 → 1.3.27
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.
|
@@ -50,7 +50,11 @@ interface ApplyFirstRequest {
|
|
|
50
50
|
interface BackupManifest {
|
|
51
51
|
sessionId: string;
|
|
52
52
|
timestamp: number;
|
|
53
|
-
files: {
|
|
53
|
+
files: {
|
|
54
|
+
original: string;
|
|
55
|
+
backup: string;
|
|
56
|
+
isNewFile: boolean; // Track if file was newly created (needs deletion on revert)
|
|
57
|
+
}[];
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
const BACKUP_ROOT = ".sonance-backups";
|
|
@@ -512,6 +516,15 @@ async function applyChangesWithBackup(
|
|
|
512
516
|
const backupDir = path.join(projectRoot, BACKUP_ROOT, sessionId);
|
|
513
517
|
const backupPaths: string[] = [];
|
|
514
518
|
|
|
519
|
+
// Track which files exist before we modify them
|
|
520
|
+
const existingFiles = new Set<string>();
|
|
521
|
+
for (const mod of modifications) {
|
|
522
|
+
const fullPath = path.join(projectRoot, mod.filePath);
|
|
523
|
+
if (fs.existsSync(fullPath)) {
|
|
524
|
+
existingFiles.add(mod.filePath);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
515
528
|
try {
|
|
516
529
|
// Step 1: Create backup directory
|
|
517
530
|
fs.mkdirSync(backupDir, { recursive: true });
|
|
@@ -520,7 +533,7 @@ async function applyChangesWithBackup(
|
|
|
520
533
|
for (const mod of modifications) {
|
|
521
534
|
const fullPath = path.join(projectRoot, mod.filePath);
|
|
522
535
|
|
|
523
|
-
if (
|
|
536
|
+
if (existingFiles.has(mod.filePath)) {
|
|
524
537
|
const backupPath = path.join(backupDir, mod.filePath);
|
|
525
538
|
const backupDirForFile = path.dirname(backupPath);
|
|
526
539
|
|
|
@@ -530,13 +543,14 @@ async function applyChangesWithBackup(
|
|
|
530
543
|
}
|
|
531
544
|
}
|
|
532
545
|
|
|
533
|
-
// Step 3: Write manifest
|
|
546
|
+
// Step 3: Write manifest (track which files are new)
|
|
534
547
|
const manifest: BackupManifest = {
|
|
535
548
|
sessionId,
|
|
536
549
|
timestamp: Date.now(),
|
|
537
550
|
files: modifications.map(m => ({
|
|
538
551
|
original: m.filePath,
|
|
539
552
|
backup: path.join(backupDir, m.filePath),
|
|
553
|
+
isNewFile: !existingFiles.has(m.filePath), // Track if file was newly created
|
|
540
554
|
})),
|
|
541
555
|
};
|
|
542
556
|
|
|
@@ -616,24 +630,51 @@ async function revertFromBackups(
|
|
|
616
630
|
);
|
|
617
631
|
|
|
618
632
|
let filesReverted = 0;
|
|
633
|
+
let filesDeleted = 0;
|
|
619
634
|
|
|
620
635
|
for (const file of manifest.files) {
|
|
621
|
-
const backupPath = path.join(backupDir, file.original);
|
|
622
636
|
const originalPath = path.join(projectRoot, file.original);
|
|
623
637
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
638
|
+
// Handle new files - delete them
|
|
639
|
+
if (file.isNewFile) {
|
|
640
|
+
if (fs.existsSync(originalPath)) {
|
|
641
|
+
fs.unlinkSync(originalPath);
|
|
642
|
+
filesDeleted++;
|
|
643
|
+
console.log(`[Revert] Deleted new file: ${file.original}`);
|
|
644
|
+
|
|
645
|
+
// Clean up empty parent directories
|
|
646
|
+
try {
|
|
647
|
+
const parentDir = path.dirname(originalPath);
|
|
648
|
+
const entries = fs.readdirSync(parentDir);
|
|
649
|
+
if (entries.length === 0) {
|
|
650
|
+
fs.rmdirSync(parentDir);
|
|
651
|
+
console.log(`[Revert] Removed empty directory: ${path.dirname(file.original)}`);
|
|
652
|
+
}
|
|
653
|
+
} catch {
|
|
654
|
+
// Ignore errors when cleaning up directories
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
} else {
|
|
658
|
+
// Handle existing files - restore from backup
|
|
659
|
+
const backupPath = path.join(backupDir, file.original);
|
|
660
|
+
if (fs.existsSync(backupPath)) {
|
|
661
|
+
fs.copyFileSync(backupPath, originalPath);
|
|
662
|
+
filesReverted++;
|
|
663
|
+
}
|
|
627
664
|
}
|
|
628
665
|
}
|
|
629
666
|
|
|
630
667
|
// Delete backup directory after successful revert
|
|
631
668
|
fs.rmSync(backupDir, { recursive: true });
|
|
632
669
|
|
|
670
|
+
const message = filesDeleted > 0
|
|
671
|
+
? `Reverted ${filesReverted} file(s), deleted ${filesDeleted} new file(s)`
|
|
672
|
+
: `Reverted ${filesReverted} file(s)`;
|
|
673
|
+
|
|
633
674
|
return {
|
|
634
675
|
success: true,
|
|
635
|
-
message
|
|
636
|
-
filesReverted,
|
|
676
|
+
message,
|
|
677
|
+
filesReverted: filesReverted + filesDeleted,
|
|
637
678
|
};
|
|
638
679
|
} catch (error) {
|
|
639
680
|
console.error("Error reverting from backups:", error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sonance-brand-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.27",
|
|
4
4
|
"description": "MCP Server for Sonance Brand Guidelines and Component Library - gives Claude instant access to brand colors, typography, and UI components.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|