diff --git a/bin/create-probot-app.js b/bin/create-probot-app.js index 011c936088..d5ce5d36c2 100755 --- a/bin/create-probot-app.js +++ b/bin/create-probot-app.js @@ -10,11 +10,28 @@ const { generate } = require('egad') const kebabCase = require('lodash.kebabcase') const camelCase = require('lodash.camelcase') const chalk = require('chalk') +const jsesc = require('jsesc') const spawn = require('cross-spawn') const stringifyAuthor = require('stringify-author') const { guessEmail, guessAuthor, guessGitHubUsername } = require('conjecture') const validatePackageName = require('validate-npm-package-name') +/** + * Partially sanitizes keys by escaping double-quotes. + * + * @param {Object} object The object to mutate. + * @param {String[]} keys The keys on `object` to sanitize. + */ +function sanitizeBy(object, keys) { + keys.forEach(key => { + if (key in object) { + object[key] = jsesc(object[key], { + quotes: 'double' + }) + } + }) +} + program .usage('[options] [destination]') .option('-n, --appName ', 'App name') @@ -133,6 +150,8 @@ inquirer.prompt(prompts) answers.template = program.template || answers.template // TODO: clean that up into nicer object combinging + + sanitizeBy(answers, ['author', 'description']) if (!templates.includes(answers.template)) { console.log(chalk.red(`Please use an existing use case template: ${templates.join(', ')}`)) diff --git a/package.json b/package.json index 2109c20232..0c1870b9b7 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "conjecture": "^0.1.2", "egad": "^0.2.0", "inquirer": "^7.0.0", + "jsesc": "^2.5.2", "lodash.camelcase": "^4.3.0", "lodash.kebabcase": "^4.1.1", "stringify-author": "^0.1.3",