Skip to content

Commit 0cc1ece

Browse files
committed
config plugin
1 parent 0fe767b commit 0cc1ece

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# OSX
3+
#
4+
.DS_Store
5+
6+
# node.js
7+
#
8+
node_modules/
9+
npm-debug.log
10+
yarn-error.log
11+

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

gatsby-node.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const path = require('path');
2+
const fsExtra = require('fs-extra');
3+
4+
exports.onCreateNode = ({ node }, pluginOptions) => {
5+
const { source, destination } = pluginOptions;
6+
const sourceNormalized = path.normalize(source);
7+
if (node.internal.type === 'File') {
8+
const dir = path.normalize(node.dir);
9+
if (dir.includes(sourceNormalized)) {
10+
const relativeToDest = dir.replace(sourceNormalized, '');
11+
const newPath = path.join(
12+
process.cwd(),
13+
'public',
14+
destination,
15+
relativeToDest,
16+
node.base
17+
);
18+
19+
fsExtra.copy(node.absolutePath, newPath, err => {
20+
if (err) {
21+
console.error('Error copying file', err);
22+
}
23+
});
24+
}
25+
}
26+
};

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "gatsby-plugin-copy-files-enhanced",
3+
"version": "1.0.0",
4+
"description": "Copies files from source to destination with regex support.",
5+
"main": "gatsby-node.js",
6+
"repository": "https://github.com/csath/gatsby-plugin-copy-files-enhanced",
7+
"author": "Chanaka Athurugiriya <chanakaathurugiriya@gmail.com>",
8+
"license": "MIT",
9+
"dependencies": {
10+
"fs-extra": "^9.0.0"
11+
},
12+
"keywords": [
13+
"gatsby",
14+
"gatsby-plugin"
15+
],
16+
"bugs": {
17+
"url": "https://github.com/csath/gatsby-plugin-copy-files-enhanced/issues"
18+
},
19+
"homepage": "https://github.com/csath/gatsby-plugin-copy-files-enhanced#readme"
20+
}

yarn.lock

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
at-least-node@^1.0.0:
6+
version "1.0.0"
7+
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
8+
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
9+
10+
fs-extra@^9.0.0:
11+
version "9.0.0"
12+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.0.tgz#b6afc31036e247b2466dc99c29ae797d5d4580a3"
13+
integrity sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g==
14+
dependencies:
15+
at-least-node "^1.0.0"
16+
graceful-fs "^4.2.0"
17+
jsonfile "^6.0.1"
18+
universalify "^1.0.0"
19+
20+
graceful-fs@^4.1.6, graceful-fs@^4.2.0:
21+
version "4.2.4"
22+
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
23+
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
24+
25+
jsonfile@^6.0.1:
26+
version "6.0.1"
27+
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179"
28+
integrity sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==
29+
dependencies:
30+
universalify "^1.0.0"
31+
optionalDependencies:
32+
graceful-fs "^4.1.6"
33+
34+
universalify@^1.0.0:
35+
version "1.0.0"
36+
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
37+
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==

0 commit comments

Comments
 (0)