Skip to content

Commit

Permalink
fix: Passed in options are not being set when using --defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyguerra committed Apr 1, 2024
1 parent c9465c3 commit a05d940
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
60 changes: 34 additions & 26 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,41 @@ class HubotGenerator extends Generator {

async prompting () {
const botOwner = await this.determineDefaultName()
const prompts = [
{
type: 'input',
name: 'botOwner',
message: 'My Owner',
default: botOwner
},
{
type: 'input',
name: 'botName',
message: 'Bot name',
default: 'mybot'
},
{
type: 'input',
name: 'botDescription',
message: 'Description',
default: 'A simple helpful robot for your Company'
},
{
type: 'input',
name: 'botAdapter',
message: 'Bot adapter',
default: 'shell'
if (this.options.defaults) {
this.props = {
botOwner: this.options.owner,
botName: this.options.name,
botDescription: this.options.description,
botAdapter: this.options.adapter
}
]
this.props = await this.prompt(prompts)
} else {
this.props = await this.prompt([
{
type: 'input',
name: 'botOwner',
message: 'My Owner',
default: botOwner
},
{
type: 'input',
name: 'botName',
message: 'Bot name',
default: 'mybot'
},
{
type: 'input',
name: 'botDescription',
message: 'Description',
default: 'A simple helpful robot for your Company'
},
{
type: 'input',
name: 'botAdapter',
message: 'Bot adapter',
default: 'shell'
}
])
}
return this.props
}

Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "<%= botDescription %>",

"dependencies": {
<% if (botAdapter) { %>"<%= botAdapter %>": "*",<% } %>
<% if (botAdapter && botAdapter !== 'shell') { %>"<%= botAdapter %>": "*",<% } %>
"hubot": "^11.0.0",
"hubot-help": "^2.0.0",
"hubot-redis-brain": "^3.0.0",
Expand Down
1 change: 1 addition & 0 deletions test/temp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"description": "A simple helpful robot for your Company",

"dependencies": {

"hubot": "^11.0.0",
"hubot-help": "^2.0.0",
"hubot-redis-brain": "^3.0.0",
Expand Down
8 changes: 5 additions & 3 deletions test/test-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { describe, it, before } from 'node:test'
import path from 'node:path'
import helpers from 'yeoman-test'
import assert from 'yeoman-assert'

import fs from 'node:fs/promises'
const __dirname = path.dirname(new URL(import.meta.url).pathname)

describe('hubot:app', function () {
before(async () => {
await helpers.run(path.join(__dirname, '../generators/app'))
.withOptions({ 'skip-install': true })
.withOptions({ 'skip-install': true, defaults: true, name: 'hubot', owner: 'temp' })
})

it('creates files', function () {
it('creates files', async function () {
assert.file([
'bin/hubot',
'bin/hubot.cmd',
Expand All @@ -23,5 +23,7 @@ describe('hubot:app', function () {
'package.json',
'scripts/Example.mjs'
])
assert.fileContent('bin/hubot', await fs.readFile(path.join(__dirname, '../test/temp/bin/hubot'), 'utf8'))
assert.fileContent('package.json', await fs.readFile(path.join(__dirname, '../test/temp/package.json'), 'utf8'))
})
})

0 comments on commit a05d940

Please sign in to comment.