Skip to content

Commit 8c9c0e1

Browse files
Adding a New Feature and Fixing Diffs
- [X] Added new `--filter` flag to allow filtering results to matches only - [X] Fixed DIFF as I had the order backwards so modifications were shown in reverse
1 parent 5781998 commit 8c9c0e1

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Name | Param | Alias | Definition
5555
Cartridge | `--cartridge` | `-c` | Source Cartridge
5656
Diff | `--diff` | `-d` | Show Full Diff
5757
Exclude | `--exclude` | `-e` | List of Cartridges to Exclude
58+
Filter | `--filter` | `-f` | Filter Results for Match
5859
Include | `--include` | `-i` | List of Cartridges to Include
5960
Junk Only | `--junk-only` | `-j` | Junk Files Only
6061
Modified Only | `--modified-only` | `-m` | Modified Files Only
@@ -107,6 +108,15 @@ sfcc-diff --cartridge app_client_name --junk-only
107108
sfcc-diff -c app_client_name -j
108109
```
109110

111+
#### Comparing Client Cartridge to All Cartridges and Filtering for ISML Files:
112+
113+
> If you want to limit the results to just what matches a filter, you can use the `--filter` flag. This will match on the entire relative URL, not just the file name.
114+
115+
```bash
116+
sfcc-diff --cartridge app_client_name --filter .isml
117+
sfcc-diff -c app_client_name -f .isml
118+
```
119+
110120
#### Comparing Client Cartridge to Specific Cartridge and Generate Diff:
111121

112122
> Want to actually see the changes between cartridge files? Just pass in a the Diff option and it will render it in your terminal window.

bin/cli.js

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const cli = yargs
2727
describe: 'List of Cartridges to Exclude',
2828
type: 'array'
2929
},
30+
filter: {
31+
alias: 'f',
32+
describe: 'Filter Results for Match',
33+
type: 'string'
34+
},
3035
include: {
3136
alias: 'i',
3237
describe: 'List of Cartridges to Include',
@@ -49,6 +54,8 @@ const cli = yargs
4954
.example('sfcc-diff -c app_client_name --modified-only', 'Use Git Commit for Compare')
5055
.example('sfcc-diff -c app_client_name --junk-only', 'Just list Junk Files')
5156
.example('sfcc-diff -c app_client_name -m -d ksdiff', 'Modified Only and Diff')
57+
.example('sfcc-diff -c app_client_name -f .isml', 'Filter for ISML files')
58+
.example('sfcc-diff -c app_client_name -f common.properties', 'Filter for Specific File')
5259
.example('sfcc-diff -c app_client_name -i rvw_autobahn_core', 'Compare Two Cartridges')
5360
.updateStrings({
5461
'Options:': chalk.cyan('Options:\n'),

lib/cartridgeCompare.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ module.exports = (cartridges, options) => {
5757

5858
// Only track file if requested
5959
if (!options.junkOnly || (options.junkOnly && fileIsJunk)) {
60-
diffs.push({
61-
fileIsJunk: fileIsJunk,
62-
relativePath: `${dif.relativePath}/${dif.name1 || dif.name2}`,
63-
sourceFile: sourceFile,
64-
sourceName: source[0].name,
65-
targetFile: targetFile,
66-
targetName: cartridge.name
67-
})
60+
const relPath = `${dif.relativePath}/${dif.name1 || dif.name2}`
61+
62+
// Check for File Filter
63+
if (!options.filter || relPath.indexOf(options.filter) > -1) {
64+
diffs.push({
65+
fileIsJunk: fileIsJunk,
66+
relativePath: relPath,
67+
sourceFile: sourceFile,
68+
sourceName: source[0].name,
69+
targetFile: targetFile,
70+
targetName: cartridge.name
71+
})
72+
}
6873
}
6974
}
7075
})

lib/diff.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ module.exports = (files, options) => {
6060
// Check if we provided a custom tool we want to diff with, otherwise output to terminal
6161
if (options.diff.length > 0) {
6262
console.log(`${chalk.dim('DIFF:'.padStart(leftPad, ' '))} ${chalk.dim(`Opened in ${options.diff}`)}`)
63-
execSync(`git difftool --tool=${options.diff} --no-prompt --exit-code --no-index ${sourceFile} ${targetFile}`)
63+
execSync(`git difftool --tool=${options.diff} --no-prompt --exit-code --no-index ${targetFile} ${sourceFile}`)
6464
} else if (hasChanges) {
6565
console.log(`${chalk.dim('DIFF:'.padStart(leftPad, ' '))} ${chalk.dim('↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓')}\n`)
66-
execSync(`git diff --color-words --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol --unified=0 --exit-code --no-index ${sourceFile} ${targetFile} 2> /dev/null | tail -n +5`, { stdio: 'inherit' })
66+
execSync(`git diff --color-words --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol --unified=0 --exit-code --no-index ${targetFile} ${sourceFile} 2> /dev/null | tail -n +5`, { stdio: 'inherit' })
6767
}
6868
}
6969
}

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sfcc-cartridge-diff",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "SFCC Cartridge Diff Tool",
55
"homepage": "https://github.com/redvanworkshop/sfcc-cartridge-diff#readme",
66
"license": "MIT",

0 commit comments

Comments
 (0)