Skip to content

Commit

Permalink
feat(code-of-conduct): generate a CODE_OF_CONDUCT.md file
Browse files Browse the repository at this point in the history
With the primary "Contact email".

#8
  • Loading branch information
gregswindle committed Sep 26, 2017
1 parent 1a796a1 commit 40c1e51
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 14 deletions.
59 changes: 48 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `generator-community`

[![License][license-badge-image]][license-url] [![Dependencies' licenses][fossa-badge-image]][fossa-url] [![NSP Status][nsp-badge-image]][nsp-url] [![Synk Vulnerabilities][snyk-vulnerabilities-badge-image]][snyk-vulnerabilities-url]<br>[![StackShare][stack-share-badge-image]][stack-share-url] [![Dependency Status][david-dm-badge-image]][daviddm-url] [![devDependencies Status][david-dm-dev-badge-image]][daviddm-dev-url] <br>[![Build Status][travis-badge-image]][travis-url] [![Windows Build status][appveyor-badge-image]][appveyor-url] [![Coverage percentage][coveralls-badge-image]][coveralls-url] [![Codacy quality][codacy-badge-image]][codacy-url]
[![License][license-badge-image]][license-url] [![Dependencies' licenses][fossa-badge-image]][fossa-url] [![NSP Status][nsp-badge-image]][nsp-url] [![Synk Vulnerabilities][snyk-vulnerabilities-badge-image]][snyk-vulnerabilities-url]<br>[![StackShare][stack-share-badge-image]][stack-share-url] [![Dependency Status][david-dm-badge-image]][daviddm-url] [![devDependencies Status][david-dm-dev-badge-image]][daviddm-dev-url] <br>[![Build Status][travis-badge-image]][travis-url] [![Windows Build status][appveyor-badge-image]][appveyor-url] [![Coverage Status](https://coveralls.io/repos/github/commonality/generator-community/badge.svg?branch=master)](https://coveralls.io/github/commonality/generator-community?branch=master) [![Codacy quality][codacy-badge-image]][codacy-url]
> Generate `README`, `CODE_OF_CONDUCT`, `CONTRIBUTING`, and `LICENSE` files according to [recommended community standards][opensource-guide-community-standards-url].

Expand All @@ -16,6 +16,8 @@
+ [3.1.1. Guided assistance](#311-guided-assistance)
+ [3.1.2. CLI automation](#312-cli-automation)
* [3.2. `yo community:conduct`](#32-yo-communityconduct)
+ [3.2.1. Guided assistance](#321-guided-assistance)
+ [3.2.2. CLI automation](#322-cli-automation)
* [3.3. `yo community:contributing`](#33-yo-communitycontributing)
* [3.4. `yo community:license`](#34-yo-communitylicense)
+ [3.4.1. Guided assistance](#341-guided-assistance)
Expand All @@ -38,14 +40,15 @@

---

[![Alert icon][icon-alert-50-image]][milestones-url] Currently, `generator-community` generates:
[![Alert icon][icon-alert-50-image]][milestones-url] Currently, `generator-community` generates a:

1. `README.md` files
1. `LICENSEs`
1. `.editorconfig` files
1. `.gitattributes` files
1. `.gitignore` files
1. `.yo-rc.json` files (to store answers for your convenience)
1. `.editorconfig`
1. `.gitattributes`
1. `.gitignore`
1. `.yo-rc.json` (to store answers for your convenience)
1. `CODE_OF_CONDUCT.md`
1. `LICENSE`
1. `README.md`

`generator-community` also initializes local Git repository, if one doesn't yet exist.

Expand Down Expand Up @@ -133,12 +136,14 @@ $ yo community
? Which programming language does this product use the most? Node.js (JavaScript)
? What do you use to manage dependencies (e.g., Gradle, npm, NuGet)? Leave blank if you don't know. npm
? ⦾ 📄 LICENSE: Select a license MIT
? ⦾ 📄 CODE_OF_CONDUCT: Would you like to generate a Code of Conduct? Yes
? ⦾ 📄 README: Select the sections to include in your README Overview, Configuration, Security, API, Background, License
create package.json
create README.md
create .editorconfig
create .gitattributes
create .gitignore
create CODE_OF_CONDUCT.md
create LICENSE


Expand Down Expand Up @@ -263,7 +268,39 @@ $ yo community:readme --authorName "Jane Doe" --authorUrl "https://jdoe.example.
>
> Owen, K., Keepers, B., Shepherd, S., & Eghbal, N. (2017, February 17). Starting an Open Source Project. Retrieved September 13, 2017, from https://opensource.guide/starting-a-project/#establishing-a-code-of-conduct

[![Alert icon][icon-goal-image]][milestones-url] This feature will be delivered with [MVP2: community:conduct][milestones-url].
#### 3.2.1. Guided assistance

To answer prompts manually, open a Terminal and run

```shell
$ yo community:conduct
? Contact email: fake@elsewhere.net
create CODE_OF_CONDUCT.md
```

#### 3.2.2. CLI automation

You can automate CODE_OF_CONDUCT.md generation via the command line interface (CLI) (e.g., during one of your CI/CD pipelines). To view all CLI options, use the `--help` or `-h` option:

```shell
$ yo community:conduct --help
Usage:
yo community:conduct [options]
Options:
-h, --help # Print the generator's options and usage
--skip-cache # Do not remember prompt answers Default: false
--skip-install # Do not automatically install dependencies Default: false
--email # Contact email
--generateInto # Destination directory
```

__Example:__

```shell
$ yo community:conduct --email somebody@example.com
create CODE_OF_CONDUCT.md
```

### 3.3. `yo community:contributing`
> ![Quote][icon-quote-left-image] A CONTRIBUTING file tells your audience how to participate in your project. For example, you might include information on:
Expand Down Expand Up @@ -300,7 +337,7 @@ The `community:readme` subgenerator will evaluate your product repository's _man
__Example:__
```shell
yo community:license
$ yo community:license
? What's your name: Greg Swindle
? Your email (optional): greg@swindle.net
? Your website (optional):
Expand Down Expand Up @@ -438,7 +475,7 @@ __Third-party software licenses for `generator-community__ ([read the NOTICE fil
[conventional-commits-badge-image]: https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg?style=flat-square
[conventional-commits-url]: https://conventionalcommits.org/
[coolor-palette-url]: https://coolors.co/cfdbd5-e8eddf-f5cb5c-242423-333533
[coveralls-badge-image]: https://img.shields.io/coveralls/repos/commonality/generator-community/badge.svg?style=flat-square
[coveralls-badge-image]: https://img.shields.io/coveralls/repos/commonality/generator-community/badge.svg?branch=master&style=flat-square
[coveralls-url]: https://coveralls.io/r/commonality/generator-community
[david-dm-badge-image]: https://img.shields.io/david/dev/commonality/generator-community.svg?style=flat-square
[david-dm-dev-badge-image]: https://img.shields.io/david/commonality/generator-community.svg?style=flat-square
Expand Down
44 changes: 44 additions & 0 deletions __tests__/conduct.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict'
var path = require('path')
var assert = require('yeoman-assert')
var helpers = require('yeoman-test')

describe('generator-community:conduct', () => {
afterAll(() => {
process.setMaxListeners(0)
})

describe(', when given a contact email with --email,', () => {
beforeEach(() => {
return helpers.run(path.join(__dirname, '../generators/conduct'))
.withOptions({
conduct: true,
email: 'somebody@example.com'
})
})

it('creates a CODE_OF_CONDUCT.md with a team contact email', () => {
assert.file('CODE_OF_CONDUCT.md')
assert.fileContent('CODE_OF_CONDUCT.md', '[email]: somebody@example.com')
})
})

describe(', when not given an --email,', () => {
beforeEach(() => {
return helpers.run(path.join(__dirname, '../generators/conduct'))
.withOptions({
conduct: true
})
.withPrompts({
email: 'somebody@example.com'
})
.on('ready', (generator) => {
generator.options.email = null
})
})

it('prompts for an email address', () => {
assert.fileContent('CODE_OF_CONDUCT.md', '[email]: somebody@example.com')
})
})
})
6 changes: 6 additions & 0 deletions generators/app/default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ const defaultOptions = {
required: true,
type: String
},
conduct: {
defaults: true,
desc: 'Code of Conduct',
required: false,
type: Boolean
},
dependencyManager: {
defaults: 'Unspecified',
desc: 'Tool used to install third-party libraries',
Expand Down
7 changes: 7 additions & 0 deletions generators/app/default-prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ class DefaultPrompts {
default: generator.props.defaultLicense || generator.props.license,
when: !generator.props.license,
choices: spdx.licenses
},
{
type: 'confirm',
name: 'conduct',
message: '⦾ 📄 CODE_OF_CONDUCT: Would you like to generate a Code of Conduct?',
default: true,
when: !generator.props.conduct
}
]
}
Expand Down
10 changes: 9 additions & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CommunityAppGenerator extends YeomanGenerator {
this.props = this.nodeAppGenerator.props
this.props.license = this.nodeAppGenerator.pkg.license
this.pkg = this.nodeAppGenerator.pkg
this.props.repository = this.pkg.repository
}

_askForGithubAccount () {
Expand Down Expand Up @@ -133,6 +134,13 @@ class CommunityAppGenerator extends YeomanGenerator {
if (!this.fs.exists(this.destinationPath('README.md'))) {
this.composeWith(require.resolve('../readme'), this.props)
}

/* istanbul ignore else */
if (this.options.conduct) {
this.composeWith(require.resolve('../conduct'), {
email: this.props.authorEmail
})
}
}

writing () {
Expand All @@ -141,7 +149,7 @@ class CommunityAppGenerator extends YeomanGenerator {

const pkgTemplate = require('./templates/package.json')

const issuesUrl = `https://github.com/${this.props.githubAccount}/${this.props.name}`
const issuesUrl = `https://github.com/${this.props.repository}/issues`

const pkg = _.merge({
bugs: issuesUrl,
Expand Down
52 changes: 52 additions & 0 deletions generators/conduct/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict'

const YeomanGenerator = require('yeoman-generator')

class CommunityConductGenerator extends YeomanGenerator {
constructor (args, options) {
super(args, options)

this.option('email', {
defaults: this.options.email || this.user.git.email(),
desc: 'Contact email',
required: true,
type: String
})

this.option('generateInto', {
defaults: '',
desc: 'Destination directory',
required: false,
type: String
})
}

prompting () {
if (this.options.email) {
return Promise.resolve(true)
} else {
const prompts = [
{
name: 'email',
message: 'Contacts\'s e-mail',
when: !this.options.email,
default: this.user.git.email(),
store: true
}
]
return this.prompt(prompts).then((answer) => {
this.options.email = answer.email
})
}
}

writing () {
this.fs.copyTpl(
this.templatePath('en/_CODE_OF_CONDUCT.md'),
this.destinationPath(this.options.generateInto, 'CODE_OF_CONDUCT.md'),
this.options
)
}
};

module.exports = CommunityConductGenerator
74 changes: 74 additions & 0 deletions generators/conduct/templates/en/_CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by [contacting the project team][email]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[email]: <%= email %>
[homepage]: https://www.contributor-covenant.org
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
"main": "index.js",
"repository": "commonality/generator-community",
"scripts": {
"docs": "md-magic --path '**/*.md' --ignore 'node_modules' --ignore 'node_modules' --config ./markdown.config.js",
"docs:toc": "md-magic --path '**/*.md' --ignore 'node_modules'",
"docs": "md-magic --ignore 'node_modules' --ignore 'node_modules' --config ./markdown.config.js",
"docs:toc": "md-magic --ignore 'node_modules'",
"lint": "npm run lint:node-version && npm run lint:js && npm run lint:manifest",
"lint:js": "eslint ./generators/**/*.js ./__tests__/**/*.js --fix",
"lint:manifest": "fixpack",
Expand Down

0 comments on commit 40c1e51

Please sign in to comment.