Skip to content

Commit 3fa4f6d

Browse files
sudo-suhasokonet
authored andcommitted
style: Promisify staged-git-files (#325)
1 parent ebf1767 commit 3fa4f6d

File tree

2 files changed

+30
-37
lines changed

2 files changed

+30
-37
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"minimatch": "^3.0.0",
4141
"npm-which": "^3.0.1",
4242
"p-map": "^1.1.1",
43+
"pify": "^3.0.0",
4344
"staged-git-files": "0.0.4",
4445
"stringify-object": "^3.2.0"
4546
},

src/runAll.js

+29-37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const sgf = require('staged-git-files')
44
const Listr = require('listr')
55
const has = require('lodash/has')
6+
const pify = require('pify')
67
const runScript = require('./runScript')
78
const generateTasks = require('./generateTasks')
89
const resolveGitDir = require('./resolveGitDir')
@@ -24,44 +25,35 @@ module.exports = function runAll(scripts, config) {
2425
const renderer = config.renderer
2526
sgf.cwd = resolveGitDir(gitDir)
2627

27-
return new Promise((resolve, reject) => {
28-
sgf('ACM', (err, files) => {
29-
if (err) {
30-
return reject(err)
31-
}
32-
33-
/* files is an Object{ filename: String, status: String } */
34-
const filenames = files.map(file => file.filename)
35-
const tasks = generateTasks(config, filenames).map(task => ({
36-
title: `Running tasks for ${task.pattern}`,
37-
task: () =>
38-
new Listr(runScript(task.commands, task.fileList, scripts, config), {
39-
// In sub-tasks we don't want to run concurrently
40-
// and we want to abort on errors
41-
dateFormat: false,
42-
concurrent: false,
43-
exitOnError: true
44-
}),
45-
skip: () => {
46-
if (task.fileList.length === 0) {
47-
return `No staged files match ${task.pattern}`
48-
}
49-
return false
50-
}
51-
}))
52-
53-
if (tasks.length) {
54-
return new Listr(tasks, {
28+
return pify(sgf)('ACM').then(files => {
29+
/* files is an Object{ filename: String, status: String } */
30+
const filenames = files.map(file => file.filename)
31+
const tasks = generateTasks(config, filenames).map(task => ({
32+
title: `Running tasks for ${task.pattern}`,
33+
task: () =>
34+
new Listr(runScript(task.commands, task.fileList, scripts, config), {
35+
// In sub-tasks we don't want to run concurrently
36+
// and we want to abort on errors
5537
dateFormat: false,
56-
concurrent,
57-
renderer,
58-
exitOnError: !concurrent // Wait for all errors when running concurrently
59-
})
60-
.run()
61-
.then(resolve)
62-
.catch(reject)
38+
concurrent: false,
39+
exitOnError: true
40+
}),
41+
skip: () => {
42+
if (task.fileList.length === 0) {
43+
return `No staged files match ${task.pattern}`
44+
}
45+
return false
6346
}
64-
return resolve('No tasks to run.')
65-
})
47+
}))
48+
49+
if (tasks.length) {
50+
return new Listr(tasks, {
51+
dateFormat: false,
52+
concurrent,
53+
renderer,
54+
exitOnError: !concurrent // Wait for all errors when running concurrently
55+
}).run()
56+
}
57+
return 'No tasks to run.'
6658
})
6759
}

0 commit comments

Comments
 (0)