Last active
August 29, 2015 13:56
-
-
Save TooTallNate/8923821 to your computer and use it in GitHub Desktop.
`npm owner` syncing tool. Invoke like: gnode sync.js tootallnate rauchg coreh
This file contains 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 exec = require('child_process').exec; | |
var suspend = require('suspend'); | |
var resume = suspend.resume; | |
suspend.run(function*(){ | |
// first determine the list of npm usernames to sync up to | |
var npmUsers = process.argv.slice(2); | |
if (!npmUsers.length) { | |
return console.error('must pass the npm usernames as command arguments'); | |
} | |
// second get an array of current owners for the module in CWD | |
var r = yield exec('npm owner ls', resume()); | |
var currentOwners = r.split('\n').map(function (line) { | |
return line.split(/\s+/)[0]; | |
}); | |
// last entry is usually blank... remove it | |
if (!currentOwners[currentOwners.length - 1]) { | |
currentOwners.splice(currentOwners.length - 1, 1); | |
} | |
// remove and current owners who are not present in the `npmUsers` list | |
for (var i = 0; i < currentOwners.length; i++) { | |
var owner = currentOwners[i]; | |
if (-1 === npmUsers.indexOf(owner)) { | |
console.log('removing npm user %j', owner); | |
yield exec('npm owner rm ' + owner, resume()); | |
} | |
} | |
// now add any users from the `npmUsers` array who are not already an owner | |
for (var i = 0; i < npmUsers.length; i++) { | |
var user = npmUsers[i]; | |
if (-1 === currentOwners.indexOf(user)) { | |
console.log('adding npm user %j', user); | |
yield exec('npm owner add ' + user, resume()); | |
// sleep for 1 second | |
yield setTimeout(resume(), 1000); | |
} else { | |
console.log('npm user %j is already an owner, skipping…', user); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment