Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Dependencies
node_modules

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
debug.log

# Lockfiles
package-lock.json
yarn.lock

# Temporary directory for testing
tmp
49 changes: 44 additions & 5 deletions bin/create-probot-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

'use strict'

const fs = require('fs')
const path = require('path')
const inquirer = require('inquirer')
const program = require('commander')
const {generate} = require('egad')
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 { guessEmail, guessAuthor, guessGitHubUsername } = require('conjecture')
const validatePackageName = require('validate-npm-package-name')

program
Expand All @@ -35,6 +37,22 @@ const destination = program.args.length

const templates = ['basic-js', 'checks-js', 'git-data-js', 'deploy-js', 'basic-ts']

/**
* 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'
})
}
})
}

const prompts = [
{
type: 'input',
Expand Down Expand Up @@ -131,28 +149,49 @@ inquirer.prompt(prompts)
answers.repo = program.repo || answers.repo
answers.template = program.template || answers.template

// TODO: clean that up into nicer object combinging
// TODO: clean that up into nicer object combining

sanitizeBy(answers, ['author', 'description'])

if (!templates.includes(answers.template)) {
console.log(chalk.red(`Please use an existing use case template: ${templates.join(', ')}`))
process.exit(1)
}

const relativePath = path.join(__dirname, '/../templates/', answers.template)
return generate(relativePath, destination, answers, {
overwrite: Boolean(program.overwrite)
})
})
.then(results => {
results.forEach(fileinfo => {
if (fileinfo.skipped === false &&
path.basename(fileinfo.path) === 'gitignore'
) {
try {
const gitignorePath = path.join(path.dirname(fileinfo.path), '.gitignore')

if (fs.existsSync(gitignorePath)) {
const data = fs.readFileSync(fileinfo.path, { encoding: 'utf8' })
fs.appendFileSync(gitignorePath, data)
fs.unlinkSync(fileinfo.path)
} else {
fs.renameSync(fileinfo.path, gitignorePath)
}

fileinfo.path = gitignorePath
} catch (err) {
throw err
}
}

console.log(`${fileinfo.skipped ? chalk.yellow('skipped existing file')
: chalk.green('created file')}: ${fileinfo.path}`)
})
return console.log(chalk.blue('Finished scaffolding files!'))
})
.then(() => {
console.log(chalk.blue('\nInstalling Node dependencies!'))
const child = spawn('npm', ['install', '--prefix', destination], {stdio: 'inherit'})
const child = spawn('npm', ['install', '--prefix', destination], { stdio: 'inherit' })
child.on('close', code => {
if (code !== 0) {
console.log(chalk.red(`Could not install npm dependencies. Try running ${chalk.bold('npm install')} yourself.`))
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"conjecture": "^0.1.2",
"egad": "^0.2.0",
"inquirer": "^6.2.2",
"jsesc": "^2.5.2",
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1",
"stringify-author": "^0.1.3",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.