-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathcopyUnstableIncludedDirs.js
27 lines (24 loc) · 1.14 KB
/
copyUnstableIncludedDirs.js
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 path = require('path')
const fs = require('fs')
const AdmZip = require('adm-zip')
const getNetlifyFunctionName = require('../src/lib/helpers/getNetlifyFunctionName')
// This is UNSTABLE support for special use cases needing files served with their Next.js
// pages that become Netlify functions. Eventually this will be supported internally.
const copyUnstableIncludedDirs = ({ nextConfig, functionsDist }) => {
for (const name in nextConfig.unstableNetlifyFunctionsSupport || {}) {
const includeDirs = nextConfig.unstableNetlifyFunctionsSupport[name].includeDirs || []
console.log('Processing included dirs for ', name)
const zipName = path.join(functionsDist, getNetlifyFunctionName(name) + '.zip')
const zip = new AdmZip(zipName)
includeDirs.forEach((includes) => {
if (fs.lstatSync(includes).isDirectory()) {
// We add the files at the root of the ZIP because process.cwd()
// points to `/` in serverless functions
zip.addLocalFolder(includes, includes)
console.log(`Added ${includes} to ${zipName}`)
}
})
zip.writeZip(zipName)
}
}
module.exports = copyUnstableIncludedDirs