msbot
Version:
MSBot command line tool for manipulating Microsoft Bot Framework .bot files
69 lines • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Copyright(c) Microsoft Corporation.All rights reserved.
* Licensed under the MIT License.
*/
const chalk = require("chalk");
const program = require("commander");
const path = require("path");
const BotConfig_1 = require("./BotConfig");
const fileService_1 = require("./models/fileService");
program.Command.prototype.unknownOption = function (flag) {
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
showErrorHelp();
};
program
.name('msbot connect file <path>')
.description('Connect a file to the bot')
.option('-b, --bot <path>', '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')
.action((filePath, actions) => {
if (filePath)
actions.filePath = filePath;
});
let args = program.parse(process.argv);
if (process.argv.length < 3) {
program.help();
}
else {
if (!args.bot) {
BotConfig_1.BotConfig.LoadBotFromFolder(process.cwd(), args.secret)
.then(processConnectFile)
.catch((reason) => {
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
showErrorHelp();
});
}
else {
BotConfig_1.BotConfig.Load(args.bot, args.secret)
.then(processConnectFile)
.catch((reason) => {
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
showErrorHelp();
});
}
}
async function processConnectFile(config) {
args.name = args.hasOwnProperty('name') ? args.name : config.name;
if (!args.hasOwnProperty('filePath'))
throw new Error('Bad or missing file');
// add the service
let newService = new fileService_1.FileService({
id: args.filePath,
name: path.basename(args.filePath),
filePath: args.filePath
});
config.connectService(newService);
await config.save();
process.stdout.write(JSON.stringify(newService, null, 2));
return config;
}
function showErrorHelp() {
program.outputHelp((str) => {
console.error(str);
return '';
});
process.exit(1);
}
//# sourceMappingURL=msbot-connect-file.js.map