Skip to content

Instantly share code, notes, and snippets.

@therealklanni
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save therealklanni/67ebc6d2f4e228778d53 to your computer and use it in GitHub Desktop.
Save therealklanni/67ebc6d2f4e228778d53 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var rfs = fs.readFileSync;
var wfs = fs.writeFileSync;
var path = require('path');
var yaml = require('js-yaml');
var inquirer = require('inquirer');
var program = require('commander');
var version = require('./package.json').version;
program
.version(version)
.option('-r, --repo [name]', 'name of the new repository')
.option('-o, --outfile [filename]', 'file to output, otherwise stdout')
.parse(process.argv);
function apply(template, data) {
return template.replace(/\$\{(\w+)\}/gm, function (_, key) {
return data[key] || '';
});
}
if (!program.repo.length) {
inquirer.prompt({
name: 'repo',
message: 'Repository name',
validate: function (input) {
return !!input.length;
}
}, function (ans) {
program.repo = ans.repo
render();
});
} else {
render();
}
function render() {
var template = yaml.safeLoad(rfs(path.resolve('template.yml'))).template;
var contents = apply(template, {
repo: program.repo,
repoUrl: 'https://github.com/hubot-scripts/'+ program.repo
});
if (program.outfile) {
wfs(program.outfile, contents);
} else {
console.log(contents);
}
}

Almost done!

A repository has been created for you at hubot-calculator. A team has also been created that has admin rights to this repo and you have been added to it so you can manage it as you see fit.

To complete the transition, follow these steps:

Clone the new repository

git clone https://github.com/hubot-scripts/hubot-calculator

OR

git remote set-url origin https://github.com/hubot-scripts/hubot-calculator

Update the package.json

  "repository": {
    "type": "git",
    "url": "https://github.com/hubot-scripts/hubot-calculator"
  },
  "bugs": {
    "url": "https://github.com/hubot-scripts/hubot-calculator/issues"
  },

Publish

npm version patch
npm publish
git push origin master

Profit!

Once this is done, feel free to delete your old repository. You're done!

🤘 rock on...

{
"name": "hubot-scripts-helpers",
"version": "0.1.0",
"description": "Helper scripts for hubot-scripts admins",
"main": "index.js",
"scripts": {
"postinstall": "node index.js -h",
"test": "mocha -R nyan"
},
"repository": {
"type": "git",
"url": "https://github.com/hubot-scripts/helpers"
},
"author": "Kevin Lanni",
"license": "WTFPL",
"bugs": {
"url": "https://github.com/hubot-scripts/helpers/issues"
},
"homepage": "https://github.com/hubot-scripts/helpers",
"dependencies": {
"commander": "^2.3.0",
"inquirer": "^0.6.0",
"js-yaml": "^3.2.1"
},
"devDependencies": {
"chai": "^1.9.1",
"mocha": "^1.21.4",
"sinon": "^1.10.3",
"sinon-chai": "^2.5.0"
}
}
node index.js -o output.md -r hubot-calculator
template: |
### Almost done!
A repository has been created for you at [${repo}](${repoUrl}). A team has also been created that has admin rights to this repo and you have been added to it so you can manage it as you see fit.
**To complete the transition, follow these steps:**
#### Clone the new repository
```
git clone ${repoUrl}
```
OR
```
git remote set-url origin ${repoUrl}
```
#### Update the `package.json`
```js
"repository": {
"type": "git",
"url": "${repoUrl}"
},
```
```js
"bugs": {
"url": "${repoUrl}/issues"
},
```
#### Publish
```sh
npm version patch
npm publish
git push origin master
```
#### Profit!
Once this is done, feel free to delete your old repository. You're done!
:metal: rock on...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment