nuxt-generate

This commit is contained in:
Sébastien Chopin 2016-11-10 14:46:16 +01:00
parent b9680bc3ea
commit a8776de913
3 changed files with 11 additions and 8 deletions

3
.gitignore vendored
View File

@ -7,3 +7,6 @@ npm-debug.log
# other
.nuxt
# dist example generation
examples/**/dist

View File

@ -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)

View File

@ -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",