├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .github └── contributing.md ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── docs └── demo.gif ├── generator.js ├── index.js ├── package.json └── test ├── fixtures ├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── contributing.md ├── index.js └── package.json ├── plugin.js └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to generate-gh-repo 2 | 3 | First and foremost, thank you! We appreciate that you want to contribute to generate-gh-repo, your time is valuable, and your contributions mean a lot to us. 4 | 5 | **What does "contributing" mean?** 6 | 7 | Creating an issue is the simplest form of contributing to a project. But there are many ways to contribute, including the following: 8 | 9 | - Updating or correcting documentation 10 | - Feature requests 11 | - Bug reports 12 | 13 | If you'd like to learn more about contributing in general, the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) has a lot of useful information. 14 | 15 | **Showing support for generate-gh-repo** 16 | 17 | Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use. 18 | 19 | Don't have time to contribute? No worries, here are some other ways to show your support for generate-gh-repo: 20 | 21 | - star the [project](https://github.com/generate/generate-gh-repo) 22 | - tweet your support for generate-gh-repo 23 | 24 | ## Issues 25 | 26 | ### Before creating an issue 27 | 28 | Please try to determine if the issue is caused by an underlying library, and if so, create the issue there. Sometimes this is difficult to know. We only ask that you attempt to give a reasonable attempt to find out. Oftentimes the readme will have advice about where to go to create issues. 29 | 30 | Try to follow these guidelines 31 | 32 | - **Investigate the issue**: 33 | - **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue. 34 | - Create the issue in the appropriate repository. 35 | 36 | ### Creating an issue 37 | 38 | Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: 39 | 40 | - **version**: please note the version of generate-gh-repo are you using 41 | - **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using 42 | - **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) 43 | 44 | ## Above and beyond 45 | 46 | Here are some tips for creating idiomatic issues. Taking just a little bit extra time will make your issue easier to read, easier to resolve, more likely to be found by others who have the same or similar issue in the future. 47 | 48 | - read the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) 49 | - take some time to learn basic markdown. This [markdown cheatsheet](https://gist.github.com/jonschlinkert/5854601) is super helpful, as is the GitHub guide to [basic markdown](https://help.github.com/articles/markdown-basics/). 50 | - Learn about [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/). And if you want to really go above and beyond, read [mastering markdown](https://guides.github.com/features/mastering-markdown/). 51 | - use backticks to wrap code. This ensures that code will retain its format, making it much more readable to others 52 | - use syntax highlighting by adding the correct language name after the first "code fence" 53 | 54 | 55 | [node-glob]: https://github.com/isaacs/node-glob 56 | [micromatch]: https://github.com/jonschlinkert/micromatch 57 | [so]: http://stackoverflow.com/questions/tagged/generate-gh-repo -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | 29 | examples/*/dist 30 | examples/*/site 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - '7' 9 | - '6' 10 | - '5' 11 | - '4' 12 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ### CLI 4 | 5 | When installed globally, the `gh-repo` generator is available to use through the `gen` command: 6 | 7 | Create a new GitHub repository using the [default](#default) task. 8 | 9 | ```sh 10 | $ gen gh-repo 11 | ``` 12 | 13 | ### API 14 | 15 | **Params** 16 | 17 | * `app` **{Object}**: [generate](https://github.com/generate/generate) instance to add tasks to. 18 | 19 | **Example** 20 | 21 | ```js 22 | // use as a plugin with existing generate instance 23 | // $ gen gh-repo 24 | app.use(require('generate-gh-repo')); 25 | 26 | // use as a subgenerator on an existing generate instance 27 | // $ gen repo 28 | app.register('repo', require('generate-gh-repo')); 29 | ``` 30 | 31 | [Generate]: https://github.com/generate/generate 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Brian Woodward 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 | 5 | 6 |

7 | 8 | Generate generator to create a new repository on GitHub. 9 | 10 | # generate-gh-repo 11 | 12 | [![NPM version](https://img.shields.io/npm/v/generate-gh-repo.svg?style=flat)](https://www.npmjs.com/package/generate-gh-repo) [![NPM monthly downloads](https://img.shields.io/npm/dm/generate-gh-repo.svg?style=flat)](https://npmjs.org/package/generate-gh-repo) [![Build Status](https://img.shields.io/travis/generate/generate-gh-repo.svg?style=flat)](https://travis-ci.org/generate/generate-gh-repo) 13 | 14 | ![generate-gh-repo demo](https://raw.githubusercontent.com/generate/generate-gh-repo/master/docs/demo.gif) 15 | 16 | ## Usage 17 | 18 | ### CLI 19 | 20 | When installed globally, the `gh-repo` generator is available to use through the `gen` command: 21 | 22 | Create a new GitHub repository using the [default](#default) task. 23 | 24 | ```sh 25 | $ gen gh-repo 26 | ``` 27 | 28 | ### API 29 | 30 | **Params** 31 | 32 | * `app` **{Object}**: [generate](https://github.com/generate/generate) instance to add tasks to. 33 | 34 | **Example** 35 | 36 | ```js 37 | // use as a plugin with existing generate instance 38 | // $ gen gh-repo 39 | app.use(require('generate-gh-repo')); 40 | 41 | // use as a subgenerator on an existing generate instance 42 | // $ gen repo 43 | app.register('repo', require('generate-gh-repo')); 44 | ``` 45 | 46 | ## Getting started 47 | 48 | ### Install 49 | 50 | **Installing the CLI** 51 | 52 | To run the `gh-repo` generator from the command line, you'll need to install [Generate](https://github.com/generate/generate) globally first. You can do that now with the following command: 53 | 54 | ```sh 55 | $ npm install --global generate 56 | ``` 57 | 58 | This adds the `gen` command to your system path, allowing it to be run from any directory. 59 | 60 | **Install generate-gh-repo** 61 | 62 | Install this module with the following command: 63 | 64 | ```sh 65 | $ npm install --global generate-gh-repo 66 | ``` 67 | 68 | ### CLI 69 | 70 | Run this generator's `default` [task](https://github.com/generate/generate/blob/master/docs/tasks.md#default) with the following command: 71 | 72 | ```sh 73 | $ gen gh-repo 74 | ``` 75 | 76 | **What you should see in the terminal** 77 | 78 | If completed successfully, you should see both `starting` and `finished` events in the terminal, like the following: 79 | 80 | ```sh 81 | [00:44:21] starting ... 82 | ... 83 | [00:44:22] finished ✔ 84 | ``` 85 | 86 | If you do not see one or both of those events, please [let us know about it](../../issues). 87 | 88 | ### Help 89 | 90 | To see a general help menu and available commands for Generate's CLI, run: 91 | 92 | ```sh 93 | $ gen help 94 | ``` 95 | 96 | ## Next steps 97 | 98 | ### Running unit tests 99 | 100 | It's never too early to begin running unit tests. When you're ready to get started, the following command will ensure the project's dependencies are installed then run all of the unit tests: 101 | 102 | ```sh 103 | $ npm install && test 104 | ``` 105 | 106 | ### Publishing your generator 107 | 108 | If you're tests are passing and you're ready to publish your generator to [npm](https://www.npmjs.com), you can do that now with the following command: 109 | 110 | **Are you sure you're ready?!** 111 | 112 | Let's go! 113 | 114 | ```sh 115 | $ npm publish 116 | ``` 117 | 118 | ## About 119 | 120 | ### What is "Generate"? 121 | 122 | Generate is a command line tool and developer framework for scaffolding out new GitHub projects using [generators](https://github.com/generate/generate/blob/master/docs/generators.md) and [tasks](https://github.com/generate/generate/blob/master/docs/tasks.md). 123 | 124 | Answers to prompts and the user's environment can be used to determine the templates, directories, files and contents to build. Support for [gulp](http://gulpjs.com), [base](https://github.com/node-base/base) and [assemble](https://github.com/assemble/assemble) plugins, and much more. 125 | 126 | **For more information**: 127 | 128 | * Visit the [generate project](https://github.com/generate/generate/) 129 | * Visit the [generate documentation](https://github.com/generate/generate/blob/master/docs/) 130 | * Find [generators on npm](https://www.npmjs.com/browse/keyword/generate-generator) (help us [author generators](https://github.com/generate/generate/blob/master/docs/micro-generators.md)) 131 | 132 | ### Community 133 | 134 | Are you using [Generate](https://github.com/generate/generate) in your project? Have you published a [generator](https://github.com/generate/generate/blob/master/docs/generators.md) and want to share your project with the world? 135 | 136 | Here are some suggestions! 137 | 138 | * If you get like Generate and want to tweet about it, please feel free to mention `@generatejs` or use the `#generatejs` hashtag 139 | * Show your love by starring [Generate](https://github.com/generate/generate) and `generate-gh-repo` 140 | * Get implementation help on [StackOverflow](http://stackoverflow.com/questions/tagged/generate) (please use the `generatejs` tag in questions) 141 | * **Gitter** Discuss Generate with us on [Gitter](https://gitter.im/generate/generate) 142 | * If you publish an generator, thank you! To make your project as discoverable as possible, please add the keyword `generategenerator` to package.json. 143 | 144 | ### Contributing 145 | 146 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 147 | 148 | Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards. 149 | 150 | ### Running tests 151 | 152 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 153 | 154 | ```sh 155 | $ npm install && npm test 156 | ``` 157 | 158 | ### Author 159 | 160 | **Brian Woodward** 161 | 162 | * [github/doowb](https://github.com/doowb) 163 | * [twitter/doowb](https://twitter.com/doowb) 164 | 165 | ### License 166 | 167 | Copyright © 2017, [Brian Woodward](https://github.com/doowb). 168 | Released under the [MIT License](LICENSE). 169 | 170 | *** 171 | 172 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.3, on April 07, 2017._ -------------------------------------------------------------------------------- /docs/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/generate/generate-gh-repo/5893cbdde1895b54973338cbdb4488235bd463ce/docs/demo.gif -------------------------------------------------------------------------------- /generator.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | var extend = require('extend-shallow'); 5 | var isValid = require('is-valid-app'); 6 | var gitAddRemote = require('git-add-remote'); 7 | var GitHub = require('github-base'); 8 | var github; 9 | 10 | 11 | module.exports = function(app) { 12 | // return if the generator is already registered 13 | if (!isValid(app, 'generate-gh-repo')) return; 14 | 15 | // use generate-data to collect project and repo information 16 | app.use(require('generate-data')); 17 | 18 | // configure a datastore to hold github authentication details 19 | var store = app.store.create('generate-gh-repo'); 20 | 21 | // initialize git-add-remote in the current working directory 22 | var addRemote = gitAddRemote(app.cwd); 23 | 24 | // uitility to get a property from `app.cache.data` 25 | var getProp = function(prop) { 26 | return function() { 27 | return app.get(`cache.data.${prop}`); 28 | }; 29 | }; 30 | 31 | // questions to ask when prompting the user for information 32 | var prompts = [ 33 | 'project.name', 34 | 'project.description', 35 | 'project.owner', 36 | 'project.type', 37 | 'homepage', 38 | 'private' 39 | ]; 40 | 41 | /** 42 | * Setup prompts that may be asked later 43 | * 44 | * @name gh-repo:questions 45 | */ 46 | 47 | app.task('questions', {silent: true}, function(cb) { 48 | // questions to gather information about the repository being created 49 | app.question('project.name', 'What is the name of the repository to create?', { 50 | default: getProp('project.name') 51 | }); 52 | 53 | app.question('project.description', 'What is the description of the repository?', { 54 | default: getProp('project.description') 55 | }); 56 | 57 | app.question('project.owner', 'Who is the owner of the repository?', { 58 | default: getProp('project.owner') 59 | }); 60 | 61 | app.questions.list('project.type', { 62 | message: 'Is the repository owner a "user" or an "organization"?', 63 | choices: [ 64 | 'user', 65 | 'organization' 66 | ] 67 | }); 68 | 69 | app.question('homepage', 'What is the repository\'s homepage?', { 70 | default: function() { 71 | var homepage = getProp('homepage')(); 72 | var name = getProp('project.name')(); 73 | var owner = getProp('project.owner')(); 74 | var repo = `https://github.com/${owner}/${name}`; 75 | if (repo === homepage) { 76 | return getProp('author.url')() || `https://github.com/${owner}`; 77 | } 78 | return homepage; 79 | } 80 | }); 81 | 82 | app.confirm('private', 'Is the repository private?', { 83 | default: function() { 84 | var val = getProp('private')(); 85 | if (typeof val === 'boolean') { 86 | return val; 87 | } 88 | return false; 89 | } 90 | }); 91 | 92 | // questions for gathering GitHub authentication information from the user 93 | app.confirm('useAuth', 'Found saved GitHub authentication. Would you like to use it?'); 94 | app.question('github.auth.username', 'GitHub username?', {force: true}); 95 | app.question('github.auth.password', 'GitHub password?', {force: true, type: 'password'}); 96 | app.question('github.auth.token', 'GitHub OAuth token?', {force: true}); 97 | app.questions.list('github.auth.type', { 98 | force: true, 99 | message: 'Would you like to login using an OAuth token or your GitHub username and password?', 100 | choices: [ 101 | 'token', 102 | 'username/password' 103 | ] 104 | }); 105 | 106 | // prompt the user about adding the newly created git remote 107 | app.confirm('remote', 'Would you like to add the git remote origin url?'); 108 | 109 | // questions for gathering Travis-CI webhook information from the user 110 | app.confirm('configureTravis', 'Would you like to enable Travis-CI for this repository?'); 111 | app.confirm('useTravisAuth', 'Found saved Travis-CI authentication. Would you like to use it?'); 112 | app.question('travis.username', 'GitHub username (associated with travis-ci)?', {force: true}); 113 | app.question('travis.token', 'Travis-CI token?'); 114 | 115 | cb(); 116 | }); 117 | 118 | app.task('prompt-travis', {silent: true}, function(cb) { 119 | console.log(); 120 | var travis = store.get('travis'); 121 | if (travis) { 122 | app.ask('useTravisAuth', {force: true}, function(err, answers) { 123 | if (err) return cb(err); 124 | if (answers.useTravisAuth) { 125 | app.data('travis', travis); 126 | } else { 127 | travis = null; 128 | } 129 | if (travis) return cb(); 130 | app.ask(['travis.username', 'travis.token'], handleAnswers); 131 | }); 132 | return; 133 | } 134 | app.ask(['travis.username', 'travis.token'], handleAnswers); 135 | 136 | function handleAnswers(err, answers) { 137 | if (err) return cb(err); 138 | app.data(answers); 139 | store.set('travis', answers.travis); 140 | cb(); 141 | } 142 | }); 143 | 144 | /** 145 | * Prompt the user for information about the repository being created. 146 | * 147 | * ```sh 148 | * $ gen gh-repo:prompt 149 | * ``` 150 | * @name gh-repo:prompt 151 | */ 152 | 153 | app.task('prompt', {silent: true}, function(cb) { 154 | console.log(); 155 | app.ask(prompts, {force: true}, function(err, answers) { 156 | if (err) return cb(err); 157 | app.data(answers); 158 | cb(); 159 | }); 160 | }); 161 | 162 | /** 163 | * Prompt the user for GitHub authentication information 164 | * 165 | * ```sh 166 | * $ gen gh-repo:auth 167 | * ``` 168 | * @name gh-repo:auth 169 | */ 170 | 171 | app.task('github-auth', {silent: true}, function(cb) { 172 | console.log(); 173 | var auth = store.get('github.auth'); 174 | if (auth) { 175 | app.ask('useAuth', {force: true}, function(err, answers) { 176 | if (err) return cb(err); 177 | if (answers.useAuth) { 178 | if (auth.type !== 'token') { 179 | delete auth.token; 180 | } 181 | app.data('github.auth', auth); 182 | } else { 183 | auth = null; 184 | } 185 | if (auth) return cb(); 186 | app.ask('github.auth.type', handleGithubType); 187 | }); 188 | return; 189 | } 190 | app.ask('github.auth.type', handleGithubType); 191 | 192 | function handleGithubType(err, answers) { 193 | if (err) return cb(err); 194 | var type = answers.github.auth.type; 195 | if (type === 'token') { 196 | app.ask('github.auth.token', handleAnswers); 197 | return; 198 | } 199 | 200 | app.ask([ 201 | 'github.auth.username', 202 | 'github.auth.password' 203 | ], handleAnswers); 204 | } 205 | 206 | function handleAnswers(err, answers) { 207 | if (err) return cb(err); 208 | app.data(answers); 209 | store.set('github.auth', answers.github.auth); 210 | cb(); 211 | } 212 | }); 213 | 214 | /** 215 | * Initialize the github instance using the user's GitHub authentication information. 216 | * 217 | * ```sh 218 | * $ gen gh-repo:init-github 219 | * ``` 220 | * @name gh-repo:init-github 221 | */ 222 | 223 | app.task('init-github', {silent: true}, ['github-auth'], function(cb) { 224 | var auth = getProp('github.auth')(); 225 | if (!auth) { 226 | cb(new Error('Unable to authenticate to GitHub')); 227 | return; 228 | } 229 | 230 | github = new GitHub(auth); 231 | cb(); 232 | }); 233 | 234 | /** 235 | * Create a new repository on GitHub. The generator will attempt to use data from the current project's 236 | * package.json and git repository information, while prompting for user input and validation. 237 | * 238 | * ```sh 239 | * $ gen gh-repo:gh-repo 240 | * ``` 241 | * @name gh-repo:gh-repo 242 | * @api public 243 | */ 244 | 245 | app.task('gh-repo', ['questions', 'init-github', 'prompt'], function(cb) { 246 | console.log(); 247 | var opts = { 248 | owner: getProp('project.owner')(), 249 | repo: getProp('project.name')() 250 | }; 251 | 252 | var data = { 253 | name: getProp('project.name')(), 254 | description: getProp('project.description')(), 255 | homepage: getProp('homepage')(), 256 | private: getProp('private')() 257 | }; 258 | 259 | github.get('/repos/:owner/:repo', opts, function(err, res) { 260 | if (err) return cb(err); 261 | if (res.id && !res.message) { 262 | console.log(app.log.timestamp); 263 | console.log(app.log.timestamp, `Unable to create new repository "${opts.owner}/${opts.repo}" because it already exists.`); 264 | console.log(app.log.timestamp); 265 | cb(new Error('Repository already exists.')); 266 | return; 267 | } 268 | 269 | if (res.message && res.message !== 'Not Found') { 270 | cb(new Error(res.message)); 271 | return; 272 | } 273 | 274 | var type = getProp('project.type')(); 275 | var fullName = ''; 276 | var url = ''; 277 | if (type === 'user') { 278 | url = '/user/repos'; 279 | var username = getProp('github.auth.username')(); 280 | fullName = (username && username + '/') || ''; 281 | } else { 282 | url = '/orgs/:owner/repos'; 283 | fullName = opts.owner + '/'; 284 | } 285 | fullName += data.name; 286 | 287 | console.log(app.log.timestamp); 288 | console.log(app.log.timestamp, `Creating "${fullName}" with the following settings:`); 289 | console.log(app.log.timestamp, ` private: ${data.private ? 'true' : 'false'}`); 290 | console.log(app.log.timestamp, ` homepage: ${data.homepage}`); 291 | console.log(app.log.timestamp, ` description: ${data.description}`); 292 | console.log(app.log.timestamp); 293 | 294 | app.confirm('confirmCreate', 'Are you sure you want to create this repository?'); 295 | console.log(); 296 | app.ask('confirmCreate', function(err, answers) { 297 | console.log(); 298 | if (err) return cb(err); 299 | if (!answers.confirmCreate) { 300 | console.log(app.log.timestamp); 301 | console.log(app.log.timestamp, 'The repository has not been created. Run `$ gen gh-repo` again to start over.'); 302 | console.log(app.log.timestamp); 303 | return cb(); 304 | } 305 | github.post(url, extend({}, opts, data), function(err, res) { 306 | if (err) return cb(err); 307 | if (res.message) { 308 | cb(new Error(res.message)); 309 | return; 310 | } 311 | console.log(app.log.timestamp); 312 | console.log(app.log.timestamp, `"${opts.owner}/${opts.repo}" has been created.`); 313 | console.log(app.log.timestamp); 314 | console.log(); 315 | 316 | app.ask('remote', function(err, answers) { 317 | if (err) return cb(err); 318 | if (answers.remote && !process.env.GENERATOR_TEST) { 319 | addRemote.sync('origin', app.cache.data.https + '.git'); 320 | } 321 | 322 | // ask if the user would like to also enable travis-ci 323 | app.ask('configureTravis', function(err, answers) { 324 | console.log(); 325 | if (err) return cb(err); 326 | if (!answers.configureTravis) { 327 | return cb(); 328 | } 329 | app.build('enable-travis', cb); 330 | }); 331 | }); 332 | }); 333 | }); 334 | }); 335 | }); 336 | 337 | /** 338 | * Enable Travis-CI for the repository by creating a new webhook. This task will 339 | * ask for the Travis-CI username (this should be the same as the GitHub username) and a 340 | * Travis-CI token which can be found under the Accounts menu on Travis-CI. 341 | * 342 | * ```sh 343 | * # use it standalone if the repository has already been created on GitHub 344 | * $ gen gh-repo:enable-travis 345 | * # use it when creating the repository on github 346 | * $ gen gh-repo:default,enable-travis 347 | * ``` 348 | * @name gh-repo:enable-travis 349 | * @api public 350 | */ 351 | 352 | app.task('enable-travis', ['questions', 'prompt-travis'], function(cb) { 353 | if (!github) { 354 | app.build('init-github', function(err) { 355 | if (err) return cb(err); 356 | enableTravis(); 357 | }); 358 | return; 359 | } 360 | enableTravis(); 361 | 362 | function enableTravis() { 363 | var opts = { 364 | owner: getProp('project.owner')(), 365 | repo: getProp('project.name')() 366 | }; 367 | 368 | // check to see if the webhook exists 369 | github.get('/repos/:owner/:repo/hooks', opts, function(err, hooks) { 370 | if (err) return cb(err); 371 | if (hooks && hooks.message) { 372 | return cb(new Error(hooks.message)); 373 | } 374 | 375 | if (hasHook(hooks, 'travis')) { 376 | console.log(); 377 | console.log(`The Travis-CI webhook is already enabled for "${opts.owner}/${opts.repo}"`); 378 | console.log(); 379 | return cb(); 380 | } 381 | 382 | var data = { 383 | name: 'travis', 384 | config: { 385 | user: getProp('travis.username')(), 386 | token: getProp('travis.token')(), 387 | domain: 'notify.travis-ci.org' 388 | }, 389 | active: true 390 | }; 391 | 392 | github.post('/repos/:owner/:repo/hooks', extend({}, opts, data), function(err, res) { 393 | if (err) return cb(err); 394 | if (res && res.message) { 395 | return cb(new Error(res.message)); 396 | } 397 | console.log(); 398 | console.log(`The Travis-CI webhook has been enabled for "${opts.owner}/${opts.repo}"`); 399 | console.log(); 400 | cb(); 401 | }) 402 | }); 403 | } 404 | 405 | function hasHook(arr, name) { 406 | if (!arr || !arr.length) return false; 407 | for (var i = 0; i < arr.length; i++) { 408 | if (arr[i].name === name) { 409 | return true; 410 | } 411 | } 412 | return false; 413 | } 414 | }); 415 | 416 | /** 417 | * Alias for running the [gh-repo](#gh-repo) task with the following command: 418 | * 419 | * ```sh 420 | * $ gen gh-repo 421 | * ``` 422 | * @name default 423 | * @api public 424 | */ 425 | 426 | app.task('default', ['gh-repo']); 427 | }; 428 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('./generator'); 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generate-gh-repo", 3 | "description": "Generate generator to create a new repository on GitHub.", 4 | "version": "1.1.0", 5 | "homepage": "https://github.com/generate/generate-gh-repo", 6 | "author": "Brian Woodward (https://github.com/doowb)", 7 | "repository": "generate/generate-gh-repo", 8 | "bugs": { 9 | "url": "https://github.com/generate/generate-gh-repo/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "generator.js", 14 | "index.js" 15 | ], 16 | "main": "index.js", 17 | "engines": { 18 | "node": ">=4.0" 19 | }, 20 | "scripts": { 21 | "test": "mocha" 22 | }, 23 | "keywords": [ 24 | "create", 25 | "create-github-repo", 26 | "create-github-repository", 27 | "generate", 28 | "generate-github-repo", 29 | "generate-github-repository", 30 | "generate-repo", 31 | "generate-repository", 32 | "generategenerator", 33 | "github", 34 | "github-repo", 35 | "github-repository", 36 | "repo", 37 | "repository" 38 | ], 39 | "dependencies": { 40 | "extend-shallow": "^2.0.1", 41 | "generate-data": "^0.1.6", 42 | "git-add-remote": "^1.0.0", 43 | "github-base": "^0.5.1", 44 | "is-valid-app": "^0.2.1" 45 | }, 46 | "devDependencies": { 47 | "bdd-stdin": "^0.2.0", 48 | "generate": "^0.13.1", 49 | "gulp-format-md": "^0.1.11", 50 | "mocha": "^3.2.0", 51 | "nock": "^9.0.2", 52 | "npm-install-global": "^0.1.2" 53 | }, 54 | "verb": { 55 | "toc": false, 56 | "layout": "generator", 57 | "tasks": [ 58 | "readme" 59 | ], 60 | "plugins": [ 61 | "gulp-format-md" 62 | ], 63 | "lint": { 64 | "reflinks": true 65 | }, 66 | "related": { 67 | "list": [] 68 | }, 69 | "reflinks": [ 70 | "assemble", 71 | "base", 72 | "gulp" 73 | ] 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test/fixtures/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /test/fixtures/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | "env": { 7 | "browser": false, 8 | "es6": true, 9 | "node": true, 10 | "mocha": true 11 | }, 12 | "globals": { 13 | "document": false, 14 | "navigator": false, 15 | "window": false 16 | }, 17 | "rules": { 18 | "accessor-pairs": 2, 19 | "arrow-spacing": [ 20 | 2, 21 | { 22 | "before": true, 23 | "after": true 24 | } 25 | ], 26 | "block-spacing": [ 27 | 2, 28 | "always" 29 | ], 30 | "brace-style": [ 31 | 2, 32 | "1tbs", 33 | { 34 | "allowSingleLine": true 35 | } 36 | ], 37 | "comma-dangle": [ 38 | 2, 39 | "never" 40 | ], 41 | "comma-spacing": [ 42 | 2, 43 | { 44 | "before": false, 45 | "after": true 46 | } 47 | ], 48 | "comma-style": [ 49 | 2, 50 | "last" 51 | ], 52 | "constructor-super": 2, 53 | "curly": [ 54 | 2, 55 | "multi-line" 56 | ], 57 | "dot-location": [ 58 | 2, 59 | "property" 60 | ], 61 | "eol-last": 2, 62 | "eqeqeq": [ 63 | 2, 64 | "allow-null" 65 | ], 66 | "generator-star-spacing": [ 67 | 2, 68 | { 69 | "before": true, 70 | "after": true 71 | } 72 | ], 73 | "handle-callback-err": [ 74 | 2, 75 | "^(err|error)$" 76 | ], 77 | "indent": [ 78 | 2, 79 | 2, 80 | { 81 | "SwitchCase": 1 82 | } 83 | ], 84 | "key-spacing": [ 85 | 2, 86 | { 87 | "beforeColon": false, 88 | "afterColon": true 89 | } 90 | ], 91 | "keyword-spacing": [ 92 | 2, 93 | { 94 | "before": true, 95 | "after": true 96 | } 97 | ], 98 | "new-cap": [ 99 | 2, 100 | { 101 | "newIsCap": true, 102 | "capIsNew": false 103 | } 104 | ], 105 | "new-parens": 2, 106 | "no-array-constructor": 2, 107 | "no-caller": 2, 108 | "no-class-assign": 2, 109 | "no-cond-assign": 2, 110 | "no-const-assign": 2, 111 | "no-control-regex": 2, 112 | "no-debugger": 2, 113 | "no-delete-var": 2, 114 | "no-dupe-args": 2, 115 | "no-dupe-class-members": 2, 116 | "no-dupe-keys": 2, 117 | "no-duplicate-case": 2, 118 | "no-empty-character-class": 2, 119 | "no-eval": 2, 120 | "no-ex-assign": 2, 121 | "no-extend-native": 2, 122 | "no-extra-bind": 2, 123 | "no-extra-boolean-cast": 2, 124 | "no-extra-parens": [ 125 | 2, 126 | "functions" 127 | ], 128 | "no-fallthrough": 2, 129 | "no-floating-decimal": 2, 130 | "no-func-assign": 2, 131 | "no-implied-eval": 2, 132 | "no-inner-declarations": [ 133 | 2, 134 | "functions" 135 | ], 136 | "no-invalid-regexp": 2, 137 | "no-irregular-whitespace": 2, 138 | "no-iterator": 2, 139 | "no-label-var": 2, 140 | "no-labels": 2, 141 | "no-lone-blocks": 2, 142 | "no-mixed-spaces-and-tabs": 2, 143 | "no-multi-spaces": 2, 144 | "no-multi-str": 2, 145 | "no-multiple-empty-lines": [ 146 | 2, 147 | { 148 | "max": 1 149 | } 150 | ], 151 | "no-native-reassign": 0, 152 | "no-negated-in-lhs": 2, 153 | "no-new": 2, 154 | "no-new-func": 2, 155 | "no-new-object": 2, 156 | "no-new-require": 2, 157 | "no-new-wrappers": 2, 158 | "no-obj-calls": 2, 159 | "no-octal": 2, 160 | "no-octal-escape": 2, 161 | "no-proto": 0, 162 | "no-redeclare": 2, 163 | "no-regex-spaces": 2, 164 | "no-return-assign": 2, 165 | "no-self-compare": 2, 166 | "no-sequences": 2, 167 | "no-shadow-restricted-names": 2, 168 | "no-spaced-func": 2, 169 | "no-sparse-arrays": 2, 170 | "no-this-before-super": 2, 171 | "no-throw-literal": 2, 172 | "no-trailing-spaces": 0, 173 | "no-undef": 2, 174 | "no-undef-init": 2, 175 | "no-unexpected-multiline": 2, 176 | "no-unneeded-ternary": [ 177 | 2, 178 | { 179 | "defaultAssignment": false 180 | } 181 | ], 182 | "no-unreachable": 2, 183 | "no-unused-vars": [ 184 | 2, 185 | { 186 | "vars": "all", 187 | "args": "none" 188 | } 189 | ], 190 | "no-useless-call": 0, 191 | "no-with": 2, 192 | "one-var": [ 193 | 0, 194 | { 195 | "initialized": "never" 196 | } 197 | ], 198 | "operator-linebreak": [ 199 | 0, 200 | "after", 201 | { 202 | "overrides": { 203 | "?": "before", 204 | ":": "before" 205 | } 206 | } 207 | ], 208 | "padded-blocks": [ 209 | 0, 210 | "never" 211 | ], 212 | "quotes": [ 213 | 2, 214 | "single", 215 | "avoid-escape" 216 | ], 217 | "radix": 2, 218 | "semi": [ 219 | 2, 220 | "always" 221 | ], 222 | "semi-spacing": [ 223 | 2, 224 | { 225 | "before": false, 226 | "after": true 227 | } 228 | ], 229 | "space-before-blocks": [ 230 | 2, 231 | "always" 232 | ], 233 | "space-before-function-paren": [ 234 | 2, 235 | "never" 236 | ], 237 | "space-in-parens": [ 238 | 2, 239 | "never" 240 | ], 241 | "space-infix-ops": 2, 242 | "space-unary-ops": [ 243 | 2, 244 | { 245 | "words": true, 246 | "nonwords": false 247 | } 248 | ], 249 | "spaced-comment": [ 250 | 0, 251 | "always", 252 | { 253 | "markers": [ 254 | "global", 255 | "globals", 256 | "eslint", 257 | "eslint-disable", 258 | "*package", 259 | "!", 260 | "," 261 | ] 262 | } 263 | ], 264 | "use-isnan": 2, 265 | "valid-typeof": 2, 266 | "wrap-iife": [ 267 | 2, 268 | "any" 269 | ], 270 | "yoda": [ 271 | 2, 272 | "never" 273 | ] 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /test/fixtures/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /test/fixtures/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage -------------------------------------------------------------------------------- /test/fixtures/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'node' 5 | - '6' 6 | - '5' 7 | - '4' 8 | -------------------------------------------------------------------------------- /test/fixtures/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Brian Woodward 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/fixtures/README.md: -------------------------------------------------------------------------------- 1 | # my-project [![NPM version](https://badge.fury.io/js/my-project.svg)](https://npmjs.org/package/my-project) [![Build Status](https://travis-ci.org/doowb/my-project.svg?branch=master)](https://travis-ci.org/doowb/my-project) 2 | 3 | > test project 4 | 5 | ## Installation 6 | 7 | ```sh 8 | $ npm install --save my-project 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | var myProject = require('my-project'); 15 | myProject(); 16 | ``` 17 | 18 | ## License 19 | 20 | MIT © [Brian Woodward](https://github.com/doowb) 21 | -------------------------------------------------------------------------------- /test/fixtures/contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to my-project 2 | 3 | First and foremost, thank you! We appreciate that you want to contribute to my-project, your time is valuable, and your contributions mean a lot to us. 4 | 5 | **What does "contributing" mean?** 6 | 7 | Creating an issue is the simplest form of contributing to a project. But there are many ways to contribute, including the following: 8 | 9 | - Updating or correcting documentation 10 | - Feature requests 11 | - Bug reports 12 | 13 | If you'd like to learn more about contributing in general, the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) has a lot of useful information. 14 | 15 | **Showing support for my-project** 16 | 17 | Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use. 18 | 19 | Don't have time to contribute? No worries, here are some other ways to show your support for my-project: 20 | 21 | - star the [project](https://github.com/doowb/my-project) 22 | - tweet your support for my-project 23 | 24 | ## Issues 25 | 26 | ### Before creating an issue 27 | 28 | Please try to determine if the issue is caused by an underlying library, and if so, create the issue there. Sometimes this is difficult to know. We only ask that you attempt to give a reasonable attempt to find out. Oftentimes the readme will have advice about where to go to create issues. 29 | 30 | Try to follow these guidelines 31 | 32 | - **Investigate the issue**: 33 | - **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue. 34 | - Create the issue in the appropriate repository. 35 | 36 | ### Creating an issue 37 | 38 | Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: 39 | 40 | - **version**: please note the version of my-project are you using 41 | - **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using 42 | - **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) 43 | 44 | ## Above and beyond 45 | 46 | Here are some tips for creating idiomatic issues. Taking just a little bit extra time will make your issue easier to read, easier to resolve, more likely to be found by others who have the same or similar issue in the future. 47 | 48 | - read the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) 49 | - take some time to learn basic markdown. This [markdown cheatsheet](https://gist.github.com/jonschlinkert/5854601) is super helpful, as is the GitHub guide to [basic markdown](https://help.github.com/articles/markdown-basics/). 50 | - Learn about [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/). And if you want to really go above and beyond, read [mastering markdown](https://guides.github.com/features/mastering-markdown/). 51 | - use backticks to wrap code. This ensures that code will retain its format, making it much more readable to others 52 | - use syntax highlighting by adding the correct language name after the first "code fence" 53 | 54 | 55 | [node-glob]: https://github.com/isaacs/node-glob 56 | [micromatch]: https://github.com/jonschlinkert/micromatch 57 | [so]: http://stackoverflow.com/questions/tagged/my-project -------------------------------------------------------------------------------- /test/fixtures/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function() { 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-project", 3 | "description": "test project", 4 | "version": "0.1.0", 5 | "private": true, 6 | "homepage": "https://github.com/doowb/my-project", 7 | "author": "Brian Woodward (https://github.com/doowb)", 8 | "repository": "doowb/my-project", 9 | "bugs": { 10 | "url": "https://github.com/doowb/my-project/issues" 11 | }, 12 | "license": "MIT", 13 | "files": [ 14 | "index.js", 15 | "LICENSE" 16 | ], 17 | "main": "index.js", 18 | "engines": { 19 | "node": ">=4" 20 | }, 21 | "scripts": { 22 | "test": "mocha" 23 | }, 24 | "keywords": [ 25 | "generategenerator" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /test/plugin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var path = require('path'); 5 | var assert = require('assert'); 6 | var generate = require('generate'); 7 | var generator = require('../'); 8 | var app; 9 | 10 | var fixtures = path.resolve.bind(path, __dirname, 'fixtures'); 11 | 12 | describe('generate-gh-repo', function() { 13 | beforeEach(function() { 14 | app = generate({cwd: fixtures()}); 15 | }); 16 | 17 | describe('plugin', function() { 18 | it('should add tasks to the instance', function() { 19 | app.use(generator); 20 | assert(app.tasks.hasOwnProperty('default')); 21 | assert(app.tasks.hasOwnProperty('gh-repo')); 22 | }); 23 | 24 | it('should only register the plugin once', function(cb) { 25 | var count = 0; 26 | app.on('plugin', function(name) { 27 | if (name === 'generate-gh-repo') { 28 | count++; 29 | } 30 | }); 31 | app.use(generator); 32 | app.use(generator); 33 | app.use(generator); 34 | assert.equal(count, 1); 35 | cb(); 36 | }); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | process.env.GENERATOR_TEST = true; 4 | require('mocha'); 5 | var fs = require('fs'); 6 | var path = require('path'); 7 | var nock = require('nock'); 8 | var assert = require('assert'); 9 | var generate = require('generate'); 10 | var bddStdin = require('bdd-stdin'); 11 | var npm = require('npm-install-global'); 12 | var generator = require('../'); 13 | var pkg = require('../package'); 14 | var app, mock; 15 | 16 | var cwd = process.cwd(); 17 | var fixtures = path.resolve.bind(path, __dirname, 'fixtures'); 18 | 19 | function setupMock() { 20 | var data1 = { 21 | owner: 'doowb', 22 | repo: 'my-project', 23 | name: 'my-project', 24 | description: 'test project', 25 | homepage: 'https://github.com/doowb/my-project', 26 | private: true 27 | }; 28 | 29 | var data2 = { 30 | owner: 'doowb', 31 | repo: 'my-project', 32 | name: 'my-project', 33 | description: 'test project', 34 | homepage: 'https://github.com/doowb', 35 | private: true 36 | }; 37 | 38 | mock.get('/repos/doowb/my-project') 39 | .query(true) 40 | .reply(200, {message: 'Not Found'}) 41 | .post('/user/repos', data1) 42 | .query(true) 43 | .reply(200, {foo: 'bar'}) 44 | .post('/user/repos', data2) 45 | .query(true) 46 | .reply(200, {foo: 'bar'}); 47 | } 48 | 49 | describe('generate-gh-repo', function() { 50 | if (!process.env.CI && !process.env.TRAVIS) { 51 | before(function(cb) { 52 | npm.maybeInstall('generate', cb); 53 | }); 54 | } 55 | 56 | describe('tasks', function() { 57 | beforeEach(function() { 58 | process.chdir(fixtures()); 59 | mock = nock('https://api.github.com'); 60 | app = generate({ 61 | cwd: fixtures(), 62 | silent: true 63 | }); 64 | app.use(generator); 65 | bddStdin( 66 | '\n', // Use saved credentials 67 | '\n', // project name 68 | '\n', // project description 69 | '\n', // project owner 70 | '\n', // project type 71 | '\n', // project homepage 72 | '\n', // private 73 | '\n', // create project? 74 | '\n', // git remote? 75 | 'n\n' // enable travis-ci? 76 | ); 77 | }); 78 | 79 | afterEach(function() { 80 | process.chdir(cwd); 81 | }); 82 | 83 | it('should return an error when the project already exists', function(cb) { 84 | mock.get('/repos/doowb/my-project') 85 | .query(true) 86 | .reply(200, {id: 123}); 87 | 88 | app.build('default', function(err, results) { 89 | if (!err) return cb(new Error('expected an error')); 90 | try { 91 | assert.equal(err.message, 'Repository already exists.'); 92 | cb(); 93 | } catch(err) { 94 | cb(err); 95 | } 96 | }); 97 | }); 98 | 99 | it('should run the `default` task with .build', function(cb) { 100 | setupMock(); 101 | app.build('default', cb); 102 | }); 103 | 104 | it('should run the `default` task with .generate', function(cb) { 105 | setupMock(); 106 | app.generate('default', cb); 107 | }); 108 | }); 109 | 110 | if (!process.env.CI && !process.env.TRAVIS) { 111 | describe('generator (CLI)', function() { 112 | beforeEach(function() { 113 | process.chdir(fixtures()); 114 | mock = nock('https://api.github.com'); 115 | app = generate({ 116 | cwd: fixtures(), 117 | silent: true 118 | }); 119 | app.use(generator); 120 | setupMock(); 121 | bddStdin( 122 | '\n', // Use saved credentials 123 | '\n', // project name 124 | '\n', // project description 125 | '\n', // project owner 126 | '\n', // project type 127 | '\n', // project homepage 128 | '\n', // private 129 | '\n', // create project? 130 | 'n\n' // enable travis-ci? 131 | ); 132 | }); 133 | 134 | afterEach(function() { 135 | process.chdir(cwd); 136 | }); 137 | 138 | it('should run the default task using the `generate-gh-repo` name', function(cb) { 139 | app.generate('generate-gh-repo', cb); 140 | }); 141 | 142 | it('should run the default task using the `generator` generator alias', function(cb) { 143 | app.generate('gh-repo', cb); 144 | }); 145 | }); 146 | } 147 | 148 | describe('generator (API)', function() { 149 | beforeEach(function() { 150 | process.chdir(fixtures()); 151 | mock = nock('https://api.github.com'); 152 | app = generate({ 153 | cwd: fixtures(), 154 | silent: true 155 | }); 156 | setupMock(); 157 | bddStdin( 158 | '\n', // Use saved credentials 159 | '\n', // project name 160 | '\n', // project description 161 | '\n', // project owner 162 | '\n', // project type 163 | '\n', // project homepage 164 | '\n', // private 165 | '\n', // create project? 166 | 'n\n' // enable travis-ci? 167 | ); 168 | }); 169 | 170 | afterEach(function() { 171 | process.chdir(cwd); 172 | }); 173 | 174 | it('should run the default task on the generator', function(cb) { 175 | app.register('foo', generator); 176 | app.generate('foo', cb); 177 | }); 178 | 179 | it('should run the `gh-repo` task', function(cb) { 180 | app.register('foo', generator); 181 | app.generate('foo:gh-repo', cb); 182 | }); 183 | 184 | it('should run the `default` task when defined explicitly', function(cb) { 185 | app.register('foo', generator); 186 | app.generate('foo:default', cb); 187 | }); 188 | }); 189 | 190 | describe('sub-generator', function() { 191 | beforeEach(function() { 192 | process.chdir(fixtures()); 193 | mock = nock('https://api.github.com'); 194 | app = generate({ 195 | cwd: fixtures(), 196 | silent: true 197 | }); 198 | setupMock(); 199 | bddStdin( 200 | '\n', // Use saved credentials 201 | '\n', // project name 202 | '\n', // project description 203 | '\n', // project owner 204 | '\n', // project type 205 | '\n', // project homepage 206 | '\n', // private 207 | '\n', // create project? 208 | 'n\n' // enable travis-ci? 209 | ); 210 | }); 211 | 212 | afterEach(function() { 213 | process.chdir(cwd); 214 | }); 215 | 216 | it('should work as a sub-generator', function(cb) { 217 | app.register('foo', function(foo) { 218 | foo.register('gh-repo', generator); 219 | }); 220 | app.generate('foo.gh-repo', cb); 221 | }); 222 | 223 | it('should run the `default` task by default', function(cb) { 224 | app.register('foo', function(foo) { 225 | foo.register('gh-repo', generator); 226 | }); 227 | app.generate('foo.gh-repo', cb); 228 | }); 229 | 230 | it('should run the `gh-repo:default` task when defined explicitly', function(cb) { 231 | app.register('foo', function(foo) { 232 | foo.register('gh-repo', generator); 233 | }); 234 | app.generate('foo.gh-repo:default', cb); 235 | }); 236 | 237 | it('should run the `gh-repo:gh-repo` task', function(cb) { 238 | app.register('foo', function(foo) { 239 | foo.register('gh-repo', generator); 240 | }); 241 | app.generate('foo.gh-repo:gh-repo', cb); 242 | }); 243 | 244 | it('should work with nested sub-generators', function(cb) { 245 | app 246 | .register('foo', generator) 247 | .register('bar', generator) 248 | .register('baz', generator); 249 | app.generate('foo.bar.baz', cb); 250 | }); 251 | }); 252 | }); 253 | --------------------------------------------------------------------------------