Skip to content

Commit ef2c57d

Browse files
committed
Extract init command from probot/probot#139
h/t @boneskull
0 parents  commit ef2c57d

File tree

5 files changed

+1799
-0
lines changed

5 files changed

+1799
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

LICENSE

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright (c) 2017, Brandon Keepers
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

bin/create-probot-plugin.js

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const path = require('path');
6+
const inquirer = require('inquirer');
7+
const program = require('commander');
8+
const {scaffold} = require('egad');
9+
const kebabCase = require('lodash.kebabcase');
10+
const chalk = require('chalk');
11+
const stringifyAuthor = require('stringify-author');
12+
const {guessEmail, guessAuthor, guessGitHubUsername} = require('conjecture');
13+
14+
const PLUGIN_REPO_URL = 'https://github.com/probot/plugin-template.git';
15+
16+
program
17+
.usage('[options] [destination]')
18+
.option('-p, --pkgname <package-name>', 'Plugin package name')
19+
.option('-d, --desc "<description>"',
20+
'Plugin description (contain in quotes)')
21+
.option('-a, --author "<full-name>"',
22+
'Plugin author name (contain in quotes)')
23+
.option('-e, --email <email>', 'Plugin author email address')
24+
.option('-h, --homepage <homepage>', 'Plugin author\'s homepage')
25+
.option('-u, --user <username>', 'GitHub username or org (repo owner)')
26+
.option('-r, --repo <repo-name>', 'Plugin repo name')
27+
.option('--overwrite', 'Overwrite existing files', false)
28+
.option('--template <template-url>', 'URL of custom plugin template',
29+
PLUGIN_REPO_URL)
30+
.parse(process.argv);
31+
32+
const destination = program.args.length ?
33+
path.resolve(process.cwd(), program.args.shift()) :
34+
process.cwd();
35+
36+
const prompts = [
37+
{
38+
type: 'input',
39+
name: 'name',
40+
default(answers) {
41+
return answers.repo || kebabCase(path.basename(destination));
42+
},
43+
message: 'Plugin\'s package name:',
44+
when: !program.pkgname
45+
},
46+
{
47+
type: 'input',
48+
name: 'desc',
49+
default() {
50+
return 'A Probot plugin';
51+
},
52+
message: 'Description of plugin:',
53+
when: !program.desc
54+
},
55+
{
56+
type: 'input',
57+
name: 'author',
58+
default() {
59+
return guessAuthor();
60+
},
61+
message: 'Plugin author\'s full name:',
62+
when: !program.author
63+
},
64+
{
65+
type: 'input',
66+
name: 'email',
67+
default() {
68+
return guessEmail();
69+
},
70+
message: 'Plugin author\'s email address:',
71+
when: !program.email
72+
},
73+
{
74+
type: 'input',
75+
name: 'homepage',
76+
message: 'Plugin author\'s homepage:',
77+
when: !program.homepage
78+
},
79+
{
80+
type: 'input',
81+
name: 'owner',
82+
default(answers) {
83+
return guessGitHubUsername(answers.email);
84+
},
85+
message: 'Plugin\'s GitHub user or org name:',
86+
when: !program.user
87+
},
88+
{
89+
type: 'input',
90+
name: 'repo',
91+
default(answers) {
92+
return answers.pkgname || kebabCase(path.basename(destination));
93+
},
94+
message: 'Plugin\'s repo name:',
95+
when: !program.repo
96+
}
97+
];
98+
99+
console.log(chalk.blue('Let\'s create a Probot plugin!'));
100+
101+
inquirer.prompt(prompts)
102+
.then(answers => {
103+
answers.author = stringifyAuthor({
104+
name: answers.author,
105+
email: answers.email,
106+
url: answers.homepage
107+
});
108+
return scaffold(program.template, destination, answers, {
109+
overwrite: Boolean(program.overwrite)
110+
});
111+
})
112+
.then(results => {
113+
results.forEach(fileinfo => {
114+
console.log(`${fileinfo.skipped ? chalk.yellow('skipped existing file') :
115+
chalk.green('created file')}: ${fileinfo.path}`);
116+
});
117+
console.log(chalk.blue('Done!'));
118+
});

0 commit comments

Comments
 (0)