-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli-compare.js
More file actions
130 lines (107 loc) · 4.15 KB
/
Copy pathcli-compare.js
File metadata and controls
130 lines (107 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const WorkflowComparator = require('./compare-workflows');
function showUsage() {
console.log(`
🔧 N8N Workflow Comparator CLI
Usage:
node cli-compare.js <OLD_FILE> <NEW_FILE> [options]
Arguments:
OLD_FILE Path to the baseline/older workflow backup file
NEW_FILE Path to the newer workflow backup file to compare against
Options:
--help Show this help message
--json Output results as JSON
--summary Only show summary (no detailed changes)
--reverse Reverse comparison direction (NEW_FILE → OLD_FILE)
Examples:
# Compare workflows_old as OLD vs workflows_new as NEW
node cli-compare.js "workflows_old.json" "workflows_new.json"
# Quick summary only
node cli-compare.js ./backup1.json ./backup2.json --summary
# JSON output for further processing
node cli-compare.js file1.json file2.json --json > report.json
# Reverse comparison direction
node cli-compare.js file1.json file2.json --reverse
Note: The comparison shows changes from OLD_FILE → NEW_FILE
- "Added" means present in NEW_FILE but not in OLD_FILE
- "Removed" means present in OLD_FILE but not in NEW_FILE
`);
}
function main() {
const args = process.argv.slice(2);
// Check for help flag
if (args.includes('--help') || args.length < 2) {
showUsage();
return;
}
const INPUT_DIR_NAME = 'data';
let file1Path = path.resolve(INPUT_DIR_NAME, args[0]);
let file2Path = path.resolve(INPUT_DIR_NAME, args[1]);
const outputJson = args.includes('--json');
const summaryOnly = args.includes('--summary');
const reverse = args.includes('--reverse');
// Handle reverse comparison
if (reverse) {
[file1Path, file2Path] = [file2Path, file1Path];
console.log('🔄 Reverse comparison enabled: NEW → OLD\n');
}
// Validate files exist
if (!fs.existsSync(file1Path)) {
console.error(`❌ File not found: ${file1Path}`);
process.exit(1);
}
if (!fs.existsSync(file2Path)) {
console.error(`❌ File not found: ${file2Path}`);
process.exit(1);
}
console.log(`🔍 Workflow Comparison Setup:`);
console.log(` 📁 OLD (baseline): ${path.basename(file1Path)}`);
console.log(` 📁 NEW (compared): ${path.basename(file2Path)}`);
console.log(` 🔄 Direction: ${path.basename(file1Path)} → ${path.basename(file2Path)}\n`);
// Create custom comparator for CLI
class CLIWorkflowComparator extends WorkflowComparator {
printResults() {
if (outputJson) {
// Output JSON format
const jsonResult = {
comparison: {
direction: `${path.basename(file1Path)} → ${path.basename(file2Path)}`,
oldFile: {
path: file1Path,
name: path.basename(file1Path)
},
newFile: {
path: file2Path,
name: path.basename(file2Path)
}
},
summary: {
added: this.results.added.length,
removed: this.results.removed.length,
modified: this.results.modified.length,
unchanged: this.results.unchanged.length
},
timestamp: new Date().toISOString(),
results: this.results
};
console.log(JSON.stringify(jsonResult, null, 2));
return;
}
// Call parent method for normal output
super.printResults();
}
generateDetailedReport() {
if (summaryOnly || outputJson) {
return; // Skip detailed report
}
super.generateDetailedReport();
}
}
const comparator = new CLIWorkflowComparator();
comparator.compareWorkflowFiles(file1Path, file2Path);
}
if (require.main === module) {
main();
}