forked from benrobertsonio/netlify-functions-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
28 lines (25 loc) · 816 Bytes
/
gatsby-node.js
File metadata and controls
28 lines (25 loc) · 816 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
28
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const glob = require('glob');
const path = require('path');
const fs = require('fs');
exports.onPostBuild = () => {
// Configure where the functions are kept and where we want to move them.
const srcLocation = `${__dirname}/src/functions`;
const outputLocation = `${__dirname}/public/functions`;
// Get all the functions.
const modules = glob.sync('*.js', { cwd: srcLocation });
modules.forEach(src => {
const moduleSrc = path.join(srcLocation, src);
const moduleOut = path.join(outputLocation, path.basename(src, path.extname(src)) + '.js');
// Copy file to new location.
fs.copyFile(moduleSrc, moduleOut, (err) => {
if (err) {
throw err;
}
});
});
};