forked from netlify/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-functions.js
More file actions
27 lines (19 loc) · 809 Bytes
/
Copy pathget-functions.js
File metadata and controls
27 lines (19 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { listFunctions } = require('@netlify/zip-it-and-ship-it')
const { fileExistsAsync } = require('../lib/fs')
const getUrlPath = (functionName) => `/.netlify/functions/${functionName}`
const BACKGROUND = '-background'
const addFunctionProps = ({ mainFile, name, runtime }) => {
const urlPath = getUrlPath(name)
const isBackground = name.endsWith(BACKGROUND)
return { mainFile, name, runtime, urlPath, isBackground }
}
const JS = 'js'
const getFunctions = async (functionsSrcDir) => {
if (!(await fileExistsAsync(functionsSrcDir))) {
return []
}
const functions = await listFunctions(functionsSrcDir)
const functionsWithProps = functions.filter(({ runtime }) => runtime === JS).map((func) => addFunctionProps(func))
return functionsWithProps
}
module.exports = { getFunctions }