UNPKG

runtime-eol

Version:
51 lines (40 loc) 1.19 kB
const fs = require('fs'); function extractRuntimeTag(fileContent) { // Pattern for TypeScript files with quotes: runtime: "any-value" const tsPattern = /runtime:\s*["']?([^"'\s]+)["']?/; // Pattern for YAML files: runtime: any-value const yamlPattern = /runtime:\s*([^\s]+)/; // Try both patterns const tsMatch = fileContent.match(tsPattern); if (tsMatch && tsMatch[1]) { return tsMatch[1]; } const yamlMatch = fileContent.match(yamlPattern); if (yamlMatch && yamlMatch[1]) { return yamlMatch[1]; } return null; } function getRuntimeFromFile(filePath) { try { const fileContent = fs.readFileSync(filePath, 'utf8'); return extractRuntimeTag(fileContent); } catch { return null; } } function getCurrent() { const possibleFiles = ['serverless.ts', 'serverless.yml', 'serverless.yaml']; for (const file of possibleFiles) { const runtime = getRuntimeFromFile(file); if (runtime) { console.log(`Runtime found in ${file}: ${runtime}`); return runtime; } } console.warn('Could not find SLS runtime. Looked at = %j', possibleFiles); return false; } module.exports = { getCurrent: getCurrent, };