Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

Commit

Permalink
fixed config issues -> replaced custom config implementation with a m…
Browse files Browse the repository at this point in the history
…ore native solution
  • Loading branch information
marcelkilian committed May 18, 2016
1 parent 9f8c271 commit 7cf4b6f
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 188 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changed:

Fixed:

- fixed config issues -> replaced custom config implementation with a more native solution
- project cloning/installation and removing not finishing when custom.json does not exist
- removing and reinstalling a running project shows wrong state in project listing
- not showing configured design after clone when there was already a customization with that id
Expand Down
6 changes: 2 additions & 4 deletions config/test.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"registry": {
"url": "",
"public": "",
"private": [],
"refreshInterval": "900000"
},
"test": {
"key": "value"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ansi-to-html-umd": "^0.4.2",
"asar": "^0.8.0",
"coffee-script": "1.9.3",
"config": "^1.15.0",
"config": "^1.20.2",
"docker-events": "0.0.2",
"dockerode": "^2.2.9",
"fs-jetpack": "^0.7.0",
Expand All @@ -34,7 +34,7 @@
"tmp": "0.0.28"
},
"devDependencies": {
"electron-prebuilt": "^0.37.5",
"electron-prebuilt": "^0.37.8",
"gulp": "^3.9.0",
"gulp-clean": "^0.3.1",
"gulp-concat": "^2.5.2",
Expand Down
3 changes: 3 additions & 0 deletions src/app.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
utilsModel = require './models/util'
utilsModel.initConfig()

eventHandler = require './handler/events.coffee'
setupModel = require './models/setup/setup.coffee'
projectsModel = require './models/projects/list.coffee'
Expand Down
2 changes: 1 addition & 1 deletion src/handler/runtimeStreams.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _r = require 'kefir'
ks = require 'kefir-storage'
isOnline = require 'is-online'

config = require '../models/stores/config'
config = require 'config'
utilModel = require '../models/util'
dockerProxyModel = require '../models/docker/proxy.coffee'
dockerListModel = require '../models/docker/list.coffee'
Expand Down
2 changes: 1 addition & 1 deletion src/models/docker/proxy.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_r = require 'kefir'
config = require 'config'

config = require '../stores/config.coffee'
dockerModel = require '.'

proxyConfig = config.get 'proxy'
Expand Down
2 changes: 1 addition & 1 deletion src/models/registry/index.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
_r = require 'kefir'
ks = require 'kefir-storage'
crypto = require "crypto"
config = require 'config'

config = require '../stores/config.coffee'
utils = require '../util/index.coffee'
remote = require './remote.coffee'
local = require './local.coffee'
Expand Down
2 changes: 1 addition & 1 deletion src/models/setup/setup.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_r = require 'kefir'
ks = require 'kefir-storage'
config = require 'config'

config = require '../stores/config'
vagrantFsModel = require '../vagrant/fs.coffee'
vagrantRunModel = require '../vagrant/run.coffee'
virtualBoxModel = require '../vagrant/virtualbox.coffee'
Expand Down
28 changes: 0 additions & 28 deletions src/models/stores/config.coffee

This file was deleted.

33 changes: 14 additions & 19 deletions src/models/util/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ convert = new Convert();

model = {}

# use original config first and let it overwrite later with the custom config
model.setConfig = (newConfig) ->
return false if ! newConfig || typeof newConfig != "object"
config = newConfig
return true
# sync - extends default config with user config.
# Changes to require('config') can only be made before the first .get call. After that it gets immutable
model.initConfig = () ->
return false if ! (configModulePath = @getConfigModulePath())
configPath = jetpack.cwd(configModulePath).path('config.json')

#@todo improve error handling -> show config errors on eintopf startup
try
userConfig = jetpack.read configPath, 'json'
config.util.extendDeep config, userConfig
catch err
if process.env.NODE_ENV == 'development'
console.log 'Failed to load user config in ' + configPath
console.log 'Error message: ' + err.message

# resolves relative paths
model.resolvePath = (path) ->
Expand Down Expand Up @@ -46,20 +55,6 @@ model.getConfigModulePath = () ->
return null if ! (configPath = @getConfigPath())? || ! config?.app?.defaultNamespace
return jetpack.cwd(configPath).path config.app.defaultNamespace

model.loadUserConfig = (callback) ->
return callback new Error 'Failed to get config module path' if ! (configModulePath = @getConfigModulePath())
@loadJson jetpack.cwd(configModulePath).path('config.json'), callback

model.loadJson = (path, callback) ->
return callback new Error 'Invalid path' if ! path

try
userConfig = jetpack.read path, 'json'
catch err
return callback err

return callback null, userConfig

model.loadJsonAsync = (path, callback) ->
return callback new Error 'Invalid path' if ! path

Expand Down
2 changes: 1 addition & 1 deletion src/models/vagrant/fs.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_r = require 'kefir'
jetpack = require 'fs-jetpack'
config = require 'config'

config = require '../stores/config'
utilModel = require '../util/'

appConfig = config.get 'app'
Expand Down
27 changes: 0 additions & 27 deletions tests/specs/models/stores/config-spec.coffee

This file was deleted.

Loading

0 comments on commit 7cf4b6f

Please sign in to comment.