diff --git a/generators/app/index.js b/generators/app/index.js index 0eafac4..9626616 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -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 } diff --git a/generators/app/templates/_package.json b/generators/app/templates/_package.json index e2b21e8..ed56bd8 100644 --- a/generators/app/templates/_package.json +++ b/generators/app/templates/_package.json @@ -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", diff --git a/test/temp/package.json b/test/temp/package.json index b325e98..4ca4bdd 100644 --- a/test/temp/package.json +++ b/test/temp/package.json @@ -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", diff --git a/test/test-app.mjs b/test/test-app.mjs index 08a4402..092219f 100644 --- a/test/test-app.mjs +++ b/test/test-app.mjs @@ -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', @@ -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')) }) })