-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
40 lines (33 loc) · 1.05 KB
/
gatsby-node.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
28
29
30
31
32
33
34
35
36
37
38
39
40
const fs = require('fs-extra');
const path = require('path');
function stripInitCwd(str) {
return str.replace(process.env.INIT_CWD + path.sep, '');
}
function copyApiFolders(pluginFilepath, reporter) {
const src = path.join(pluginFilepath, 'api');
const dest = path.join(process.env.INIT_CWD, 'api');
if (src !== dest && fs.existsSync(src)) {
reporter.info(`Copying ${stripInitCwd(src)} to ${stripInitCwd(dest)}`);
fs.copySync(src, dest);
}
}
exports.onPostBuild = function onPostBuild({ store, reporter }, pluginOptions) {
const { flattenedPlugins } = store.getState();
const { prefix = '', packages = [] } = pluginOptions;
flattenedPlugins.forEach(plugin => {
const { name, pluginFilepath } = plugin;
if (prefix) {
if (name.indexOf(prefix) === 0) {
copyApiFolders(pluginFilepath, reporter);
}
} else {
copyApiFolders(pluginFilepath, reporter);
}
});
packages.forEach(package => {
copyApiFolders(
path.resolve(process.env.INIT_CWD, 'node_modules', package),
reporter
);
});
};