UNPKG

teamsfx-extension

Version:

Create, debug, and deploy Teams apps with Teams Toolkit

78 lines 3.6 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isNonEmptyDir = exports.createTmpDir = exports.setExecutionPolicyForCurrentUser = exports.getExecutionPolicyForCurrentUser = exports.assertPathEqual = exports.commandExistsInPath = void 0; const chai = require("chai"); const fs = require("fs-extra"); const cpUtils_1 = require("../../../../src/debug/depsChecker/cpUtils"); const common_1 = require("../../../../src/debug/depsChecker/common"); const testLogger_1 = require("../adapters/testLogger"); const tmp = require("tmp"); function commandExistsInPath(command) { return __awaiter(this, void 0, void 0, function* () { try { if (common_1.isWindows()) { yield cpUtils_1.cpUtils.executeCommand(undefined, testLogger_1.logger, { shell: "cmd.exe" }, "where", command); } else { yield cpUtils_1.cpUtils.executeCommand(undefined, testLogger_1.logger, { shell: "/bin/bash" }, "type", "-P", command); } return true; } catch (error) { return false; } }); } exports.commandExistsInPath = commandExistsInPath; function assertPathEqual(actual, expected) { chai.assert.equal(fs.realpathSync(actual), fs.realpathSync(expected)); } exports.assertPathEqual = assertPathEqual; function getExecutionPolicyForCurrentUser() { return __awaiter(this, void 0, void 0, function* () { const policy = yield cpUtils_1.cpUtils.executeCommand(undefined, testLogger_1.logger, undefined, "powershell.exe", "-Command", "Get-ExecutionPolicy", "-Scope", "CurrentUser"); return policy.trim(); }); } exports.getExecutionPolicyForCurrentUser = getExecutionPolicyForCurrentUser; function setExecutionPolicyForCurrentUser(policy) { return __awaiter(this, void 0, void 0, function* () { yield cpUtils_1.cpUtils.executeCommand(undefined, testLogger_1.logger, undefined, "powershell.exe", "-Command", "Set-ExecutionPolicy", "-Scope", "CurrentUser", policy); }); } exports.setExecutionPolicyForCurrentUser = setExecutionPolicyForCurrentUser; function createTmpDir() { return new Promise((resolve, reject) => { // unsafeCleanup: recursively removes the created temporary directory, even when it's not empty. tmp.dir({ unsafeCleanup: true }, function (err, path, cleanupCallback) { if (err) { reject(err); return; } resolve([path, cleanupCallback]); }); }); } exports.createTmpDir = createTmpDir; function isNonEmptyDir(dir) { return __awaiter(this, void 0, void 0, function* () { try { const files = yield fs.readdir(dir); return files.length !== 0; } catch (error) { return false; } }); } exports.isNonEmptyDir = isNonEmptyDir; //# sourceMappingURL=common.js.map