UNPKG

teamsfx-extension

Version:

Create, debug, and deploy Teams apps with Teams Toolkit

191 lines 11.1 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. 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.TeamsfxTaskProvider = void 0; const vscode = require("vscode"); const constants = require("./constants"); const commonUtils = require("./commonUtils"); const teamsfx_api_1 = require("@microsoft/teamsfx-api"); const dotnetChecker_1 = require("./depsChecker/dotnetChecker"); const handlers_1 = require("../handlers"); const vscodeAdapter_1 = require("./depsChecker/vscodeAdapter"); const vscodeLogger_1 = require("./depsChecker/vscodeLogger"); const vscodeTelemetry_1 = require("./depsChecker/vscodeTelemetry"); class TeamsfxTaskProvider { provideTasks(token) { return __awaiter(this, void 0, void 0, function* () { const tasks = []; if (vscode.workspace.workspaceFolders) { const workspaceFolder = vscode.workspace.workspaceFolders[0]; const workspacePath = workspaceFolder.uri.fsPath; if (!(yield commonUtils.isFxProject(workspacePath))) { return tasks; } const programmingLanguage = yield commonUtils.getProgrammingLanguage(); // Always provide the following tasks no matter whether it is defined in tasks.json const frontendRoot = yield commonUtils.getProjectRoot(workspacePath, constants.frontendFolderName); if (frontendRoot) { tasks.push(yield this.createFrontendStartTask(workspaceFolder, frontendRoot)); } const backendRoot = yield commonUtils.getProjectRoot(workspacePath, constants.backendFolderName); if (backendRoot) { tasks.push(yield this.createBackendStartTask(workspaceFolder, backendRoot, programmingLanguage)); if (programmingLanguage === constants.ProgrammingLanguage.typescript) { tasks.push(yield this.createBackendWatchTask(workspaceFolder, backendRoot)); } } const authRoot = yield commonUtils.getAuthServicePath(); if (authRoot) { tasks.push(yield this.createAuthStartTask(workspaceFolder, authRoot)); } const botRoot = yield commonUtils.getProjectRoot(workspacePath, constants.botFolderName); if (botRoot) { tasks.push(yield this.createNgrokStartTask(workspaceFolder, botRoot)); const silent = frontendRoot !== undefined; tasks.push(yield this.createBotStartTask(workspaceFolder, botRoot, programmingLanguage, silent)); } const vscodeEnv = handlers_1.detectVsCodeEnv(); const isCodeSpaceEnv = vscodeEnv === teamsfx_api_1.VsCodeEnv.codespaceBrowser || vscodeEnv === teamsfx_api_1.VsCodeEnv.codespaceVsCode; if (isCodeSpaceEnv) { tasks.push(yield this.createOpenTeamsWebClientTask(workspaceFolder)); } } return tasks; }); } resolveTask(task, token) { return __awaiter(this, void 0, void 0, function* () { // Return undefined since all tasks are provided and fully resolved return undefined; }); } createFrontendStartTask(workspaceFolder, projectRoot, definition, problemMatchers) { return __awaiter(this, void 0, void 0, function* () { const command = constants.frontendStartCommand; definition = definition || { type: TeamsfxTaskProvider.type, command }; const commandLine = "npx react-scripts start"; const env = yield commonUtils.getFrontendLocalEnv(); const options = { cwd: projectRoot, env, }; problemMatchers = problemMatchers || constants.frontendProblemMatcher; const task = new vscode.Task(definition, workspaceFolder, command, TeamsfxTaskProvider.type, new vscode.ShellExecution(commandLine, options), problemMatchers); task.isBackground = true; return task; }); } createBackendStartTask(workspaceFolder, projectRoot, programmingLanguage, definition, problemMatchers) { return __awaiter(this, void 0, void 0, function* () { const command = constants.backendStartCommand; definition = definition || { type: TeamsfxTaskProvider.type, command }; // NOTE: properly handle quoting and escaping to work on windows (both powershell and cmd), linux and osx const commandLine = programmingLanguage === constants.ProgrammingLanguage.typescript ? 'npx func start --typescript --language-worker="--inspect=9229" --port "7071" --cors "*"' : 'npx func start --javascript --language-worker="--inspect=9229" --port "7071" --cors "*"'; const env = yield commonUtils.getBackendLocalEnv(); const options = { cwd: projectRoot, env, }; problemMatchers = problemMatchers || constants.backendProblemMatcher; const task = new vscode.Task(definition, workspaceFolder, command, TeamsfxTaskProvider.type, new vscode.ShellExecution(commandLine, options), problemMatchers); task.isBackground = true; task.presentationOptions.reveal = vscode.TaskRevealKind.Silent; return task; }); } createAuthStartTask(workspaceFolder, projectRoot, definition) { return __awaiter(this, void 0, void 0, function* () { const command = constants.authStartCommand; definition = definition || { type: TeamsfxTaskProvider.type, command }; const dotnetChecker = new dotnetChecker_1.DotnetChecker(vscodeAdapter_1.vscodeAdapter, vscodeLogger_1.vscodeLogger, vscodeTelemetry_1.vscodeTelemetry); const dotnetPath = yield dotnetChecker.getDotnetExecPath(); const env = yield commonUtils.getAuthLocalEnv(); const options = { cwd: projectRoot, env, }; const task = new vscode.Task(definition, workspaceFolder, command, TeamsfxTaskProvider.type, new vscode.ProcessExecution(dotnetPath, ["Microsoft.TeamsFx.SimpleAuth.dll"], options), constants.authProblemMatcher); task.isBackground = true; task.presentationOptions.reveal = vscode.TaskRevealKind.Silent; return task; }); } createNgrokStartTask(workspaceFolder, projectRoot, definition) { return __awaiter(this, void 0, void 0, function* () { const command = constants.ngrokStartCommand; definition = definition || { type: TeamsfxTaskProvider.type, command }; let commandLine = "npx ngrok http 3978 --log=stdout"; const skipNgrokConfig = yield commonUtils.getSkipNgrokConfig(); const skipNgrok = skipNgrokConfig && skipNgrokConfig.trim().toLocaleLowerCase() === "true"; if (skipNgrok) { commandLine = "echo 'Do not start ngrok, but use predefined bot endpoint.'"; } const options = { cwd: projectRoot, }; const task = new vscode.Task(definition, workspaceFolder, command, TeamsfxTaskProvider.type, new vscode.ShellExecution(commandLine, options), constants.ngrokProblemMatcher); task.isBackground = !skipNgrok; return task; }); } createBotStartTask(workspaceFolder, projectRoot, programmingLanguage, silent, definition) { return __awaiter(this, void 0, void 0, function* () { const command = constants.botStartCommand; definition = definition || { type: TeamsfxTaskProvider.type, command }; // TODO: tell nodemon which files to watch (depends on bot's decision) const commandLine = programmingLanguage === constants.ProgrammingLanguage.typescript ? "npx nodemon --exec node --inspect=9239 --signal SIGINT -r ts-node/register index.ts" : "npx nodemon --inspect=9239 --signal SIGINT index.js"; const env = yield commonUtils.getBotLocalEnv(); const options = { cwd: projectRoot, env, }; const task = new vscode.Task(definition, workspaceFolder, command, TeamsfxTaskProvider.type, new vscode.ShellExecution(commandLine, options), constants.botProblemMatcher); task.isBackground = true; if (silent) { task.presentationOptions.reveal = vscode.TaskRevealKind.Silent; } return task; }); } createOpenTeamsWebClientTask(workspaceFolder, definition) { return __awaiter(this, void 0, void 0, function* () { const command = constants.openWenClientCommand; definition = definition || { type: TeamsfxTaskProvider.type, command }; const localTeamsAppId = yield commonUtils.getLocalDebugTeamsAppId(true); const commandLine = `npx open-cli https://teams.microsoft.com/_#/l/app/${localTeamsAppId}?installAppPackage=true`; const task = new vscode.Task(definition, workspaceFolder, command, TeamsfxTaskProvider.type, new vscode.ShellExecution(commandLine)); return task; }); } createBackendWatchTask(workspaceFolder, projectRoot, definition) { return __awaiter(this, void 0, void 0, function* () { const command = constants.backendWatchCommand; definition = definition || { type: TeamsfxTaskProvider.type, command }; const commandLine = "npx tsc --watch"; // TODO: tell tsc which files to watch (depends on function's decision) const options = { cwd: projectRoot, }; const task = new vscode.Task(definition, workspaceFolder, command, TeamsfxTaskProvider.type, new vscode.ShellExecution(commandLine, options), constants.tscWatchProblemMatcher); task.isBackground = true; task.presentationOptions.reveal = vscode.TaskRevealKind.Silent; return task; }); } } exports.TeamsfxTaskProvider = TeamsfxTaskProvider; TeamsfxTaskProvider.type = teamsfx_api_1.ProductName; //# sourceMappingURL=teamsfxTaskProvider.js.map