Skip to content

Instantly share code, notes, and snippets.

@BretCameron
Created June 21, 2019 10:46
Show Gist options
  • Save BretCameron/24f0079bd2c546e704914b86f1b1627a to your computer and use it in GitHub Desktop.
Save BretCameron/24f0079bd2c546e704914b86f1b1627a to your computer and use it in GitHub Desktop.
A custom npm init script, which incorporates an initial GitHub commit. The file should be in your home directory.
const { execSync } = require('child_process');
function run(func) {
console.log(execSync(func).toString())
}
module.exports = {
name: prompt('package name', basename || package.name),
version: prompt('version', '0.0.0'),
decription: prompt('description', ''),
main: prompt('entry point', 'index.js'),
keywords: prompt(function (s) { return s.split(/\s+/) }),
author: prompt('author', 'Joe Bloggs <joe.bloggs@gmail.com> (joebloggs.com)'),
license: prompt('license', 'ISC'),
repository: prompt('github repository url', '', function (url) {
if (url) {
run('touch README.md');
run('git init');
run('git add README.md');
run('git commit -m "first commit"');
run(`git remote add origin ${url}`);
run('git push -u origin master');
}
return url;
}),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment