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: {
|
|
|
|
cache: true
|
|
|
|
}
|
|
|
|
})
|
2018-02-07 00:26:40 +00:00
|
|
|
|
|
|
|
const getRootDir = argv => resolve(argv._[0] || '.')
|
|
|
|
const getNuxtConfigFile = argv => resolve(getRootDir(argv), argv['config-file'])
|
|
|
|
|
|
|
|
exports.nuxtConfigFile = getNuxtConfigFile
|
|
|
|
|
|
|
|
exports.loadNuxtConfig = argv => {
|
|
|
|
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 =
|
|
|
|
(argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
|
|
|
|
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.getLatestHost = argv => {
|
|
|
|
const port =
|
|
|
|
argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
|
|
|
const host =
|
|
|
|
argv.hostname ||
|
|
|
|
process.env.HOST ||
|
|
|
|
process.env.npm_package_config_nuxt_host
|
|
|
|
|
|
|
|
return { port, host }
|
|
|
|
}
|