mirror of
https://github.com/jakejarvis/netlify-plugin-cache.git
synced 2025-04-26 02:55:22 -04:00
add very basic linting & expand CI tests to Node >=10
This commit is contained in:
parent
a32494baca
commit
29cf08d5ff
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
@ -4,14 +4,23 @@ on: [push, pull_request]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node: [14.x, 13.x, 12.x, 10.x]
|
||||||
|
fail-fast: false
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
name: Node ${{ matrix.node }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12'
|
node-version: ${{ matrix.node }}
|
||||||
- run: npm install -g netlify-cli
|
- name: Install dependencies
|
||||||
- run: netlify build
|
run: npm install --no-package-lock --no-optional
|
||||||
|
- name: Run tests
|
||||||
|
run: npm run test
|
||||||
|
- name: Build example site locally with plugin
|
||||||
|
run: npm run build
|
||||||
env:
|
env:
|
||||||
NETLIFY_SITE_ID: '8ceb6251-650b-481a-976c-fec1a4f95800'
|
NETLIFY_SITE_ID: '8ceb6251-650b-481a-976c-fec1a4f95800'
|
||||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||||
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,2 +1,6 @@
|
|||||||
# Local Netlify folder
|
# Local Netlify folder
|
||||||
.netlify
|
.netlify
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
package-lock.json
|
||||||
|
npm-debug.log*
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Just a test of netlify-plugin-cache.",
|
"description": "Just a test of netlify-plugin-cache.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"netlify-plugin-cache": "*",
|
"netlify-plugin-cache": "file:../",
|
||||||
"netlify-plugin-debug-cache": "^1.0.3"
|
"netlify-plugin-debug-cache": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
index.js
21
index.js
@ -1,7 +1,11 @@
|
|||||||
|
// Netlify Plugin: netlify-plugin-cache
|
||||||
|
// https://github.com/jakejarvis/netlify-plugin-cache
|
||||||
|
//
|
||||||
|
// This plugin is essentially a wrapper around Netlify's native `cache-utils`:
|
||||||
// https://github.com/netlify/build/blob/master/packages/cache-utils/README.md
|
// https://github.com/netlify/build/blob/master/packages/cache-utils/README.md
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// try to restore cache before build begins, if it exists
|
// Try to restore cache before build begins, if it exists
|
||||||
onPreBuild: async ({ utils: { cache }, inputs }) => {
|
onPreBuild: async ({ utils: { cache }, inputs }) => {
|
||||||
if (await cache.restore(inputs.paths)) {
|
if (await cache.restore(inputs.paths)) {
|
||||||
const files = await cache.list(inputs.paths)
|
const files = await cache.list(inputs.paths)
|
||||||
@ -11,24 +15,23 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// only save/update cache if build was successful
|
// Only save/update cache if build was successful
|
||||||
onSuccess: async ({ utils: { cache, status }, inputs }) => {
|
onSuccess: async ({ utils: { cache, status }, inputs }) => {
|
||||||
if (await cache.save(inputs.paths)) {
|
if (await cache.save(inputs.paths)) {
|
||||||
const files = await cache.list(inputs.paths)
|
const files = await cache.list(inputs.paths)
|
||||||
console.log(`Successfully cached: ${inputs.paths.join(', ')} ... ${files.length} files in total.`)
|
console.log(`Successfully cached: ${inputs.paths.join(', ')} ... ${files.length} files in total.`)
|
||||||
|
|
||||||
// show success & more detail in deploy summary
|
// Show success & more detail in deploy summary
|
||||||
status.show({
|
status.show({
|
||||||
title: `${files.length} files cached`,
|
title: `${files.length} files cached`,
|
||||||
summary: 'These will be restored on the next build! ⚡',
|
summary: 'These will be restored on the next build! ⚡',
|
||||||
text: `${inputs.paths.join(', ')}`,
|
text: `${inputs.paths.join(', ')}`
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// this probably happened because the default `paths` is set, so provide instructions to fix
|
// This probably happened because the default `paths` is set, so provide instructions to fix
|
||||||
console.log(`Attempted to cache: ${inputs.paths.join(', ')} ... but failed. :(`)
|
console.log(`Attempted to cache: ${inputs.paths.join(', ')} ... but failed. :(`)
|
||||||
console.log(`Try setting the 'paths' input appropriately in your netlify.toml configuration.`)
|
console.log('Try setting the \'paths\' input appropriately in your netlify.toml configuration.')
|
||||||
console.log(`More details: https://jrvs.io/netlify-cache-usage`)
|
console.log('More details: https://jrvs.io/netlify-cache-usage')
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
28
package.json
28
package.json
@ -2,17 +2,30 @@
|
|||||||
"name": "netlify-plugin-cache",
|
"name": "netlify-plugin-cache",
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"description": "Generic cache plugin for saving and restoring files and/or folders between Netlify builds",
|
"description": "Generic cache plugin for saving and restoring files and/or folders between Netlify builds",
|
||||||
"author": "Jake Jarvis <jake@jarv.is>",
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "index.js",
|
"author": {
|
||||||
|
"name": "Jake Jarvis",
|
||||||
|
"email": "jake@jarv.is",
|
||||||
|
"url": "http://jarv.is/"
|
||||||
|
},
|
||||||
"homepage": "https://github.com/jakejarvis/netlify-plugin-cache#readme",
|
"homepage": "https://github.com/jakejarvis/netlify-plugin-cache#readme",
|
||||||
"bugs": "https://github.com/jakejarvis/netlify-plugin-cache/issues",
|
"bugs": "https://github.com/jakejarvis/netlify-plugin-cache/issues",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/jakejarvis/netlify-plugin-cache.git"
|
"url": "git+https://github.com/jakejarvis/netlify-plugin-cache.git"
|
||||||
},
|
},
|
||||||
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"build": "netlify build",
|
||||||
|
"test": "xo"
|
||||||
|
},
|
||||||
|
"dependencies": {},
|
||||||
|
"devDependencies": {
|
||||||
|
"netlify-cli": "*",
|
||||||
|
"xo": "~0.32.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.18"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"netlify",
|
"netlify",
|
||||||
@ -21,5 +34,12 @@
|
|||||||
"ci",
|
"ci",
|
||||||
"build",
|
"build",
|
||||||
"plugin"
|
"plugin"
|
||||||
]
|
],
|
||||||
|
"xo": {
|
||||||
|
"semicolon": false,
|
||||||
|
"space": 2,
|
||||||
|
"rules": {
|
||||||
|
"object-curly-spacing": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user