2018-03-16 19:52:17 +00:00
|
|
|
|
2018-02-07 00:26:40 +00:00
|
|
|
const { resolve } = require('path')
|
|
|
|
const { existsSync } = require('fs')
|
2018-04-05 08:38:54 +00:00
|
|
|
const consola = require('consola')
|
2018-04-22 07:31:35 +00:00
|
|
|
const esm = require('esm')(module, {
|
|
|
|
cache: false,
|
|
|
|
cjs: {
|
2018-05-02 09:20:41 +00:00
|
|
|
cache: true,
|
|
|
|
vars: true,
|
|
|
|
namedExports: true
|
2018-04-22 07:31:35 +00:00
|
|
|
}
|
|
|
|
})
|
2018-02-07 00:26:40 +00:00
|
|
|
|
2018-09-06 12:35:51 +00:00
|
|
|
const getRootDir = argv => resolve(argv._[0] || '.')
|
2018-02-07 00:26:40 +00:00
|
|
|
const getNuxtConfigFile = argv => resolve(getRootDir(argv), argv['config-file'])
|
|
|
|
|
|
|
|
exports.nuxtConfigFile = getNuxtConfigFile
|
|
|
|
|
2018-08-06 00:12:44 +00:00
|
|
|
exports.loadNuxtConfig = (argv) => {
|
2018-02-07 00:26:40 +00:00
|
|
|
const rootDir = getRootDir(argv)
|
|
|
|
const nuxtConfigFile = getNuxtConfigFile(argv)
|
|
|
|
|
|
|
|
let options = {}
|
|
|
|
|
|
|
|
if (existsSync(nuxtConfigFile)) {
|
2018-04-22 07:31:35 +00:00
|
|
|
delete require.cache[nuxtConfigFile]
|
2018-04-05 15:34:36 +00:00
|
|
|
options = esm(nuxtConfigFile)
|
|
|
|
if (!options) {
|
|
|
|
options = {}
|
|
|
|
}
|
|
|
|
if (options.default) {
|
|
|
|
options = options.default
|
|
|
|
}
|
2018-02-07 00:26:40 +00:00
|
|
|
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
2018-04-05 08:38:54 +00:00
|
|
|
consola.fatal('Could not load config file: ' + argv['config-file'])
|
2018-02-07 00:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof options.rootDir !== 'string') {
|
|
|
|
options.rootDir = rootDir
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nuxt Mode
|
|
|
|
options.mode =
|
2018-08-10 07:19:19 +00:00
|
|
|
(argv.spa && 'spa') || (argv.universal && 'universal') || options.mode
|
2018-02-07 00:26:40 +00:00
|
|
|
|
2018-08-12 14:26:30 +00:00
|
|
|
// Server options
|
|
|
|
if (!options.server) {
|
|
|
|
options.server = {}
|
|
|
|
}
|
|
|
|
options.server.port = argv.port || options.server.port
|
|
|
|
options.server.host = argv.hostname || options.server.host
|
2018-02-07 00:26:40 +00:00
|
|
|
|
2018-08-12 14:26:30 +00:00
|
|
|
return options
|
2018-02-07 00:26:40 +00:00
|
|
|
}
|
2018-09-02 09:20:25 +00:00
|
|
|
|
|
|
|
exports.getLatestHost = (argv) => {
|
|
|
|
const port =
|
|
|
|
argv.port ||
|
|
|
|
process.env.NUXT_PORT ||
|
|
|
|
process.env.PORT ||
|
|
|
|
process.env.npm_package_config_nuxt_port
|
|
|
|
const host =
|
|
|
|
argv.hostname ||
|
|
|
|
process.env.NUXT_HOST ||
|
|
|
|
process.env.HOST ||
|
|
|
|
process.env.npm_package_config_nuxt_host
|
|
|
|
const socket =
|
|
|
|
argv['unix-socket'] ||
|
|
|
|
process.env.UNIX_SOCKET ||
|
|
|
|
process.env.npm_package_config_unix_socket
|
|
|
|
|
|
|
|
return { port, host, socket }
|
|
|
|
}
|