This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benedikt Rötsch
committed
Jun 6, 2018
0 parents
commit 8b2f8a4
Showing
5 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/*.js | ||
package-lock.json | ||
|
||
# Created by https://www.gitignore.io/api/vim,code,linux,macos,windows,sublimetext,node | ||
|
||
### Code ### | ||
# Visual Studio Code - https://code.visualstudio.com/ | ||
.settings/ | ||
.vscode/ | ||
tsconfig.json | ||
jsconfig.json | ||
|
||
### Linux ### | ||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
|
||
### macOS ### | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
### SublimeText ### | ||
# cache files for sublime text | ||
*.tmlanguage.cache | ||
*.tmPreferences.cache | ||
*.stTheme.cache | ||
|
||
# workspace files are user-specific | ||
*.sublime-workspace | ||
|
||
# project files should be checked into the repository, unless a significant | ||
# proportion of contributors will probably not be using SublimeText | ||
# *.sublime-project | ||
|
||
# sftp configuration file | ||
sftp-config.json | ||
|
||
# Package control specific files | ||
Package Control.last-run | ||
Package Control.ca-list | ||
Package Control.ca-bundle | ||
Package Control.system-ca-bundle | ||
Package Control.cache/ | ||
Package Control.ca-certs/ | ||
Package Control.merged-ca-bundle | ||
Package Control.user-ca-bundle | ||
oscrypto-ca-bundle.crt | ||
bh_unicode_properties.cache | ||
|
||
# Sublime-github package stores a github token in this file | ||
# https://packagecontrol.io/packages/sublime-github | ||
GitHub.sublime-settings | ||
|
||
### Vim ### | ||
# swap | ||
.sw[a-p] | ||
.*.sw[a-p] | ||
# session | ||
Session.vim | ||
# temporary | ||
.netrwhist | ||
# auto-generated tag files | ||
tags | ||
|
||
### Windows ### | ||
# Windows thumbnail cache files | ||
Thumbs.db | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
|
||
# End of https://www.gitignore.io/api/vim,code,linux,macos,windows,sublimetext,node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
*.un~ | ||
yarn.lock | ||
src | ||
flow-typed | ||
coverage | ||
decls | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# gatsby-plugin-netlify-cache | ||
|
||
<p align="center"> | ||
<a href="https://www.npmjs.com/package/gatsby-plugin-netlify-cache"> | ||
<img src="https://img.shields.io/npm/v/gatsby-plugin-netlify-cache.svg" alt="NPM"> | ||
</a> | ||
| ||
<a href="http://npm-stat.com/charts.html?package=gatsby-plugin-netlify-cache"> | ||
<img src="https://img.shields.io/npm/dm/gatsby-plugin-netlify-cache.svg" alt="NPM downloads"> | ||
</a> | ||
</p> | ||
|
||
> This plugin caches your build files locally or in the Netlify cache directory. It will massively speed up subsequent builds. | ||
## ☁️ Installation | ||
|
||
```sh | ||
npm install gatsby-plugin-netlify-cache | ||
``` | ||
|
||
## 🛫 Setup | ||
|
||
Add `'gatsby-plugin-netlify-cache'` to the plugins in your `gatsby-config.js` file. | ||
|
||
## ⚙️ Configuration | ||
|
||
There is no configuration yet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "gatsby-plugin-netlify-cache", | ||
"version": "1.0.0", | ||
"description": "Cache your build files on Netlify", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "babel src --out-dir . --ignore __tests__", | ||
"watch": "babel -w src --out-dir . --ignore __tests__", | ||
"prepublish": "cross-env NODE_ENV=production npm run build" | ||
}, | ||
"keywords": [ | ||
"gatsby", | ||
"gatsby-plugin" | ||
], | ||
"author": "Benedikt Rötsch <[email protected]>", | ||
"bugs": { | ||
"url": "https://github.com/axe312ger/gatsby-plugin-netlify-cache/issues" | ||
}, | ||
"homepage": "https://github.com/axe312ger/gatsby-plugin-netlify-cache/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/axe312ger/gatsby-plugin-netlify-cache.git" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0", | ||
"fs-extra": "^6.0.1" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"cross-env": "^5.0.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { resolve } = require(`path`) | ||
|
||
const { ensureDir, readdir, copy } = require(`fs-extra`) | ||
|
||
function calculateDirs (store) { | ||
const program = store.getState().program | ||
|
||
const staticDir = resolve(program.directory, `public`, `static`) | ||
const cacheDir = process.env.NETLIFY_BUILD_BASE | ||
? resolve(process.env.NETLIFY_BUILD_BASE, `cache`, `.gatsby-static-files`) | ||
: resolve(program.directory, `.gatsby-static-files`) | ||
|
||
return { | ||
staticDir, | ||
cacheDir, | ||
} | ||
} | ||
|
||
exports.onPreBootstrap = async function({ | ||
store, | ||
}) { | ||
const { staticDir, cacheDir } = calculateDirs(store) | ||
|
||
console.log(`Ensuring existance of cache and gatsby public/static directory`) | ||
await ensureDir(cacheDir) | ||
await ensureDir(staticDir) | ||
|
||
const cacheFiles = await readdir(cacheDir) | ||
console.log(`Found ${cacheFiles.length} files in cache directory`) | ||
|
||
const staticFiles = await readdir(staticDir) | ||
console.log(`Found ${staticFiles.length} files in public/static directory`) | ||
|
||
await copy(cacheDir, staticDir, { | ||
overwrite: false, | ||
}) | ||
console.log(`Refilled gatsby cache if neccessary`) | ||
} | ||
|
||
exports.onPostBuild = async function({ | ||
store, | ||
}) { | ||
const { staticDir, cacheDir } = calculateDirs(store) | ||
|
||
const cacheFiles = await readdir(cacheDir) | ||
console.log(`Found ${cacheFiles.length} files in cache directory`) | ||
|
||
const staticFiles = await readdir(staticDir) | ||
console.log(`Found ${staticFiles.length} files in public/static directory`) | ||
|
||
await copy(staticDir, cacheDir, { | ||
overwrite: false, | ||
}) | ||
console.log(`Restored gatsby cache`) | ||
} |