Nuxt/bin/common/utils.js
Jonas Galvez 3f1d634fb7 Consistent parens in arrow functions (#3630)
* Minor consistency enhancements

* Arrow parenthesis consistency

* Change linting rule

* Fix typo

* Update .eslintrc.js to only require parens for blocks

* Update style according to brace-only suggestion

* Remove --fix from lint

* Tweak no-loading time (failing test)

* Tweak no-loading time (failing test) (2)

* Tweak no-loading time (failing test) (3)

* Tweak no-loading time (failing test) (4)

* Tweak no-loading time (failing test) (5)
2018-08-06 02:12:44 +02:00

59 lines
1.4 KiB
JavaScript

const { resolve } = require('path')
const { existsSync } = require('fs')
const consola = require('consola')
const esm = require('esm')(module, {
cache: false,
cjs: {
cache: true,
vars: true,
namedExports: true
}
})
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)) {
delete require.cache[nuxtConfigFile]
options = esm(nuxtConfigFile)
if (!options) {
options = {}
}
if (options.default) {
options = options.default
}
} else if (argv['config-file'] !== 'nuxt.config.js') {
consola.fatal('Could not load config file: ' + argv['config-file'])
}
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 }
}