compat with node 4

This commit is contained in:
Sébastien Chopin 2016-12-09 19:40:59 +01:00
parent 10190052b9
commit 7cbc06144d
8 changed files with 56 additions and 57 deletions

View File

@ -1,10 +1,10 @@
#!/usr/bin/env node
const { join } = require('path')
const { spawn } = require('cross-spawn')
var join = require('path').join
var spawn = require('cross-spawn').spawn
const defaultCommand = 'dev'
const commands = new Set([
var defaultCommand = 'dev'
var commands = new Set([
defaultCommand,
'init',
'build',
@ -12,8 +12,8 @@ const commands = new Set([
'generate'
])
let cmd = process.argv[2]
let args
var cmd = process.argv[2]
var args
if (commands.has(cmd)) {
args = process.argv.slice(3)
@ -22,9 +22,9 @@ if (commands.has(cmd)) {
args = process.argv.slice(2)
}
const bin = join(__dirname, 'nuxt-' + cmd)
var bin = join(__dirname, 'nuxt-' + cmd)
const proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] })
var proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] })
proc.on('close', (code) => process.exit(code))
proc.on('error', (err) => {
console.error(err) // eslint-disable-line no-console

View File

@ -3,14 +3,14 @@
// Show logs
process.env.DEBUG = 'nuxt:*'
const fs = require('fs')
const Nuxt = require('../')
const { resolve } = require('path')
var fs = require('fs')
var Nuxt = require('../')
var resolve = require('path').resolve
const rootDir = resolve(process.argv.slice(2)[0] || '.')
const nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
var rootDir = resolve(process.argv.slice(2)[0] || '.')
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
let options = {}
var options = {}
if (fs.existsSync(nuxtConfigFile)) {
options = require(nuxtConfigFile)
}
@ -20,7 +20,7 @@ if (typeof options.rootDir !== 'string') {
options.dev = false // Create production build when calling `nuxt build`
console.log('[nuxt] Building...') // eslint-disable-line no-console
const nuxt = new Nuxt(options)
var nuxt = new Nuxt(options)
nuxt.build()
.then(() => {
console.log('[nuxt] Building done') // eslint-disable-line no-console

View File

@ -3,18 +3,18 @@
// Show logs
process.env.DEBUG = 'nuxt:*'
const _ = require('lodash')
const debug = require('debug')('nuxt:build')
const fs = require('fs')
const Nuxt = require('../')
const Server = require('../lib/server')
const chokidar = require('chokidar')
const { resolve } = require('path')
var _ = require('lodash')
var debug = require('debug')('nuxt:build')
var fs = require('fs')
var Nuxt = require('../')
var Server = require('../lib/server')
var chokidar = require('chokidar')
var resolve = require('path').resolve
const rootDir = resolve(process.argv.slice(2)[0] || '.')
const nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
var rootDir = resolve(process.argv.slice(2)[0] || '.')
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
let options = {}
var options = {}
if (fs.existsSync(nuxtConfigFile)) {
options = require(nuxtConfigFile)
}
@ -23,10 +23,10 @@ if (typeof options.rootDir !== 'string') {
}
options.dev = true // Add hot reloading and watching changes
const nuxt = new Nuxt(options)
var nuxt = new Nuxt(options)
nuxt.build()
.then(() => {
const server = new Server(nuxt)
var server = new Server(nuxt)
.listen(process.env.PORT || process.env.npm_package_config_nuxt_port, process.env.HOST || process.env.npm_package_config_nuxt_host)
listenOnConfigChanges(nuxt, server)
})
@ -37,10 +37,10 @@ nuxt.build()
function listenOnConfigChanges (nuxt, server) {
// Listen on nuxt.config.js changes
const build = _.debounce(() => {
var build = _.debounce(() => {
debug('[nuxt.config.js] changed, rebuilding the app...')
delete require.cache[nuxtConfigFile]
let options = {}
var options = {}
if (fs.existsSync(nuxtConfigFile)) {
options = require(nuxtConfigFile)
}
@ -57,7 +57,7 @@ function listenOnConfigChanges (nuxt, server) {
process.exit(1)
})
}, 200)
const nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
chokidar.watch(nuxtConfigFile, { ignoreInitial: true })
.on('all', build)
}

View File

@ -3,14 +3,14 @@
// Show logs
process.env.DEBUG = 'nuxt:*'
const fs = require('fs')
const Nuxt = require('../')
const { resolve } = require('path')
var fs = require('fs')
var Nuxt = require('../')
var resolve = require('path').resolve
const rootDir = resolve(process.argv.slice(2)[0] || '.')
const nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
var rootDir = resolve(process.argv.slice(2)[0] || '.')
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
let options = {}
var options = {}
if (fs.existsSync(nuxtConfigFile)) {
options = require(nuxtConfigFile)
}
@ -20,7 +20,7 @@ if (typeof options.rootDir !== 'string') {
options.dev = false // Force production mode (no webpack middlewares called)
console.log('[nuxt] Generating...') // eslint-disable-line no-console
const nuxt = new Nuxt(options)
var nuxt = new Nuxt(options)
nuxt.generate()
.then(() => {
console.log('[nuxt] Generate done') // eslint-disable-line no-console

View File

@ -1,14 +1,14 @@
#!/usr/bin/env node
const fs = require('fs')
const Nuxt = require('../')
const Server = require('../lib/server')
const { resolve } = require('path')
var fs = require('fs')
var Nuxt = require('../')
var Server = require('../lib/server')
var resolve = require('path').resolve
const rootDir = resolve(process.argv.slice(2)[0] || '.')
const nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
var rootDir = resolve(process.argv.slice(2)[0] || '.')
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
let options = {}
var options = {}
if (fs.existsSync(nuxtConfigFile)) {
options = require(nuxtConfigFile)
}
@ -17,7 +17,7 @@ if (typeof options.rootDir !== 'string') {
}
options.dev = false // Force production mode (no webpack middlewares called)
const nuxt = new Nuxt(options)
var nuxt = new Nuxt(options)
new Server(nuxt)
.listen(

View File

@ -16,7 +16,7 @@ setAnsiColors(ansiHTML)
class Nuxt {
constructor (options = {}, cb) {
constructor (options = {}) {
var defaults = {
// special options
_renderer: true,

View File

@ -1,18 +1,16 @@
<% const {
title, htmlAttrs, bodyAttrs, link, style, script, noscript, meta
} = context.meta.inject() %><!DOCTYPE html>
<html n-head-ssr ${htmlAttrs.text()}>
<% var m = context.meta.inject() %><!DOCTYPE html>
<html n-head-ssr <%= m.htmlAttrs.text() %>>
<head>
${meta.text()}
${title.text()}
${link.text()}
${style.text()}
${script.text()}
${noscript.text()}
<%= m.meta.text() %>
<%= m.title.text() %>
<%= m.link.text() %>
<%= m.style.text() %>
<%= m.script.text() %>
<%= m.noscript.text() %>
<base href="<%= baseUrl %>">
<% if (!dev) { %><link rel="stylesheet" href="<%= files.css %>"><% } %>
</head>
<body ${bodyAttrs.text()}>
<body <%= m.bodyAttrs.text() %>>
<%= APP %>
<script type="text/javascript" defer>window.__NUXT__=<%= serialize(context.nuxt) %></script>
<script src="<%= files.vendor %>" defer></script>

View File

@ -65,6 +65,7 @@
"hash-sum": "^1.0.2",
"lodash": "^4.17.2",
"lru-cache": "^4.0.2",
"memory-fs": "^0.4.1",
"path-to-regexp": "^1.7.0",
"pify": "^2.3.0",
"serialize-javascript": "^1.3.0",