UNPKG

express-to-lambda

Version:

Simple package for converting your express application to an AWS Lambda.

39 lines (38 loc) 2.03 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.adapter = exports.convert = void 0; const addHandler_1 = require("./utils/addHandler"); const commentCode_1 = require("./utils/commentCode"); const findFilesWithString_1 = require("./utils/findFilesWithString"); const isFolder_1 = require("./utils/isFolder"); const regex_1 = require("./utils/regex"); const handler_1 = require("./utils/handler"); Object.defineProperty(exports, "adapter", { enumerable: true, get: function () { return handler_1.adapter; } }); function isCommonJs(targetDirectory) { return !(0, findFilesWithString_1.findFilesWithString)(targetDirectory, `"type": "module"`).at(0); } function getAppIndex(targetDirectory) { const appIndex = (0, findFilesWithString_1.findFilesWithString)(targetDirectory, "express()").at(0); if (!appIndex) { throw new Error("Express app not found"); } return appIndex; } function convert(targetDirectory) { return __awaiter(this, void 0, void 0, function* () { yield (0, isFolder_1.checkIfFolder)(targetDirectory); const appIndex = getAppIndex(targetDirectory); yield (0, commentCode_1.commentCode)(appIndex, regex_1.appListenerRegex); yield (0, addHandler_1.addHandler)(appIndex, isCommonJs(targetDirectory)); }); } exports.convert = convert;