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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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