|
| 1 | +'use strict' |
| 2 | + |
| 3 | +/** |
| 4 | + * Module dependencies. |
| 5 | + */ |
| 6 | + |
| 7 | +const { |
| 8 | + path, toAbsolutePath, chalk, logger, |
| 9 | + datatypes: { isString, isBoolean } |
| 10 | +} = require('@vuepress/shared-utils') |
| 11 | + |
| 12 | +/** |
| 13 | + * Get cache directory and cache identifier via config. |
| 14 | + * @param {object} siteConfig |
| 15 | + * @param {object} cliOptions |
| 16 | + */ |
| 17 | + |
| 18 | +exports.getCacheLoaderOptions = function (siteConfig, cliOptions, cwd, isProd) { |
| 19 | + const defaultCacheDirectory = path.resolve(__dirname, '../../node_modules/.cache/vuepress') |
| 20 | + let cache = cliOptions.cache || siteConfig.cache || defaultCacheDirectory |
| 21 | + |
| 22 | + if (isBoolean(cache)) { |
| 23 | + if (cache === true) { |
| 24 | + cache = defaultCacheDirectory |
| 25 | + } |
| 26 | + } else if (!isString(cache)) { |
| 27 | + throw new Error(`expected cache option to be string or boolean, but got ${typeof cache}`) |
| 28 | + } |
| 29 | + |
| 30 | + const cacheDirectory = toAbsolutePath(cache, cwd) |
| 31 | + const cacheIdentifier = JSON.stringify({ |
| 32 | + vuepress: require('../../package.json').version, |
| 33 | + 'cache-loader': require('cache-loader/package.json').version, |
| 34 | + 'vue-loader': require('cache-loader/package.json').version, |
| 35 | + isProd, |
| 36 | + config: ( |
| 37 | + ( |
| 38 | + siteConfig.markdown |
| 39 | + ? JSON.stringify(siteConfig.markdown) |
| 40 | + : '' |
| 41 | + ) + |
| 42 | + ( |
| 43 | + siteConfig.markdown && siteConfig.markdown.extendMarkdown |
| 44 | + ? siteConfig.markdown.extendMarkdown.toString() |
| 45 | + : '' |
| 46 | + ) + |
| 47 | + ( |
| 48 | + siteConfig.extendMarkdown |
| 49 | + ? siteConfig.extendMarkdown.toString() |
| 50 | + : '' |
| 51 | + ) + |
| 52 | + (siteConfig.chainWebpack || '').toString() + |
| 53 | + (siteConfig.configureWebpack || '').toString() |
| 54 | + ) |
| 55 | + }) |
| 56 | + |
| 57 | + logger.debug('\nCache directory: ' + chalk.gray(cacheDirectory)) |
| 58 | + logger.debug('\nCache identifier : ' + chalk.gray(cacheIdentifier)) |
| 59 | + |
| 60 | + return { cacheDirectory, cacheIdentifier } |
| 61 | +} |
0 commit comments