ask-cli
Version:
Alexa Skills Kit (ASK) Command Line Interfaces
81 lines (80 loc) • 4.15 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSkillFlowInstance = exports.selectRunFlowClass = exports.getNormalisedRuntime = exports.getSkillCodeFolderName = exports.getNonHostedSkillInvocationInfo = exports.getHostedSkillInvocationInfo = void 0;
const fs_1 = require("fs");
const resources_config_1 = require("../../model/resources-config");
const constants_1 = require("../../utils/constants");
const string_utils_1 = require("../../utils/string-utils");
const cli_error_1 = __importDefault(require("../../exceptions/cli-error"));
const nodejs_run_1 = require("./run-flow/nodejs-run");
const python_run_1 = require("./run-flow/python-run");
const java_run_1 = require("./run-flow/java-run");
const RUN_FLOWS = [java_run_1.JavaRunFlow, nodejs_run_1.NodejsRunFlow, python_run_1.PythonRunFlow];
function getHostedSkillInvocationInfo(runtime) {
const invocationInfo = constants_1.HOSTED_SKILL.RUN.INVOCATION_INFO;
return invocationInfo[runtime];
}
exports.getHostedSkillInvocationInfo = getHostedSkillInvocationInfo;
function getNonHostedSkillInvocationInfo(runtime, handler, skillCodeFolderName) {
if (!(0, string_utils_1.isNonBlankString)(runtime)) {
throw new cli_error_1.default(`Missing runtime info in resource file ${constants_1.FILE_PATH.ASK_RESOURCES_JSON_CONFIG}.`);
}
if (!(0, string_utils_1.isNonBlankString)(handler)) {
throw new cli_error_1.default(`Missing handler info in resource file ${constants_1.FILE_PATH.ASK_RESOURCES_JSON_CONFIG}.`);
}
if (runtime === constants_1.RUNTIME.JAVA) {
return { handlerName: handler, skillCodeFolderName };
}
const handlerInfo = handler.split(".");
const handlerName = handlerInfo.pop();
const skillFileName = handlerInfo.pop();
return { handlerName, skillFileName, skillCodeFolderName };
}
exports.getNonHostedSkillInvocationInfo = getNonHostedSkillInvocationInfo;
function getSkillCodeFolderName(profile, skillCodeRegion) {
const userRegionSkillCodeFolderName = (0, resources_config_1.getInstance)().getCodeSrcByRegion(profile, skillCodeRegion);
const skillCodeFolderName = !(0, string_utils_1.isNonBlankString)(userRegionSkillCodeFolderName) && userRegionSkillCodeFolderName !== constants_1.ALEXA.REGION.DEFAULT
? (0, resources_config_1.getInstance)().getCodeSrcByRegion(profile, constants_1.ALEXA.REGION.DEFAULT)
: userRegionSkillCodeFolderName;
if (!(0, string_utils_1.isNonBlankString)(skillCodeFolderName)) {
throw new cli_error_1.default(`Invalid code setting in region ${skillCodeRegion}. "src" must be set if you want to run the skill code with skill package.`);
}
if (!(0, fs_1.existsSync)(skillCodeFolderName)) {
throw new cli_error_1.default(`Invalid code setting in region ${skillCodeRegion}. File doesn't exist for code src: ${skillCodeFolderName}.`);
}
return skillCodeFolderName;
}
exports.getSkillCodeFolderName = getSkillCodeFolderName;
function getNormalisedRuntime(runtime) {
if (runtime.includes(constants_1.RUNTIME.NODE)) {
return constants_1.RUNTIME.NODE;
}
if (runtime.includes(constants_1.RUNTIME.PYTHON)) {
return constants_1.RUNTIME.PYTHON;
}
if (runtime.includes(constants_1.RUNTIME.JAVA)) {
return constants_1.RUNTIME.JAVA;
}
throw new cli_error_1.default(`Runtime - ${runtime} is not supported.`);
}
exports.getNormalisedRuntime = getNormalisedRuntime;
function selectRunFlowClass(runtime) {
return RUN_FLOWS.find((flow) => flow.canHandle(runtime));
}
exports.selectRunFlowClass = selectRunFlowClass;
function getSkillFlowInstance(runtime, skillInvocationInfo, waitForAttach, debugPort, token, skillId, runRegion, watch) {
const RunFlow = selectRunFlowClass(runtime);
return new RunFlow({
skillInvocationInfo,
waitForAttach,
debugPort,
token,
skillId,
runRegion,
watch,
});
}
exports.getSkillFlowInstance = getSkillFlowInstance;