UNPKG

ask-cli

Version:

Alexa Skills Kit (ASK) Command Line Interfaces

59 lines (58 loc) 2.62 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PythonRunFlow = void 0; const child_process_1 = require("child_process"); const path_1 = require("path"); const fs_1 = require("fs"); const constants_1 = require("../../../utils/constants"); const cli_error_1 = __importDefault(require("../../../exceptions/cli-error")); const abstract_run_flow_1 = require("./abstract-run-flow"); class PythonRunFlow extends abstract_run_flow_1.AbstractRunFlow { static canHandle(runtime) { return runtime === constants_1.RUNTIME.PYTHON; } constructor({ skillInvocationInfo, waitForAttach, debugPort, token, skillId, runRegion, watch }) { const sitePkgLocationsStr = (0, child_process_1.execSync)('python3 -c "import site; import json; print(json.dumps(site.getsitepackages()))"') .toString(); const sitePkgLocations = JSON.parse(sitePkgLocationsStr); const localDebuggerPath = sitePkgLocations .map((location) => (0, path_1.join)(location, constants_1.RUN.PYTHON.SCRIPT_LOCATION)) .find((location) => (0, fs_1.existsSync)(location)); if (!(0, fs_1.existsSync)(localDebuggerPath)) { throw new cli_error_1.default("ask-sdk-local-debug cannot be found. Please install ask-sdk-local-debug to your skill code project. " + "Refer https://pypi.org/project/ask-sdk-local-debug, for more info."); } if (waitForAttach) { (0, child_process_1.execSync)("python3 -m pip install debugpy", { stdio: "inherit" }); } const execMap = waitForAttach ? { py: `python3 -m debugpy --listen ${debugPort} --wait-for-client`, } : { py: "python3", }; super({ execMap, script: localDebuggerPath, args: [ "--accessToken", `"${token}"`, "--skillId", skillId, "--skillHandler", skillInvocationInfo.handlerName, "--skillFilePath", (0, path_1.join)(`${skillInvocationInfo.skillCodeFolderName}`, `${skillInvocationInfo.skillFileName}.py`), "--region", runRegion, ], ext: "py,json,txt", watch: watch ? `${skillInvocationInfo.skillCodeFolderName}` : watch, }); } } exports.PythonRunFlow = PythonRunFlow;