Last active
March 25, 2019 23:47
-
-
Save zpao/6e5d45754b5dcb982512b9a27befdcae to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
const util = require('util'); | |
const execp = util.promisify(require('child_process').exec); | |
main(process.argv[2], process.argv[3]); | |
async function main(pkg, user) { | |
const whoamioutput = await execp(`npm whoami`); | |
const whoami = whoamioutput.stdout.trim(); | |
try { | |
const output = await execp(`npm owner ls ${pkg}`); | |
const owners = output.stdout | |
.trim() | |
.split('\n') | |
.map(o => o.split(' ')[0]); | |
if (!owners.includes(whoami)) { | |
console.log(`ERROR: ${pkg} doesn't include ~${whoami}`); | |
return; | |
} | |
} catch (e) { | |
console.log(`ERROR: ${pkg} doesn't exist`); | |
return; | |
} | |
try { | |
await execp(`npm owner add ${user} ${pkg}`); | |
} catch (e) { | |
// Probably... | |
console.log(`ERROR: don't have proper permissions on ${pkg}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment