prompting()

in templates/typescript/generator-bot-virtualassistant/generators/skill/index.js [123:237]


  prompting() {
    this.log(bigBot);
    // Validate language option
    if (this.options.skillLang) {
      this.options.skillLang = this.options.skillLang
        .replace(/\s/g, "")
        .split(",");
      if (
        !this.options.skillLang.every(language => {
          return languages.includes(language);
        })
      ) {
        this.log.error(
          "ERROR: One of the languages is not recognized, please check your language value\n\t"
        );
        process.exit(1);
      }
    } else {
      this.log.error(
        "ERROR: Language must be selected from the list:\n\t" +
          languages.map(l => `${l.value} -> ${l.name}`).join("\n\t") +
          "\nDefault value: en-us"
      );
      process.exit(1);
    }

    // Generate the main prompts
    const prompts = [
      // Name of the skill
      {
        type: `input`,
        name: `skillName`,
        message: `What's the name of your skill?`,
        default: this.options.skillName
          ? this.options.skillName
          : `sample-skill`
      },
      // Description of the skill
      {
        type: `input`,
        name: `skillDesc`,
        message: `What's the description of your skill?`,
        default: this.options.skillDesc ? this.options.skillDesc : ``
      },
      // Language of the skill
      {
        type: "checkbox",
        name: "skillLang",
        message: "Which languages will your skill use?",
        choices: languagesChoice
      },
      // Path of the skill
      {
        type: `confirm`,
        name: `pathConfirmation`,
        message: `Do you want to change the new skill's location?`,
        default: false
      },
      {
        when: function(response) {
          return response.pathConfirmation === true;
        },
        type: `input`,
        name: `skillGenerationPath`,
        message: `Where do you want to generate the skill?`,
        default: this.options.skillGenerationPath
          ? this.options.skillGenerationPath
          : process.cwd(),
        validate: path => {
          if (fs.existsSync(path)) {
            return true;
          }

          this.log(
            chalk.red(
              `\n`,
              `ERROR: This is not a valid path. Please try again.`
            )
          );
        }
      },
      // Final confirmation of the skill
      {
        type: `confirm`,
        name: `finalConfirmation`,
        message: `Looking good. Shall I go ahead and create your new skill?`,
        default: true
      }
    ];

    // Check that if it was generated with CLI commands
    if (this.options.noPrompt) {
      this.props = _pick(this.options, [
        `skillName`,
        `skillDesc`,
        `skillLang`,
        `skillGenerationPath`
      ]);

      // Validate we have what we need, or we'll need to throw
      if (!this.props.skillName) {
        this.log.error(
          `ERROR: Must specify a name for your skill when using --noPrompt argument. Use --skillName or -n option.`
        );
        process.exit(1);
      }

      this.props.finalConfirmation = true;
      return;
    }

    return this.prompt(prompts).then(props => {
      this.props = props;
    });
  }