Skip to content

Commit a05d940

Browse files
committed
fix: Passed in options are not being set when using --defaults
1 parent c9465c3 commit a05d940

File tree

4 files changed

+41
-30
lines changed

4 files changed

+41
-30
lines changed

generators/app/index.js

+34-26
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,41 @@ class HubotGenerator extends Generator {
128128

129129
async prompting () {
130130
const botOwner = await this.determineDefaultName()
131-
const prompts = [
132-
{
133-
type: 'input',
134-
name: 'botOwner',
135-
message: 'My Owner',
136-
default: botOwner
137-
},
138-
{
139-
type: 'input',
140-
name: 'botName',
141-
message: 'Bot name',
142-
default: 'mybot'
143-
},
144-
{
145-
type: 'input',
146-
name: 'botDescription',
147-
message: 'Description',
148-
default: 'A simple helpful robot for your Company'
149-
},
150-
{
151-
type: 'input',
152-
name: 'botAdapter',
153-
message: 'Bot adapter',
154-
default: 'shell'
131+
if (this.options.defaults) {
132+
this.props = {
133+
botOwner: this.options.owner,
134+
botName: this.options.name,
135+
botDescription: this.options.description,
136+
botAdapter: this.options.adapter
155137
}
156-
]
157-
this.props = await this.prompt(prompts)
138+
} else {
139+
this.props = await this.prompt([
140+
{
141+
type: 'input',
142+
name: 'botOwner',
143+
message: 'My Owner',
144+
default: botOwner
145+
},
146+
{
147+
type: 'input',
148+
name: 'botName',
149+
message: 'Bot name',
150+
default: 'mybot'
151+
},
152+
{
153+
type: 'input',
154+
name: 'botDescription',
155+
message: 'Description',
156+
default: 'A simple helpful robot for your Company'
157+
},
158+
{
159+
type: 'input',
160+
name: 'botAdapter',
161+
message: 'Bot adapter',
162+
default: 'shell'
163+
}
164+
])
165+
}
158166
return this.props
159167
}
160168

generators/app/templates/_package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"description": "<%= botDescription %>",
99

1010
"dependencies": {
11-
<% if (botAdapter) { %>"<%= botAdapter %>": "*",<% } %>
11+
<% if (botAdapter && botAdapter !== 'shell') { %>"<%= botAdapter %>": "*",<% } %>
1212
"hubot": "^11.0.0",
1313
"hubot-help": "^2.0.0",
1414
"hubot-redis-brain": "^3.0.0",

test/temp/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"description": "A simple helpful robot for your Company",
99

1010
"dependencies": {
11+
1112
"hubot": "^11.0.0",
1213
"hubot-help": "^2.0.0",
1314
"hubot-redis-brain": "^3.0.0",

test/test-app.mjs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { describe, it, before } from 'node:test'
33
import path from 'node:path'
44
import helpers from 'yeoman-test'
55
import assert from 'yeoman-assert'
6-
6+
import fs from 'node:fs/promises'
77
const __dirname = path.dirname(new URL(import.meta.url).pathname)
88

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

15-
it('creates files', function () {
15+
it('creates files', async function () {
1616
assert.file([
1717
'bin/hubot',
1818
'bin/hubot.cmd',
@@ -23,5 +23,7 @@ describe('hubot:app', function () {
2323
'package.json',
2424
'scripts/Example.mjs'
2525
])
26+
assert.fileContent('bin/hubot', await fs.readFile(path.join(__dirname, '../test/temp/bin/hubot'), 'utf8'))
27+
assert.fileContent('package.json', await fs.readFile(path.join(__dirname, '../test/temp/package.json'), 'utf8'))
2628
})
2729
})

0 commit comments

Comments
 (0)