From 7b777ca5905c1a2f81f848fe5fcd3c1636c6d002 Mon Sep 17 00:00:00 2001 From: Macklin Underdown Date: Thu, 18 May 2017 18:21:05 -0400 Subject: [PATCH] feat(generator): add keywords option resolves #5 --- src/app/__snapshots__/index.test.js.snap | 2 + src/app/defaults.js | 49 +++++++++++++++++ src/app/index.js | 38 +++++++++++--- src/app/index.test.js | 1 + src/app/templates/package.json | 67 ------------------------ 5 files changed, 84 insertions(+), 73 deletions(-) create mode 100644 src/app/defaults.js delete mode 100644 src/app/templates/package.json diff --git a/src/app/__snapshots__/index.test.js.snap b/src/app/__snapshots__/index.test.js.snap index d5ab03c..a69eb5e 100644 --- a/src/app/__snapshots__/index.test.js.snap +++ b/src/app/__snapshots__/index.test.js.snap @@ -133,6 +133,8 @@ Object { "keywords": Array [ "danger", "danger-plugin", + "fun", + "time", ], "license": "MIT", "lint-staged": Object { diff --git a/src/app/defaults.js b/src/app/defaults.js new file mode 100644 index 0000000..b2190ba --- /dev/null +++ b/src/app/defaults.js @@ -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', + ], + }, +} diff --git a/src/app/index.js b/src/app/index.js index 6299099..e72afc8 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -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-' @@ -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 = {} @@ -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', @@ -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'), @@ -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'), diff --git a/src/app/index.test.js b/src/app/index.test.js index b29f2ee..53d5bd4 100644 --- a/src/app/index.test.js +++ b/src/app/index.test.js @@ -117,6 +117,7 @@ describe('generator:app', () => { authorName: 'Macklin Underdown', authorEmail: 'email@example.com', githubUsername: 'macklinu', + keywords: ['fun', 'time'], }) const pkg = readFile('package.json') expect(pkg).toMatchSnapshot() diff --git a/src/app/templates/package.json b/src/app/templates/package.json deleted file mode 100644 index 7b8e76f..0000000 --- a/src/app/templates/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "<%= pluginName %>", - "version": "0.0.0-development", - "description": "<%= description %>", - "author": { - "name": "<%= authorName %>", - "email": "<%= authorEmail %>" - }, - "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" - }, - "keywords": [ - "danger", - "danger-plugin" - ], - "license": "MIT", - "engines": { - "node": ">=4.0.0" - }, - "repository": { - "type": "git", - "url": "<%= githubBaseUrl %>.git" - }, - "bugs": { - "url": "<%= githubBaseUrl %>/issues" - }, - "homepage": "<%= githubBaseUrl %>#readme", - "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" - ] - } -}