Last active
December 31, 2017 17:10
-
-
Save simov/a54f20ae73d776a1de96d6e8c6b99aa9 to your computer and use it in GitHub Desktop.
Flat search for changed git repositories: `node check-for-git-changes.js path/to/projects/folder/`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs') | |
var path = require('path') | |
var cp = require('child_process') | |
if (!process.argv[2]) { | |
console.log('Specify directory to check') | |
process.exit() | |
} | |
var dpath = path.resolve(process.cwd(), process.argv[2]) | |
var api = { | |
read: (dpath) => new Promise((resolve, reject) => { | |
fs.readdir(dpath, (err, names) => err | |
? reject(err) | |
: resolve(names.map((name) => path.resolve(dpath, name)))) | |
}) | |
, | |
check: (dpath) => new Promise((resolve, reject) => { | |
cp.exec( | |
'git status', | |
{cwd: dpath}, | |
(err, stdout, stderr) => (err || stderr) | |
? reject(err || stderr) | |
: resolve({dpath, status: stdout}) | |
) | |
}) | |
, | |
} | |
// main | |
api.read(dpath) | |
.then((dirs) => Promise.all(dirs.map(api.check))) | |
.then((statuses) => statuses | |
.filter(({status}) => !/nothing to commit, working tree clean/.test(status)) | |
.map(({dpath}) => console.log(dpath)) | |
) | |
.catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment