Skip to content
Permalink
Browse files

refactor: improve the use of fs-extra

  • Loading branch information...
NicoPennec committed May 10, 2019
1 parent 276e8fa commit 0cf1ab1042f612d2fd35eb3f8e241b9054a4e9ac
Showing with 7 additions and 6 deletions.
  1. +7 −6 lib/module.js
@@ -62,8 +62,7 @@ module.exports = function module (moduleOptions) {

if (!this.options.dev) {
// Save static routes
fs.ensureDirSync(path.resolve(this.options.buildDir, 'dist'))
fs.writeJsonSync(jsonStaticRoutesPath, staticRoutes)
fs.outputJsonSync(jsonStaticRoutesPath, staticRoutes)
}
})

@@ -74,18 +73,20 @@ module.exports = function module (moduleOptions) {
// Generate sitemap.xml in dist
this.nuxt.hook('generate:done', async () => {
consola.info('Generating sitemaps')

// Generate sitemap.xml
const routes = await cache.get('routes')
const sitemap = await createSitemap(options, routes)
const xml = await sitemap.toXML()
const xmlGeneratePath = path.join(this.options.generate.dir, options.path)
await fs.ensureFile(xmlGeneratePath)
await fs.writeFile(xmlGeneratePath, xml)
fs.outputFileSync(xmlGeneratePath, xml)
consola.success('Generated', getPathname(this.options.generate.dir, xmlGeneratePath))

// Generate sitemap.xml.gz
if (options.gzip) {
const gzip = await sitemap.toGzip()
const gzipGeneratePath = path.join(this.options.generate.dir, options.pathGzip)
await fs.ensureFile(gzipGeneratePath)
await fs.writeFile(gzipGeneratePath, gzip)
fs.outputFileSync(gzipGeneratePath, gzip)
consola.success('Generated', getPathname(this.options.generate.dir, gzipGeneratePath))
}
})

0 comments on commit 0cf1ab1

Please sign in to comment.
You can’t perform that action at this time.