Skip to content

Commit 98a2dc1

Browse files
authored
Merge pull request #16 from hkdobrev/commands-refactor
Deduplicate commands for each run
2 parents 6160472 + 8da1948 commit 98a2dc1

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

run-if-changed.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ if (changedFiles.length === 0) {
77
process.exit(0);
88
}
99

10-
require('./src/runForMatchingPatterns')(changedFiles, config);
10+
const resolveMatchingPatterns = require('./src/resolveMatchingPatterns');
11+
const runCommands = require('./src/runCommands');
12+
13+
runCommands(resolveMatchingPatterns(changedFiles, config));

src/findBinary.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This code is adapted from https://git.io/fhsKi
2+
13
const parseStringArgv = require('string-argv');
24
const which = require('npm-which')(process.cwd());
35

src/resolveMatchingPatterns.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const matcher = require('./matcher');
2+
3+
module.exports = function resolveMatchingPatterns(list, config) {
4+
const commandsToRun = Object.entries(config)
5+
.filter(([pattern]) => matcher(list, [pattern]))
6+
.map(([, commands]) => commands)
7+
// Flatten array
8+
.reduce((acc, val) => acc.concat(val), []);
9+
10+
// unique commands, do not run them multiple times if they are the same
11+
// for multiple patterns or they are repeated in a list for a single pattern
12+
return [...new Set(commandsToRun)];
13+
};

src/runForMatchingPatterns.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)