Skip to content

Instantly share code, notes, and snippets.

@jacobbubu
Created October 17, 2019 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobbubu/35c4235d04afcc5052e01d3bc8165cdf to your computer and use it in GitHub Desktop.
Save jacobbubu/35c4235d04afcc5052e01d3bc8165cdf to your computer and use it in GitHub Desktop.
Create a github repo. using the name from package.json and then put the repo's url back to `package.repository`
name=`node -e "process.stdout.write((require('./package.json').name.replace(/^@[\w\d\-\_]+\//, '')))"`
if [ -z ${name+x} ]; then
echo 'No "name" field found in package.json'
else
output=`gh re --browser false --new $name`
repo=`echo $output | grep -Eo '(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'`
repo+=".git"
echo $repo | `node -e "process.stdin.resume();process.stdin.setEncoding('utf8');var gitUrl = '';process.stdin.on('data', function(chunk) { gitUrl = chunk.split('\n')[0]; });process.stdin.on('end', function() {var fs=require('fs');var pkg=require('./package.json');pkg.repository = { type: 'git', url: gitUrl };fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2), 'utf8');})"`
fi
@jacobbubu
Copy link
Author

jacobbubu commented Oct 17, 2019

please install gh first, npm i gh -g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment