Skip to content
Permalink
Browse files
feat(icon): expose options.cacheDir
  • Loading branch information
pi0 committed Aug 14, 2020
1 parent 014a525 commit f8dbf1dac99519648a53dc22ab4019af25a677aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
@@ -59,3 +59,9 @@ purpose: 'maskable'
```

More detail of "purpose": [https://w3c.github.io/manifest/#purpose-member](https://w3c.github.io/manifest/#purpose-member)


**cacheDir**
- Default: `{rootDir}/node_modules/.cache/icon`

Cache dir for generated icons
@@ -1,5 +1,6 @@
const path = require('path')
const { fork } = require('child_process')
const { join } = require('path')
const fs = require('fs-extra')
const hasha = require('hasha')
const { joinUrl, getRouteParams, sizeName } = require('../utils')
@@ -36,6 +37,7 @@ async function run (pwa, _emitAssets) {
fileName: 'icon.png',
source: null,
purpose: ['any', 'maskable'],
cacheDir: join(this.nuxt.options.rootDir, 'node_modules/.cache/pwa/icon'),

targetDir: 'icons',

@@ -45,7 +47,6 @@ async function run (pwa, _emitAssets) {
publicPath,

_iconHash: null,
_cacheDir: null,
_assets: null,
_manifestIcons: null,
_iosSplash: null
@@ -132,11 +133,6 @@ async function generateIcons (options) {
options.iconHash = await hasha.fromFile(options.source).then(h => h.substring(0, 6))
}

// Resize cache dir
if (!options.cacheDir) {
options.cacheDir = path.join(__dirname, '.cache', options.iconHash)
}

// Icons to be emited by webpack
options._assets = []

@@ -192,7 +188,7 @@ function emitAssets (options) {
compiler.hooks.emit.tapPromise('nuxt-pwa-icon', async (compilation) => {
await resizePromise
await Promise.all(options._assets.map(async ({ name, target }) => {
const srcFileName = path.join(options._cacheDir, `${name}.png`)
const srcFileName = path.join(options.cacheDir, `${name}.png`)
const src = await fs.readFile(srcFileName)
compilation.assets[target] = { source: () => src, size: () => src.length }
}))
@@ -207,20 +203,20 @@ async function resizeIcons (options) {
const resizeOpts = JSON.stringify({
version,
input: options.source,
distDir: options._cacheDir,
distDir: options.cacheDir,
sizes: [
...options.sizes,
...options.iosSizes
]
})

const integrityFile = path.join(options._cacheDir, '.' + hasha(resizeOpts).substr(0, 8))
const integrityFile = path.join(options.cacheDir, '.' + hasha(resizeOpts).substr(0, 8))

if (await fs.exists(integrityFile)) {
return
}
await fs.remove(options._cacheDir)
await fs.mkdirp(options._cacheDir)
await fs.remove(options.cacheDir)
await fs.mkdirp(options.cacheDir)

await new Promise((resolve, reject) => {
const child = fork(require.resolve('./resize'), [resizeOpts])

0 comments on commit f8dbf1d

Please sign in to comment.