-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
19 changed files
with
341 additions
and
220 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,27 @@ | ||
name: Linter | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
linter: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js 12.x | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '12.x' | ||
- name: Cache NPM dependencies | ||
uses: actions/cache@v1 | ||
with: | ||
path: node_modules | ||
key: ${{ runner.OS }}-npm-cache | ||
restore-keys: | | ||
${{ runner.OS }}-npm-cache | ||
- name: Install Dependencies | ||
run: npm install | ||
- name: Lint | ||
run: | | ||
npm run eslint | ||
env: | ||
CI: true |
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,60 @@ | ||
name: Tester | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
tester: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
node-version: ['10.x', '12.x', '14.x'] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Cache NPM dependencies | ||
uses: actions/cache@v1 | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-npm-cache | ||
restore-keys: ${{ runner.os }}-npm-cache | ||
- name: Install Dependencies | ||
run: npm install | ||
- name: Test | ||
run: npm run test | ||
env: | ||
CI: true | ||
coverage: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
node-version: ['12.x'] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Cache NPM dependencies | ||
uses: actions/cache@v1 | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-npm-cache | ||
restore-keys: ${{ runner.os }}-npm-cache | ||
- name: Install Dependencies | ||
run: npm install | ||
- name: Run test | ||
run: npm run test | ||
# - name: Coverage | ||
# run: npm run test-cov | ||
# env: | ||
# CI: true | ||
# - name: Coveralls | ||
# uses: coverallsapp/github-action@master | ||
# with: | ||
# github-token: ${{ secrets.github_token }} |
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,2 @@ | ||
disable-self-update-check true | ||
registry "https://registry.npmjs.org" |
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
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,65 +1,38 @@ | ||
'use strict'; | ||
|
||
const ejs = require('ejs'); | ||
const { resolve } = require('path'); | ||
const { upperFirst } = require('lodash'); | ||
const DefineCache = require('./define-cache'); | ||
const define = new DefineCache(); | ||
const getStringHash = require('./get-string-hash'); | ||
const writeServiceWorkerUsingDefaultTemplate = require('./write-sw-using-default-template'); | ||
|
||
const handeRuntimeCaching = runtimeCachingEntry => { | ||
let capture = runtimeCachingEntry.urlPattern; | ||
if (typeof capture === 'string') { | ||
capture = `'${capture}'`; | ||
} | ||
|
||
const options = runtimeCachingEntry.options || {}; | ||
|
||
options.plugins = options.plugins || []; | ||
['backgroundSync', 'broadcastUpdate', 'cacheableResponse', 'expiration'].forEach(item => { | ||
if (options[item]) { | ||
const plugin = {}; | ||
plugin.name = item; | ||
plugin.options = options[item]; | ||
options.plugins.push(plugin); | ||
delete options[item]; | ||
} | ||
}); | ||
options.plugins = options.plugins.map(plugin => { | ||
const pluginDefine = `${upperFirst(plugin.name)}Plugin`; | ||
define.set(`workbox.${plugin.name}`, pluginDefine); | ||
return `new ${pluginDefine}(${JSON.stringify(plugin.options)})`; | ||
}); | ||
module.exports = async (locals, serviceWorker) => { | ||
|
||
define.set('workbox.strategies', runtimeCachingEntry.handler); | ||
const handler = `new ${runtimeCachingEntry.handler}(${JSON.stringify(options, (key, value) => { | ||
if (key === 'plugins') { | ||
return '$plugins-point'; | ||
} | ||
return value; | ||
})})`.replace('"$plugins-point"', `[${options.plugins.join(',')}]`); | ||
const { precache, options } = serviceWorker; | ||
const { pages, posts } = locals; | ||
|
||
const method = runtimeCachingEntry.method || 'GET'; | ||
const manifestEntries = []; | ||
|
||
define.set('workbox.routing', 'registerRoute'); | ||
return `registerRoute(${capture}, ${handler}, '${method}');`; | ||
}; | ||
|
||
module.exports = serviceWorker => { | ||
const options = Object.assign({ | ||
workboxCDN: serviceWorker.cdn, | ||
disableDevLogs: serviceWorker.disableDevLogs | ||
}, serviceWorker.options); | ||
if (precache.posts.enable) { | ||
posts.sort(precache.posts.sort) | ||
.limit(precache.posts.limit) | ||
.forEach(item => { | ||
manifestEntries.push({ | ||
url: item.path, | ||
revision: getStringHash(item.content) | ||
}); | ||
}); | ||
} | ||
|
||
if (options.runtimeCaching) { | ||
options.runtimeCaching = options.runtimeCaching.map(handeRuntimeCaching); | ||
if (precache.pages) { | ||
pages.forEach(item => { | ||
manifestEntries.push({ | ||
url: item.path, | ||
revision: getStringHash(item.content) | ||
}); | ||
}); | ||
} | ||
|
||
options.importDefine = define.toString(); | ||
const files = await writeServiceWorkerUsingDefaultTemplate(Object.assign({ | ||
manifestEntries | ||
}, options)); | ||
|
||
return { | ||
path: options.swDest, | ||
data: () => { | ||
return ejs.renderFile(resolve(__dirname, '../templates/sw-template.ejs'), options); | ||
} | ||
}; | ||
return {files}; | ||
}; |
Oops, something went wrong.