From a8776de913a391bfd825b56cbd5ae655d3490240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 10 Nov 2016 14:46:16 +0100 Subject: [PATCH] nuxt-generate --- .gitignore | 3 +++ lib/generate.js | 14 +++++++------- package.json | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 1a70a5547f..199fa62f83 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ npm-debug.log # other .nuxt + +# dist example generation +examples/**/dist diff --git a/lib/generate.js b/lib/generate.js index 6ab1a6cd48..05651dff5f 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -5,7 +5,7 @@ const co = require('co') const pify = require('pify') const debug = require('debug')('nuxt:generate') const _ = require('lodash') -const { resolve, join } = require('path') +const { resolve, join, dirname } = require('path') const copy = pify(fs.copy) const remove = pify(fs.remove) const writeFile = pify(fs.writeFile) @@ -24,7 +24,7 @@ module.exports = function () { var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist') var distPath = resolve(this.dir, this.options.generate.dir) var distNuxtPath = resolve(distPath, '_nuxt') - co(function * () { + return co(function * () { /* ** Clean destination folder */ @@ -46,16 +46,16 @@ module.exports = function () { ** Generate html files from routes */ var promises = [] - this.options.routes.forEach((route) => { + this.routes.forEach((route) => { var promise = this.renderRoute(route.path) .then(({ html }) => { - var path = route.path - path += path[path.length - 1] === '/' ? 'index.html' : '.html' - debug('Generate file : ' + path) + var path = join(route.path, '/', 'index.html') // /about -> /about/index.html + debug('Generate file: ' + path) path = join(distPath, path) + // Make sure the sub folders are created + fs.mkdirsSync(dirname(path)) return writeFile(path, html, 'utf8') }) - console.log(promise) promises.push(promise) }) return Promise.all(promises) diff --git a/package.json b/package.json index 4dca6f773b..5185f2267e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuxt", - "version": "0.3.1", + "version": "0.3.2", "description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)", "main": "index.js", "license": "MIT",