Skip to content

Commit

Permalink
feat(generator): add keywords option
Browse files Browse the repository at this point in the history
resolves #5
  • Loading branch information
macklinu committed May 20, 2017
1 parent a68d753 commit 7b777ca
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 73 deletions.
2 changes: 2 additions & 0 deletions src/app/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Object {
"keywords": Array [
"danger",
"danger-plugin",
"fun",
"time",
],
"license": "MIT",
"lint-staged": Object {
Expand Down
49 changes: 49 additions & 0 deletions src/app/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export const defaultPackageJson = {
version: '0.0.0-development',
main: 'dist/index.js',
types: 'types/index.d.ts',
scripts: {
precommit: 'lint-staged',
commit: 'git-cz',
commitmsg: 'validate-commit-msg',
build: 'babel src --out-dir dist --ignore *.test.js',
test: 'jest',
predocs: 'rm -rf docs/',
docs: 'esdoc -c .esdoc.json',
prepublish: 'npm run build',
'semantic-release': 'semantic-release pre && npm publish && semantic-release post',
},
license: 'MIT',
engines: {
node: '>=4.0.0',
},
devDependencies: {
'babel-cli': '^6.24.1',
'babel-jest': '^20.0.1',
'babel-preset-env': '^1.4.0',
commitizen: '^2.9.6',
'cz-conventional-changelog': '^2.0.0',
husky: '^0.13.3',
jest: '^20.0.1',
'lint-staged': '^3.4.1',
prettier: '^1.3.1',
'semantic-release': '^6.3.6',
typescript: '^2.3.2',
'typings-tester': '^0.2.2',
'validate-commit-msg': '^2.12.1',
},
optionalDependencies: {
esdoc: '^0.5.2',
},
config: {
commitizen: {
path: 'cz-conventional-changelog',
},
},
'lint-staged': {
'*.js': [
'prettier --single-quote --trailing-comma=all --no-semi --write',
'git add',
],
},
}
38 changes: 32 additions & 6 deletions src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import chalk from 'chalk'

import { defaultEmail, defaultGitHubUsername, defaultName } from './values'
import * as validators from './validators'
import { defaultPackageJson } from './defaults'

const PLUGIN_PREFIX = 'danger-plugin-'

Expand All @@ -21,6 +22,7 @@ function makeGeneratorName(name) {
function makePluginFunctionName(name) {
return _.camelCase(name.substring(PLUGIN_PREFIX.length, name.length))
}

export default class extends Generator {
initializing() {
this.props = {}
Expand All @@ -44,6 +46,12 @@ export default class extends Generator {
message: 'Provide a brief description of the Danger plugin:',
validate: validators.description,
},
{
type: 'input',
name: 'keywords',
message: `Any additional package keywords (besides ${chalk.yellow('danger')} and ${chalk.yellow('danger-plugin')})?`,
filter: words => words.split(/\s*,\s*/g),
},
{
type: 'input',
name: 'authorName',
Expand Down Expand Up @@ -109,6 +117,30 @@ export default class extends Generator {
})
)

const pkg = Object.assign(
{
name: this.props.pluginName,
description: this.props.description,
author: {
name: this.props.authorName,
email: this.props.authorEmail,
},
repository: {
type: 'git',
url: `${githubBaseUrl}.git`,
},
bugs: {
url: `${githubBaseUrl}/issues`,
},
homepage: `${githubBaseUrl}#readme`,
keywords: _.uniq(
['danger', 'danger-plugin'].concat(this.props.keywords || [])
),
},
defaultPackageJson
)
this.fs.writeJSON(this.destinationPath('package.json'), pkg)

this.fs.copyTpl(
this.templatePath('README.md'),
this.destinationPath('README.md'),
Expand All @@ -120,12 +152,6 @@ export default class extends Generator {
this.destinationPath('CONTRIBUTING.md')
)

this.fs.copyTpl(
this.templatePath('package.json'),
this.destinationPath('package.json'),
{ ...this.props, githubBaseUrl }
)

this.fs.copyTpl(
this.templatePath('CODE_OF_CONDUCT.md'),
this.destinationPath('CODE_OF_CONDUCT.md'),
Expand Down
1 change: 1 addition & 0 deletions src/app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('generator:app', () => {
authorName: 'Macklin Underdown',
authorEmail: '[email protected]',
githubUsername: 'macklinu',
keywords: ['fun', 'time'],
})
const pkg = readFile('package.json')
expect(pkg).toMatchSnapshot()
Expand Down
67 changes: 0 additions & 67 deletions src/app/templates/package.json

This file was deleted.

0 comments on commit 7b777ca

Please sign in to comment.