Skip to content

Commit

Permalink
[Virtual Assistant Template][TypeScript] Create Virtual Assistant Gen…
Browse files Browse the repository at this point in the history
…erator (microsoft#1056)

* Add generator-botbuilder-assistant

* Fix homepage of package json
  • Loading branch information
Batta32 authored and darrenj committed Apr 6, 2019
1 parent 10d7c2f commit f104cfe
Show file tree
Hide file tree
Showing 11 changed files with 4,320 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generator's templates
/generators/app/templates

# Generator's tests
/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": [
"xo",
"prettier"
],
"env": {
"mocha": true,
"node": true
},
"rules": {
"prettier/prettier": "error"
},
"plugins": [
"prettier"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# node.js dependencies folder
node_modules/

# Bot Files
*.bot

#generator tests
test/
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 Microsoft <[email protected]> (http://dev.botframework.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

"use strict";
const Generator = require("yeoman-generator");
const chalk = require("chalk");
const path = require("path");
const pkg = require("../../package.json");
const _pick = require("lodash/pick");
const _camelCase = require("lodash/camelCase");
const _upperFirst = require("lodash/upperFirst");
const fs = require("fs");

const bigBot =
" ╭─────────────────────────────────╮\n" +
" " +
chalk.blue.bold("//") +
" " +
chalk.blue.bold("\\\\") +
" │ Welcome to the │\n" +
" " +
chalk.blue.bold("//") +
" () () " +
chalk.blue.bold("\\\\") +
" │ BotBuilder Virtual Assistant │\n" +
" " +
chalk.blue.bold("\\\\") +
" " +
chalk.blue.bold("//") +
" /│ generator! │\n" +
" " +
chalk.blue.bold("\\\\") +
" " +
chalk.blue.bold("//") +
" ╰─────────────────────────────────╯\n" +
` v${pkg.version}`;

const tinyBot =
" " + chalk.blue.bold("<") + " ** " + chalk.blue.bold(">") + " ";

var assistantGenerationPath = process.cwd();
var isAlreadyCreated = false;

module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);

this.option("assistantName", {
description: "The name you want to give to your assistant.",
type: String,
default: "customAssistant",
alias: "n"
});

this.option("assistantDesc", {
description: "A brief bit of text used to describe what your assistant does.",
type: String,
alias: "d"
});

this.option("assistantGenerationPath", {
description: "The path where the assistant will be generated.",
type: String,
default: process.cwd(),
alias: "p"
});

this.option("noPrompt", {
description: "Do not prompt for any information or confirmation.",
type: Boolean,
default: false
});
}

prompting() {
this.log(bigBot);
// Generate the main prompts
const prompts = [
// Name of the assistant
{
type: "input",
name: "assistantName",
message: "What's the name of your assistant?",
default: this.options.assistantName ? this.options.assistantName : "customAssistant"
},
// Description of the assistant
{
type: "input",
name: "assistantDesc",
message: "What will your assistant do?",
default: this.options.assistantDesc ? this.options.assistantDesc : ""
},
// Path of the assistant
{
type: "confirm",
name: "pathConfirmation",
message: "Do you want to change the new assistant's location?",
default: false
},
{
when: function(response) {
return response.pathConfirmation === true;
},
type: "input",
name: "assistantGenerationPath",
message: "Where do you want to generate the assistant?",
default: this.options.assistantGenerationPath
? this.options.assistantGenerationPath
: 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 assistant
{
type: "confirm",
name: "finalConfirmation",
message: "Looking good. Shall I go ahead and create your new assistant?",
default: true
}
];

// Check that if it was generated with CLI commands
if (this.options.noPrompt) {
this.props = _pick(this.options, [
"assistantName",
"assistantDesc",
"assistantGenerationPath"
]);

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

this.props.finalConfirmation = true;
return;
}

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

writing() {

}

end() {

}
}
Empty file.
Loading

0 comments on commit f104cfe

Please sign in to comment.