UNPKG

generator-msbf-watson-coco

Version:

A yeoman generator for creating bots built with Bot Framework v4, for Watson and CoCo

157 lines (143 loc) 4.73 kB
// @ts-nocheck // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. const _ = require("lodash"); const { BOT_TEMPLATE_NAME_SIMPLE, BOT_TEMPLATE_NOPROMPT_SIMPLE, BOT_HELP_URL_SIMPLE, BOT_LANG_NAME_JAVASCRIPT, BOT_LANG_NAME_TYPESCRIPT } = require("./constants"); /** * configureCommandlineOptions * does the work to configure the commandline options that this template will accept * this is mostly made available so that we can run the template without user * intervention. e.g. automated test runs * @param {Generator} gen Yeoman's generator object */ module.exports.configureCommandlineOptions = gen => { gen.option("botname", { desc: "The name you want to give to your bot", type: String, default: "my-chat-bot", alias: "N" }); gen.option("description", { desc: "A brief bit of text used to describe what your bot does", type: String, default: "Demonstrate the core capabilities of the Microsoft Bot Framework with Conversational Components", alias: "D" }); const langDesc = `The programming language use by the project. (${BOT_LANG_NAME_JAVASCRIPT} | ${BOT_LANG_NAME_TYPESCRIPT})`; gen.option("language", { desc: langDesc, type: String, default: BOT_LANG_NAME_JAVASCRIPT, alias: "L" }); gen.argument("noprompt", { desc: "Do not prompt for any information or confirmation", type: Boolean, required: false, default: false }); }; /** * getPrompts * constructs an array of prompts name/value pairs. This is the input we need from the user * or passed into the command line to successfully configure a new bot * @param {Object} options */ module.exports.getPrompts = generator => { const noprompt = generator.options.noprompt; const prompts = { // ask the user to name their bot askForBotName: () => { if (noprompt) { return Promise.resolve(); } return generator .prompt({ type: "input", name: "botname", message: `What's the name of your bot?`, default: generator.options.botname ? generator.options.botname : "my-chat-bot" }) .then(answer => { // store the botname description answer generator.templateConfig.botname = answer.botname; }); }, // as the user for a decription of their bot askForBotDescription: () => { if (noprompt) { return Promise.resolve(); } return generator .prompt({ type: "input", name: "description", message: "What will your bot do?", default: generator.options.description ? generator.options.description : "Demonstrate the core capabilities of a Conversational AI bot" }) .then(answer => { // store the language description answer generator.templateConfig.description = answer.description; }); }, // ask the user which programming language they want to use askForProgrammingLanguage: () => { if (noprompt) { return Promise.resolve(); } return generator .prompt({ type: "list", name: "language", message: "What programming language do you want to use?", choices: [ { name: BOT_LANG_NAME_JAVASCRIPT, value: _.toLower(BOT_LANG_NAME_JAVASCRIPT) }, { name: BOT_LANG_NAME_TYPESCRIPT, value: _.toLower(BOT_LANG_NAME_TYPESCRIPT) } ], default: generator.options.language ? _.toLower(generator.options.language) : BOT_LANG_NAME_JAVASCRIPT }) .then(answer => { // store the language prompt answer generator.templateConfig.language = answer.language; }); }, askForBotTemplate: () => Promise.resolve(), // ask the user for final confirmation before we generate their bot askForFinalConfirmation: () => { if (noprompt) { return Promise.resolve(); } return generator .prompt({ type: "confirm", name: "finalConfirmation", message: "Looking good. Shall I go ahead and create your new bot?", default: true }) .then(answer => { // store the finalConfirmation prompt answer generator.templateConfig.finalConfirmation = answer.finalConfirmation; }); } }; return prompts; };