read and merge config from .re-natal.local
This commit is contained in:
parent
ac78028655
commit
0a51de384f
|
@ -237,27 +237,34 @@ writeConfig = (config) ->
|
||||||
verifyConfig = (config) ->
|
verifyConfig = (config) ->
|
||||||
if !config.platforms? || !config.modules? || !config.imageDirs? || !config.interface? || !config.envRoots?
|
if !config.platforms? || !config.modules? || !config.imageDirs? || !config.interface? || !config.envRoots?
|
||||||
throw new Error 're-natal project needs to be upgraded, please run: re-natal upgrade'
|
throw new Error 're-natal project needs to be upgraded, please run: re-natal upgrade'
|
||||||
|
|
||||||
config
|
config
|
||||||
|
|
||||||
readConfig = (verify = true)->
|
mergeConfigs = (config1, config2) ->
|
||||||
|
Object.assign(config1, config2);
|
||||||
|
|
||||||
|
readConfig = (file = '.re-natal') ->
|
||||||
try
|
try
|
||||||
config = JSON.parse readFile '.re-natal'
|
JSON.parse readFile file
|
||||||
if (verify)
|
|
||||||
verifyConfig(config)
|
|
||||||
else
|
|
||||||
config
|
|
||||||
catch {message}
|
catch {message}
|
||||||
logErr \
|
logErr \
|
||||||
if message.match /ENOENT/i
|
if message.match /ENOENT/i
|
||||||
'No Re-Natal config was found in this directory (.re-natal)'
|
"No Re-Natal config was found in this directory (#{file})"
|
||||||
else if message.match /EACCES/i
|
else if message.match /EACCES/i
|
||||||
'No read permissions for .re-natal'
|
"No read permissions for #{file}"
|
||||||
else if message.match /Unexpected/i
|
else if message.match /Unexpected/i
|
||||||
'.re-natal contains malformed JSON'
|
"#{file} contains malformed JSON"
|
||||||
else
|
else
|
||||||
message
|
message
|
||||||
|
|
||||||
|
readAndVerifyConfig = (file) ->
|
||||||
|
verifyConfig readConfig file
|
||||||
|
|
||||||
|
readLocalConfig = () ->
|
||||||
|
config = readConfig '.re-natal'
|
||||||
|
if fs.existsSync('.re-natal.local')
|
||||||
|
config = mergeConfigs(config, readConfig( '.re-natal.local'))
|
||||||
|
verifyConfig(config)
|
||||||
|
|
||||||
scanImageDir = (dir) ->
|
scanImageDir = (dir) ->
|
||||||
fnames = fs.readdirSync(dir)
|
fnames = fs.readdirSync(dir)
|
||||||
.map (fname) -> "#{dir}/#{fname}"
|
.map (fname) -> "#{dir}/#{fname}"
|
||||||
|
@ -295,7 +302,7 @@ resolveAndroidDevHost = (deviceType) ->
|
||||||
configureDevHostForAndroidDevice = (deviceType) ->
|
configureDevHostForAndroidDevice = (deviceType) ->
|
||||||
try
|
try
|
||||||
devHost = resolveAndroidDevHost(deviceType)
|
devHost = resolveAndroidDevHost(deviceType)
|
||||||
config = readConfig()
|
config = readAndVerifyConfig()
|
||||||
config.platforms.android.host = devHost
|
config.platforms.android.host = devHost
|
||||||
writeConfig(config)
|
writeConfig(config)
|
||||||
log "Please run: re-natal use-figwheel to take effect."
|
log "Please run: re-natal use-figwheel to take effect."
|
||||||
|
@ -316,7 +323,7 @@ resolveIosDevHost = (deviceType) ->
|
||||||
configureDevHostForIosDevice = (deviceType) ->
|
configureDevHostForIosDevice = (deviceType) ->
|
||||||
try
|
try
|
||||||
devHost = resolveIosDevHost(deviceType)
|
devHost = resolveIosDevHost(deviceType)
|
||||||
config = readConfig()
|
config = readAndVerifyConfig()
|
||||||
config.platforms.ios.host = devHost
|
config.platforms.ios.host = devHost
|
||||||
writeConfig(config)
|
writeConfig(config)
|
||||||
log "Please run: re-natal use-figwheel to take effect."
|
log "Please run: re-natal use-figwheel to take effect."
|
||||||
|
@ -598,7 +605,7 @@ addPlatform = (platform) ->
|
||||||
if !(platform of platformMeta)
|
if !(platform of platformMeta)
|
||||||
throw new Error "Unknown platform [#{platform}]"
|
throw new Error "Unknown platform [#{platform}]"
|
||||||
|
|
||||||
config = readConfig()
|
config = readAndVerifyConfig()
|
||||||
platforms = Object.keys config.platforms
|
platforms = Object.keys config.platforms
|
||||||
|
|
||||||
if platform in platforms
|
if platform in platforms
|
||||||
|
@ -732,7 +739,7 @@ platformModulesAndImages = (config, platform) ->
|
||||||
|
|
||||||
generateDevScripts = () ->
|
generateDevScripts = () ->
|
||||||
try
|
try
|
||||||
config = readConfig()
|
config = readLocalConfig()
|
||||||
platforms = Object.keys config.platforms
|
platforms = Object.keys config.platforms
|
||||||
projName = config.name
|
projName = config.name
|
||||||
devEnvRoot = config.envRoots.dev
|
devEnvRoot = config.envRoots.dev
|
||||||
|
@ -829,7 +836,7 @@ doUpgrade = (config) ->
|
||||||
|
|
||||||
useComponent = (name, platform) ->
|
useComponent = (name, platform) ->
|
||||||
try
|
try
|
||||||
config = readConfig()
|
config = readAndVerifyConfig()
|
||||||
platforms = Object.keys config.platforms
|
platforms = Object.keys config.platforms
|
||||||
if typeof platform isnt 'string'
|
if typeof platform isnt 'string'
|
||||||
config.modules.push name
|
config.modules.push name
|
||||||
|
@ -861,7 +868,7 @@ logModuleDifferences = (platform, existingModules, newModules) ->
|
||||||
inferComponents = () ->
|
inferComponents = () ->
|
||||||
requiresByPlatform = buildRequireByPlatformMap()
|
requiresByPlatform = buildRequireByPlatformMap()
|
||||||
|
|
||||||
config = readConfig() # re-natal file
|
config = readAndVerifyConfig() # re-natal file
|
||||||
logModuleDifferences('common', config.modules, requiresByPlatform.common)
|
logModuleDifferences('common', config.modules, requiresByPlatform.common)
|
||||||
config.modules = requiresByPlatform.common
|
config.modules = requiresByPlatform.common
|
||||||
|
|
||||||
|
@ -873,7 +880,7 @@ inferComponents = () ->
|
||||||
writeConfig(config)
|
writeConfig(config)
|
||||||
|
|
||||||
autoRequire = (enabled) ->
|
autoRequire = (enabled) ->
|
||||||
config = readConfig()
|
config = readAndVerifyConfig()
|
||||||
config.autoRequire = enabled
|
config.autoRequire = enabled
|
||||||
writeConfig(config)
|
writeConfig(config)
|
||||||
if (enabled)
|
if (enabled)
|
||||||
|
@ -909,7 +916,7 @@ cli.command 'init <name>'
|
||||||
cli.command 'upgrade'
|
cli.command 'upgrade'
|
||||||
.description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)'
|
.description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)'
|
||||||
.action ->
|
.action ->
|
||||||
doUpgrade readConfig(false)
|
doUpgrade readConfig()
|
||||||
|
|
||||||
cli.command 'add-platform <platform>'
|
cli.command 'add-platform <platform>'
|
||||||
.description 'adds additional app platform: \'windows\' - UWP app, \'wpf\' - WPF app'
|
.description 'adds additional app platform: \'windows\' - UWP app, \'wpf\' - WPF app'
|
||||||
|
@ -921,7 +928,7 @@ cli.command 'xcode'
|
||||||
.action ->
|
.action ->
|
||||||
ensureOSX ->
|
ensureOSX ->
|
||||||
ensureXcode ->
|
ensureXcode ->
|
||||||
openXcode readConfig().name
|
openXcode readAndVerifyConfig().name
|
||||||
|
|
||||||
cli.command 'deps'
|
cli.command 'deps'
|
||||||
.description 'install all dependencies for the project'
|
.description 'install all dependencies for the project'
|
||||||
|
@ -981,7 +988,7 @@ cli.command 'disable-auto-require'
|
||||||
cli.command 'copy-figwheel-bridge'
|
cli.command 'copy-figwheel-bridge'
|
||||||
.description 'copy figwheel-bridge.js into project'
|
.description 'copy figwheel-bridge.js into project'
|
||||||
.action () ->
|
.action () ->
|
||||||
copyFigwheelBridge(readConfig(false).name)
|
copyFigwheelBridge(readConfig().name)
|
||||||
log "Copied figwheel-bridge.js"
|
log "Copied figwheel-bridge.js"
|
||||||
|
|
||||||
cli.on '*', (command) ->
|
cli.on '*', (command) ->
|
||||||
|
|
Loading…
Reference in New Issue