express-to-lambda
Version:
Simple package for converting your express application to an AWS Lambda.
24 lines (23 loc) • 923 B
JavaScript
import { addHandler } from "./utils/addHandler";
import { commentCode } from "./utils/commentCode";
import { findFilesWithString } from "./utils/findFilesWithString";
import { checkIfFolder } from "./utils/isFolder";
import { appListenerRegex } from "./utils/regex";
import { adapter } from "./utils/handler";
function isCommonJs(targetDirectory) {
return !findFilesWithString(targetDirectory, `"type": "module"`).at(0);
}
function getAppIndex(targetDirectory) {
const appIndex = findFilesWithString(targetDirectory, "express()").at(0);
if (!appIndex) {
throw new Error("Express app not found");
}
return appIndex;
}
async function convert(targetDirectory) {
await checkIfFolder(targetDirectory);
const appIndex = getAppIndex(targetDirectory);
await commentCode(appIndex, appListenerRegex);
await addHandler(appIndex, isCommonJs(targetDirectory));
}
export { convert, adapter };