Skip to content

Instantly share code, notes, and snippets.

@zpao
Last active March 25, 2019 23:47
Show Gist options
  • Save zpao/6e5d45754b5dcb982512b9a27befdcae to your computer and use it in GitHub Desktop.
Save zpao/6e5d45754b5dcb982512b9a27befdcae to your computer and use it in GitHub Desktop.
#!/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