msbot
Version:
MSBot command line tool for manipulating Microsoft Bot Framework .bot files
77 lines • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Copyright(c) Microsoft Corporation.All rights reserved.
* Licensed under the MIT License.
*/
// tslint:disable:no-console
// tslint:disable:no-object-literal-type-assertion
const botframework_config_1 = require("botframework-config");
const chalk = require("chalk");
const program = require("commander");
const path = require("path");
const stdioAsync_1 = require("./stdioAsync");
program.Command.prototype.unknownOption = (flag) => {
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
showErrorHelp();
};
program
.name('msbot connect file')
.description('Connect a file to the bot')
.option('-n, --name <name>', 'name of the file service')
.option('-f, --file <file>', 'path to file to connect to')
.option('-p, --path <path>', 'path to file to connect to')
.option('-b, --bot <bot>', 'path to bot file. If omitted, local folder will look for a .bot file')
.option('--secret <secret>', 'bot file secret password for encrypting service secrets')
.option('--prefix', 'Append [msbot] prefix to all messages')
.action((filePath, actions) => {
if (filePath) {
actions.filePath = filePath;
}
});
const command = program.parse(process.argv);
const args = {};
Object.assign(args, command);
if (process.argv.length < 3) {
program.help();
}
else {
if (!args.bot) {
botframework_config_1.BotConfiguration.loadBotFromFolder(process.cwd(), args.secret)
.then(processConnectFile)
.catch((reason) => {
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
showErrorHelp();
});
}
else {
botframework_config_1.BotConfiguration.load(args.bot, args.secret)
.then(processConnectFile)
.catch((reason) => {
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
showErrorHelp();
});
}
}
async function processConnectFile(config) {
if (!args.path && !args.file) {
throw new Error('missing --file');
}
// add the service
const newService = new botframework_config_1.FileService({
name: path.basename(args.file || args.path),
path: (args.file || args.path).replace('\\', '/')
});
const id = config.connectService(newService);
await config.save(args.secret);
await stdioAsync_1.stdoutAsync(JSON.stringify(config.findService(id), null, 2));
return config;
}
function showErrorHelp() {
program.outputHelp((str) => {
console.error(str);
return '';
});
process.exit(1);
}
//# sourceMappingURL=msbot-connect-file.js.map