// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. Object.defineProperty(exports, "__esModule", { value: true }); exports.uninstallWithTeams = exports.updateM365Account = exports.registerWithTeams = void 0; const tslib_1 = require("tslib"); const childProcess = require("child_process"); const fs = require("fs"); function registerWithTeams(filePath) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { if ((filePath.endsWith(".zip") || filePath.endsWith(".xml")) && fs.existsSync(filePath)) { const pathSwitch = filePath.endsWith(".zip") ? "--file-path" : "--xml-path"; const sideloadCommand = `npx @microsoft/teamsapp-cli install ${pathSwitch} "${filePath}"`; console.log(`running: ${sideloadCommand}`); childProcess.exec(sideloadCommand, (error, stdout, stderr) => { let titleIdMatch = stdout.match(/TitleId:\s*(.*)/); let titleId = titleIdMatch !== null ? titleIdMatch[1] : "??"; if (error || stderr.match('"error"')) { console.log(`\n${stdout}\n--Error sideloading!--\nError: ${error}\nSTDERR:\n${stderr}`); reject(error); } else { console.log(`\n${stdout}\nSuccessfully registered package! (${titleId})\n STDERR: ${stderr}\n`); resolve(titleId); } }); } else { reject(new Error(`The file '${filePath}' is not valid`)); } }); }); } exports.registerWithTeams = registerWithTeams; function updateM365Account(operation) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { const authCommand = `npx @microsoft/teamsapp-cli auth ${operation} m365`; console.log(`running: ${authCommand}`); childProcess.exec(authCommand, (error, stdout, stderr) => { if (error || (stderr.length > 0 && /Debugger attached\./.test(stderr) == false)) { console.log(`Error running auth command\n STDOUT: ${stdout}\n ERROR: ${error}\n STDERR: ${stderr}`); reject(error); } else { console.log(`Successfully ran auth command.\n`); resolve(); } }); }); }); } exports.updateM365Account = updateM365Account; function uninstallWithTeams(id) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { if (id.startsWith("U_")) { const uninstallCommand = `npx @microsoft/teamsapp-cli uninstall "--title-id" ${id}`; console.log(`running: ${uninstallCommand}`); childProcess.exec(uninstallCommand, (error, stdout, stderr) => { if (error || stderr.match('"error"')) { console.log(`\n${stdout}\n--Error uninstalling!--\n${error}\n STDERR: ${stderr}`); reject(error); } else { console.log(`\n${stdout}\nSuccessfully uninstalled!\n STDERR: ${stderr}\n`); resolve(); } }); } else { console.error(`Error: Invalid title id \"${id}\". Add-in is still installed.`); resolve(); } }); }); } exports.uninstallWithTeams = uninstallWithTeams; //# sourceMappingURL=publish.js.map