89 lines
4.3 KiB
JavaScript
89 lines
4.3 KiB
JavaScript
"use strict";
|
|
// 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 child_process_1 = tslib_1.__importDefault(require("child_process"));
|
|
const fs_1 = tslib_1.__importDefault(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_1.default.existsSync(filePath)) {
|
|
const pathSwitch = filePath.endsWith(".zip") ? "--file-path" : "--xml-path";
|
|
const sideloadCommand = `npx @microsoft/teamsapp-cli install ${pathSwitch} "${filePath}" --interactive false`;
|
|
console.log(`running: ${sideloadCommand}`);
|
|
child_process_1.default.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}`);
|
|
child_process_1.default.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) => {
|
|
const guidRegex = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/;
|
|
const manifestIdRegex = new RegExp(`^${guidRegex.source}$`);
|
|
const titleIdRegex = new RegExp(`^U_${guidRegex.source}$`);
|
|
let mode = "";
|
|
if (titleIdRegex.test(id)) {
|
|
mode = `--mode title-id --title-id ${id}`;
|
|
}
|
|
else if (manifestIdRegex.test(id)) {
|
|
mode = `--mode manifest-id --manifest-id ${id}`;
|
|
}
|
|
else {
|
|
console.error(`Error: Invalid id "${id}". Add-in is still installed.`);
|
|
resolve(false);
|
|
return;
|
|
}
|
|
const uninstallCommand = `npx @microsoft/teamsapp-cli uninstall ${mode} --interactive false`;
|
|
console.log(`running: ${uninstallCommand}`);
|
|
child_process_1.default.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(true);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|
|
exports.uninstallWithTeams = uninstallWithTeams;
|
|
//# sourceMappingURL=publish.js.map
|