office-addin-dev-settings
Version:
Configure developer settings for Office Add-ins.
88 lines • 4.35 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerWithTeams = registerWithTeams;
exports.updateM365Account = updateM365Account;
exports.uninstallWithTeams = uninstallWithTeams;
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 -p @microsoft/m365agentstoolkit-cli atk 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`));
}
});
});
}
function updateM365Account(operation) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const authCommand = `npx -p @microsoft/m365agentstoolkit-cli atk 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();
}
});
});
});
}
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(`^.+_(${guidRegex.source})$`);
let uninstallId = id;
if (!manifestIdRegex.test(id)) {
const match = id.match(titleIdRegex);
if (match) {
uninstallId = match[1];
}
else {
console.error(`Error: Invalid id "${id}". Add-in is still installed.`);
resolve(false);
return;
}
}
const uninstallCommand = `npx -p @microsoft/m365agentstoolkit-cli atk uninstall --mode manifest-id --manifest-id ${uninstallId} --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);
}
});
});
});
}
//# sourceMappingURL=publish.js.map