Skip to content

Commit

Permalink
yeoman cse work (#962)
Browse files Browse the repository at this point in the history
* frame out Empty bot, add placeholder names for other templates

- added JS/TS empty bot template
- added placeholder names for echo and basic
- cleaned up generated package.json files
- renamed markdown files to be CAPITAL.md cased
- switched TS/JS bot name validation to force kabob casing

* update template writers to use name constants

- using new consts for template options in order to account for any name changes that may come.  e.g.  basic template to core template, etc.

* Simply  and cleanup echo JS and TS

- remove state
- add eslint and tslint support
- fix eslint and tslint errors and warnings in generated code
- refine generated README.md files
- rename —botName flag to be all lowercase —botname
- added empty bot template option
- start on csharp templates

* Another round of CSE feedback

- remove C# support, all up
- update tsconfig.json for TypeScript generated templates
- update gitignore to ignore lib folder
- update restify dependency to latest version
- added testGen.cmd file that generates, builds, and lints all samples, all languages
- number of code consistency issues
- have TypeScript generated templates use TypeScript and tslint as devDependencies
- update README.md files for TypeScript generated templates to remove TypeScript and tslint as prereqs
- fix race condition using concurrently for npm TypeScript scripts
- bump the patch version

* botName property was renamed to botname

- missed this one when I did the rename

* rework README.md

- turn the crank on the README.md
- add a description to noprompt cli option
- bump the minor version number
- remove unused constants
  • Loading branch information
sgellock authored Nov 25, 2018
1 parent 0753f01 commit 2a17984
Show file tree
Hide file tree
Showing 63 changed files with 2,179 additions and 1,423 deletions.
File renamed without changes.
File renamed without changes.
183 changes: 109 additions & 74 deletions generators/generator-botbuilder/README.md

Large diffs are not rendered by default.

49 changes: 27 additions & 22 deletions generators/generator-botbuilder/components/basicTemplateWriter.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const path = require("path");
const _ = require("lodash");
const mkdirp = require("mkdirp");
const _ = require('lodash');
const mkdirp = require('mkdirp');
const path = require('path');

const { commonFilesWriter } = require('./commonFilesWriter');
const { BOT_TEMPLATE_NAME_CORE, BOT_TEMPLATE_NOPROMPT_CORE } = require('./constants');

const TEMPLATE_NAME = "basic";
const TEMPLATE_PATH = "/basic/";
// generators/app/templates folder name
const GENERATOR_TEMPLATE_NAME = 'basic';

const LANG_JS = "javascript";
const LANG_TS = "typescript";
const LANG_JS = 'javascript';
const LANG_TS = 'typescript';

/**
*
* @param {String} language either "javascript" or "typescript"
* @param {String} language either 'javascript' or 'typescript'
*/
const getFolders = language => {
if(!language || (_.toLower(language) !== LANG_JS && _.toLower(language) !== LANG_TS)) {
throw new Error(`basicTemplateWriter.getFolders called for invalid language: ${language}`);
throw new Error(`basicTemplateWriter.getFolders called for invalid language: ${ language }`);
}

let folders;
Expand Down Expand Up @@ -61,7 +62,7 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
const DIALOGS_GREETING_RESOURCES = 4;
const DIALOGS_WELCOME = 5;
const DIALOGS_WELCOME_RESOURCES = 6;
const TS_SRC_FOLDER = "src/";
const TS_SRC_FOLDER = 'src/';

// get the folder strucure, based on language
const srcFolders = [
Expand All @@ -75,8 +76,11 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
];
const destFolders = getFolders(_.toLower(gen.props.language));

const extension = _.toLower(gen.props.language) === "javascript" ? "js" : "ts";
const SRC_FOLDER = _.toLower(gen.props.language) === "javascript" ? "" : TS_SRC_FOLDER;
const extension = _.toLower(gen.props.language) === 'javascript' ? 'js' : 'ts';
const SRC_FOLDER = _.toLower(gen.props.language) === 'javascript' ? '' : TS_SRC_FOLDER;
// if we're generating JS, then keep the json extension
// if we're generating TS, then we need the extension to be js or tsc will complain (tsc v3.1.6)
const cardExtension = _.toLower(gen.props.language) === 'javascript' ? 'json' : 'js';

// create the basic bot folder structure
for (let cnt = 0; cnt < destFolders.length; ++cnt) {
Expand All @@ -99,8 +103,8 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
path.join(destinationPath, 'DEPLOYMENT.md'),
{
process: function (content) {
var pattern = new RegExp('<%= botName %>', 'g');
return content.toString().replace(pattern, gen.props.botName.toString());
var pattern = new RegExp('<%= botname %>', 'g');
return content.toString().replace(pattern, gen.props.botname.toString());
}
});

Expand All @@ -115,7 +119,7 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
path.join(sourcePath, 'bot.recipe'),
path.join(destinationPath, 'bot.recipe'),
{
botName: gen.props.botName
botname: gen.props.botname
}
);

Expand All @@ -126,7 +130,7 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
path.join(sourcePath, `greeting.${extension}`),
path.join(destinationPath, `greeting.${extension}`),
{
botName: gen.props.botName
botname: gen.props.botname
}
);

Expand Down Expand Up @@ -170,7 +174,7 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
destinationPath = path.join(gen.destinationPath(), destFolders[DIALOGS_WELCOME_RESOURCES]);
gen.fs.copy(
path.join(sourcePath, 'welcomeCard.json'),
path.join(destinationPath, 'welcomeCard.json')
path.join(destinationPath, `welcomeCard.${ cardExtension }`)
);

// write out the index.js and bot.js
Expand All @@ -181,7 +185,7 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
gen.templatePath(path.join(templatePath, `index.${extension}`)),
path.join(destinationPath, `index.${extension}`),
{
botName: gen.props.botName
botname: gen.props.botname
}
);

Expand All @@ -190,7 +194,7 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
gen.templatePath(path.join(templatePath, `bot.${extension}`)),
path.join(destinationPath, `bot.${extension}`),
{
botName: gen.props.botName
botname: gen.props.botname
}
);
}
Expand All @@ -203,10 +207,11 @@ const writeBasicTemplateFiles = (gen, templatePath) => {
module.exports.basicTemplateWriter = gen => {
// do some simple sanity checking to ensure we're being
// called correctly
if (_.toLower(gen.props.template) !== TEMPLATE_NAME) {
throw new Error(`basicTemplateWriter called for wrong template: ${gen.props.template}`);
const template = _.toLower(gen.props.template)
if (template !== _.toLower(BOT_TEMPLATE_NAME_CORE) && template !== _.toLower(BOT_TEMPLATE_NOPROMPT_CORE)) {
throw new Error(`basicTemplateWriter called for wrong template: ${ gen.props.template }`);
}
const templatePath = path.join(gen.templatePath(), TEMPLATE_PATH);
const templatePath = path.join(gen.templatePath(), GENERATOR_TEMPLATE_NAME);

// write files common to all template options
commonFilesWriter(gen, templatePath);
Expand Down
43 changes: 24 additions & 19 deletions generators/generator-botbuilder/components/commonFilesWriter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const path = require("path");
const _ = require("lodash");
const mkdirp = require("mkdirp");
const path = require('path');
const _ = require('lodash');
const mkdirp = require('mkdirp');

const pkg = require('../package.json');

Expand Down Expand Up @@ -31,23 +31,24 @@ const makeProjectDirectory = (gen, directoryName) => {
*/
// const writeCommonFiles = (gen, templatePath) => {
module.exports.commonFilesWriter = (gen, templatePath) => {
const botName = gen.props.botName;
const extension = _.toLower(gen.props.language) === "javascript" ? "js" : "ts";
const botname = gen.props.botname;
const extension = _.toLower(gen.props.language) === 'javascript' ? 'js' : 'ts';
const npmMain = extension === 'js' ? `index.js` : `./lib/index.js`;
const npmBuildCmd = extension === 'js' ? `exit 1` : `tsc`;
const npmRunCmd = extension === 'js' ? `node ./index.js` : "tsc && node ./lib/index.js";
const npmWatchCmd = extension === 'js' ? "nodemon ./index.js" : "tsc && node ./lib/index.js";
const npmRunCmd = extension === 'js' ? `node ./index.js` : 'tsc && node ./lib/index.js';
const npmWatchCmd = extension === 'js' ? 'nodemon ./index.js' : "concurrently --kill-others \"tsc -w\" \"nodemon ./lib/index.js\"";


// ensure our project directory exists before we start writing files into it
makeProjectDirectory(gen, _.camelCase(gen.props.botName));
makeProjectDirectory(gen, _.kebabCase(gen.props.botname));

// write the project files common to all templates
// do any text token processing where required
gen.fs.copyTpl(
gen.templatePath(path.join(templatePath, "package.json." + extension)),
gen.destinationPath("package.json"),
gen.templatePath(path.join(templatePath, 'package.json.' + extension)),
gen.destinationPath('package.json'),
{
botName: gen.props.botName,
botname: gen.props.botname,
botDescription: gen.props.description,
version: pkg.version,
npmMain: npmMain
Expand All @@ -60,10 +61,10 @@ module.exports.commonFilesWriter = (gen, templatePath) => {

gen.fs.copy(
gen.templatePath(path.join(templatePath, `botName.bot`)),
gen.destinationPath(`${gen.props.botName}.bot`), {
gen.destinationPath(`${gen.props.botname}.bot`), {
process: function (content) {
var pattern = new RegExp('<%= botName %>', 'g');
return content.toString().replace(pattern, botName.toString());
var pattern = new RegExp('<%= botname %>', 'g');
return content.toString().replace(pattern, botname.toString());
}
});

Expand All @@ -72,7 +73,7 @@ module.exports.commonFilesWriter = (gen, templatePath) => {
gen.templatePath(path.join(templatePath, '_env')),
gen.destinationPath('.env'),
{
botFileName: gen.props.botName
botFileName: gen.props.botname
}
);

Expand All @@ -83,21 +84,25 @@ module.exports.commonFilesWriter = (gen, templatePath) => {
gen.templatePath(path.join(templatePath, 'tsconfig.json')),
gen.destinationPath('tsconfig.json')
);
srcReadmePath = path.join(templatePath, "README.md.ts")
gen.fs.copy(
gen.templatePath(path.join(templatePath, 'tslint.json')),
gen.destinationPath('tslint.json')
);
srcReadmePath = path.join(templatePath, 'README.md.ts')
} else {
gen.fs.copy(
gen.templatePath(path.join(templatePath, '_eslintrc.js')),
gen.destinationPath('.eslintrc.js')
);
srcReadmePath = path.join(templatePath, "README.md.js")
srcReadmePath = path.join(templatePath, 'README.md.js')
}

// gen a readme with specifics to what was generated
gen.fs.copyTpl(
gen.templatePath(srcReadmePath),
gen.destinationPath("README.md"),
gen.destinationPath('README.md'),
{
botName: gen.props.botName,
botname: gen.props.botname,
description: gen.props.description,
runCmd: npmRunCmd,
watchCmd: npmWatchCmd,
Expand Down
23 changes: 23 additions & 0 deletions generators/generator-botbuilder/components/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// display names of the template options
module.exports.BOT_TEMPLATE_NAME_EMPTY = 'Empty Bot';
module.exports.BOT_TEMPLATE_NAME_SIMPLE = 'Echo Bot';
module.exports.BOT_TEMPLATE_NAME_CORE = 'Basic Bot';

// aka.ms links to documentation for each template option
module.exports.BOT_HELP_URL_EMPTY = 'https://aka.ms/bot-template-empty';
module.exports.BOT_HELP_URL_SIMPLE = 'https://aka.ms/bot-template-echo';
module.exports.BOT_HELP_URL_CORE = 'https://aka.ms/bot-template-basic';

// --noprompt template values
module.exports.BOT_TEMPLATE_NOPROMPT_EMPTY = 'Empty';
module.exports.BOT_TEMPLATE_NOPROMPT_SIMPLE = 'Echo';
module.exports.BOT_TEMPLATE_NOPROMPT_CORE = 'Basic';

// programming language name options
module.exports.BOT_LANG_NAME_JAVASCRIPT = 'JavaScript';
module.exports.BOT_LANG_NAME_TYPESCRIPT = 'TypeScript';


29 changes: 16 additions & 13 deletions generators/generator-botbuilder/components/echoTemplateWriter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const path = require("path");
const _ = require("lodash");
const mkdirp = require("mkdirp");
const path = require('path');
const _ = require('lodash');
const mkdirp = require('mkdirp');

const { commonFilesWriter } = require('./commonFilesWriter');
const { BOT_TEMPLATE_NAME_SIMPLE, BOT_TEMPLATE_NOPROMPT_SIMPLE } = require('./constants');

const TEMPLATE_NAME = "echo";
// generators/app/templates folder name
const GENERATOR_TEMPLATE_NAME = 'echo';

/**
* Write the files that are specific to the echo bot template
Expand All @@ -19,21 +21,21 @@ const writeEchoTemplateFiles = (gen, templatePath) => {
const DEPLOYMENT_SCRIPTS = 0;
const DEPLOYMENT_MSBOT = 1;
const RESOURCES = 2;
const TS_SRC_FOLDER = "src"
const TS_SRC_FOLDER = 'src'
const folders = [
'deploymentScripts',
path.join('deploymentScripts', 'msbotClone'),
'resources'
];
const extension = _.toLower(gen.props.language) === "javascript" ? "js" : "ts";
const srcFolder = _.toLower(gen.props.language) === "javascript" ? "" : TS_SRC_FOLDER;
const extension = _.toLower(gen.props.language) === 'javascript' ? 'js' : 'ts';
const srcFolder = _.toLower(gen.props.language) === 'javascript' ? '' : TS_SRC_FOLDER;

// create the echo bot folder structure common to both languages
for (let cnt = 0; cnt < folders.length; ++cnt) {
mkdirp.sync(folders[cnt]);
}
// create a src directory if we are generating TypeScript
if (_.toLower(gen.props.language) === "typescript") {
if (_.toLower(gen.props.language) === 'typescript') {
mkdirp.sync(TS_SRC_FOLDER);
}

Expand All @@ -44,7 +46,7 @@ const writeEchoTemplateFiles = (gen, templatePath) => {
path.join(sourcePath, 'bot.recipe'),
path.join(destinationPath, 'bot.recipe'),
{
botName: gen.props.botName
botname: gen.props.botname
}
);

Expand All @@ -56,7 +58,7 @@ const writeEchoTemplateFiles = (gen, templatePath) => {
gen.templatePath(path.join(templatePath, `index.${extension}`)),
path.join(destinationPath, `index.${extension}`),
{
botName: gen.props.botName
botname: gen.props.botname
}
);
// gen the main bot activity router
Expand All @@ -82,12 +84,13 @@ const writeEchoTemplateFiles = (gen, templatePath) => {
module.exports.echoTemplateWriter = gen => {
// do some simple sanity checking to ensure we're being
// called correctly
if (_.toLower(gen.props.template) !== TEMPLATE_NAME) {
throw new Error(`writeEchoProjectFiles called for wrong template: ${gen.props.template}`);
const template = _.toLower(gen.props.template)
if (template !== _.toLower(BOT_TEMPLATE_NAME_SIMPLE) && template !== _.toLower(BOT_TEMPLATE_NOPROMPT_SIMPLE)) {
throw new Error(`writeEchoProjectFiles called for wrong template: ${ gen.props.template }`);
}

// build the path to the echo template source folder
const templatePath = path.join(gen.templatePath(), TEMPLATE_NAME);
const templatePath = path.join(gen.templatePath(), GENERATOR_TEMPLATE_NAME);

// write files common to all our template options
commonFilesWriter(gen, templatePath);
Expand Down
Loading

0 comments on commit 2a17984

Please sign in to comment.