Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [#3997] Move Javascript generators from Samples to "generators" - Echo Bot #4011

Merged
merged 4 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions generators/generator-botbuilder/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Microsoft Corporation

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.
289 changes: 289 additions & 0 deletions generators/generator-botbuilder/README.md

Large diffs are not rendered by default.

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

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

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

/**
* Create the folder for the generated bot code, if it doesn't exist
*
* @param {Generator} generator Yeoman's generator object
* @param {String} directoryName root folder for the generated code
*/
const makeProjectDirectory = (generator, directoryName) => {
generator.log(path.basename(generator.destinationPath()));
generator.log(directoryName);
if (path.basename(generator.destinationPath()) !== directoryName) {
generator.log(`Your bot should be in a directory named ${directoryName}\nI'll automatically create this folder.`);
mkdirp.sync(directoryName);
generator.destinationRoot(generator.destinationPath(directoryName));
}
}

/**
* Based on the template, write the files common across the given template options
*
* @param {Generator} generator Yeoman's generator object
* @param {String} templatePath file path to write the generated code
*/
// const writeCommonFiles = (generator, templatePath) => {
module.exports.commonFilesWriter = (generator, templatePath) => {
const extension = _.toLower(generator.templateConfig.language) === 'javascript' ? 'js' : 'ts';
const npmMain = extension === 'js' ? `index.js` : `./lib/index.js`;


// ensure our project directory exists before we start writing files into it
makeProjectDirectory(generator, _.kebabCase(generator.templateConfig.botname));

// write the project files common to all templates
// do any text token processing where required
// NOTE: core bot with tests overwrites this file to add a npm test script command
generator.fs.copyTpl(
generator.templatePath(path.join(templatePath, 'package.json.' + extension)),
generator.destinationPath('package.json'),
{
botname: generator.templateConfig.botname,
botDescription: generator.templateConfig.description,
version: pkg.version,
npmMain: npmMain
}
);
generator.fs.copy(
generator.templatePath(path.join(templatePath, '_gitignore')),
generator.destinationPath('.gitignore')
);

// gen a .env file that points to the botfile
generator.fs.copyTpl(
generator.templatePath(path.join(templatePath, '_env')),
generator.destinationPath('.env'),
{
botFileName: generator.templateConfig.botname
}
);

// determine what language we are working in, TypeScript or JavaScript
// and write language specific files now
if (extension === 'ts') {
generator.fs.copy(
generator.templatePath(path.join(templatePath, 'tsconfig.json')),
generator.destinationPath('tsconfig.json')
);
generator.fs.copy(
generator.templatePath(path.join(templatePath, 'tslint.json')),
generator.destinationPath('tslint.json')
);
srcReadmePath = path.join(templatePath, 'README.md.ts')
} else {
generator.fs.copy(
generator.templatePath(path.join(templatePath, '_eslintrc.js')),
generator.destinationPath('.eslintrc.js')
);
srcReadmePath = path.join(templatePath, 'README.md.js')
}

// gen a readme with specifics to what was generated
generator.fs.copyTpl(
generator.templatePath(srcReadmePath),
generator.destinationPath('README.md'),
{
botname: generator.templateConfig.botname,
description: generator.templateConfig.description
}
);

// gen the deployment/Templates folder
const deploymentFolder = 'deploymentTemplates';
const deploymentFiles = [
'template-with-new-rg.json',
'template-with-preexisting-rg.json',
'new-rg-parameters.json',
'preexisting-rg-parameters.json',
];
mkdirp.sync(deploymentFolder);
const sourcePath = path.join(templatePath, deploymentFolder);
const destinationPath = path.join(generator.destinationPath(), deploymentFolder);
for(let cnt = 0; cnt < deploymentFiles.length; ++cnt) {
generator.fs.copy(
path.join(sourcePath, deploymentFiles[cnt]),
path.join(destinationPath, deploymentFiles[cnt]),
);
}
}
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 = 'Core 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-core';

// --noprompt template values
module.exports.BOT_TEMPLATE_NOPROMPT_EMPTY = 'empty';
module.exports.BOT_TEMPLATE_NOPROMPT_SIMPLE = 'echo';
module.exports.BOT_TEMPLATE_NOPROMPT_CORE = 'core';

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


Loading