Skip to content

Commit 006dafe

Browse files
committed
Extract config loading to a simple script
1 parent 95b616d commit 006dafe

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

index.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env node
22

33
const cli = require('commander');
4-
const process = require('process');
5-
const cosmiconfig = require('cosmiconfig');
64
const execa = require('execa');
7-
const findBinary = require('./find-binary');
5+
const config = require('./src/config');
6+
const findBinary = require('./src/find-binary');
87
const pkg = require('./package.json');
98

109
cli
@@ -24,14 +23,6 @@ function runCommandsIfFileChanged(fileToCheck, commands) {
2423
execa(binary, args).stdout.pipe(process.stdout);
2524
}
2625

27-
const configResult = cosmiconfig('run-if-changed').searchSync();
28-
29-
if (!configResult || configResult.isEmpty) {
30-
process.exit(0);
31-
}
32-
33-
const { config } = configResult;
34-
3526
Object.entries(config).forEach(([file, commands]) => {
3627
if (commands.length === 0) {
3728
return;

src/config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const cosmiconfig = require('cosmiconfig');
2+
3+
const configResult = cosmiconfig('run-if-changed').searchSync();
4+
5+
if (!configResult || configResult.isEmpty) {
6+
process.exit(0);
7+
}
8+
9+
const { config } = configResult;
10+
11+
module.exports = config;
File renamed without changes.

0 commit comments

Comments
 (0)