Merge pull request #392 from PierreRambaud/feature-391

Add config file option
This commit is contained in:
Sébastien Chopin 2017-03-15 16:07:02 +01:00 committed by GitHub
commit d782b1c516

View File

@ -15,13 +15,32 @@ if (process.argv.indexOf('--analyze') !== -1 || process.argv.indexOf('-a') !== -
process.argv = without(process.argv, '--analyze', '-a') process.argv = without(process.argv, '--analyze', '-a')
} }
var nuxtConfigFileName = 'nuxt.config.js'
// --config-file option
var indexOfConfig = false
if (process.argv.indexOf('--config-file') !== -1) {
indexOfConfig = process.argv.indexOf('--config-file')
} else if (process.argv.indexOf('-c') !== -1) {
indexOfConfig = process.argv.indexOf('-c')
}
if (indexOfConfig !== false) {
nuxtConfigFileName = process.argv.slice(indexOfConfig)[1]
process.argv = without(process.argv, '--config-file', '-c', nuxtConfigFileName)
}
// Root directory parameter
var rootDir = resolve(process.argv.slice(2)[0] || '.') var rootDir = resolve(process.argv.slice(2)[0] || '.')
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js') var nuxtConfigFilePath = resolve(rootDir, nuxtConfigFileName)
var options = {} var options = {}
if (fs.existsSync(nuxtConfigFile)) { if (fs.existsSync(nuxtConfigFilePath)) {
options = require(nuxtConfigFile) options = require(nuxtConfigFilePath)
} else {
console.log(`Could not locate ${nuxtConfigFilePath}`) // eslint-disable-line no-console
} }
if (typeof options.rootDir !== 'string') { if (typeof options.rootDir !== 'string') {
options.rootDir = rootDir options.rootDir = rootDir
} }