Skip to content

Commit

Permalink
@ teracyhq#277 | move extensions config from system to config so that…
Browse files Browse the repository at this point in the history
… we can override
  • Loading branch information
hoatle committed Aug 12, 2018
1 parent d66b62e commit 4022471
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 54 deletions.
15 changes: 14 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@
# teracy-dev related settings
teracy-dev:
require_version: ">= 0.6.0-a1-SNAPSHOT"
extensions: []
extensions:
- _id: "0"
path:
lookup: extensions # we can configure where to lookup for the extension, "extensions" by default if no configured
extension: teracy-dev-core # extension_path, we'll lookup the extension by its lookup_path + extension_path
location: # auto download the extension into the lookup_path
git: https://github.com/hoatle/teracy-dev-core.git
# ref:
# tag:
branch: develop
require_version: ">= 0.1.0-SNAPSHOT"
enabled: true # when true, extension will be auto-downloaded if not available yet and will load this extension to be used
# extension must have manifest.yaml file to describe its name, version and optional description
# optional: config_default.yaml, teracy-dev-ext.rb will be auto loaded if available

# vagrant related settings
vagrant: {}
Expand Down
4 changes: 2 additions & 2 deletions lib/teracy-dev/extension/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def sync(extension)
@logger.error("git is not avaiable")
end
Dir.chdir(lookup_path) do
@logger.info("cd #{lookup_path} && git clone #{git} -b #{branch} --single-branch --depth=1")
system("git clone #{git} -b #{branch} --single-branch --depth=1")
@logger.info("cd #{lookup_path} && git clone #{git} -b #{branch}")
system("git clone #{git} -b #{branch}")
end
end
end
Expand Down
26 changes: 4 additions & 22 deletions lib/teracy-dev/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
require_relative 'processors/manager'
require_relative 'config/manager'
require_relative 'settings/manager'
require_relative 'extension/manager'


module TeracyDev
Expand All @@ -27,9 +26,7 @@ def initialize
def start
@processorsManager = Processors::Manager.new
@configManager = Config::Manager.new
@extensionManager = Extension::Manager.new
init_system
init_entry_extensions
settings = build_settings().freeze
require_teracy_dev_version(settings['teracy-dev']['require_version'])
configure_vagrant(settings)
Expand All @@ -38,24 +35,11 @@ def start
private

def init_system
@system_settings = YAML.load_file(File.join(File.dirname(__FILE__), '../../system.yaml'))
@logger.debug("init_system: @system_settings: #{@system_settings}")
system_settings = YAML.load_file(File.join(File.dirname(__FILE__), '../../system.yaml'))
@logger.debug("init_system: system_settings: #{system_settings}")
# versions requirements
Vagrant.require_version @system_settings['vagrant']['require_version']
TeracyDev::Plugin.sync(@system_settings['vagrant']['plugins'])
@extensionManager.install(@system_settings['teracy-dev']['extensions'])
end

def init_entry_extensions
# install extensions from EXTENSION_ENTRY
entry_path = File.join(TeracyDev::BASE_DIR, TeracyDev::EXTENSION_ENTRY_PATH)
@logger.debug("init_entry_extensions: entry_path: #{entry_path}")
if File.exist? entry_path
entry_settings = Util.build_settings_from(File.join(entry_path, "config_default.yaml"))
@logger.debug("init_entry_extensions: entry_settings: #{entry_settings}")
extensions = entry_settings['teracy-dev'] ? entry_settings['teracy-dev']['extensions'] || [] : []
@extensionManager.install(extensions)
end
Vagrant.require_version system_settings['vagrant']['require_version']
TeracyDev::Plugin.sync(system_settings['vagrant']['plugins'])
end


Expand All @@ -71,8 +55,6 @@ def build_settings
def load_extension_entry_files(settings)
@logger.debug("load_extension_entry_files: #{settings}")
extensions = settings['teracy-dev']['extensions'] ||= []
system_extensions = @system_settings['teracy-dev']['extensions']
extensions = [system_extensions, extensions].flatten
extensions.each do |extension|
next if extension['enabled'] != true
lookup_path = File.join(TeracyDev::BASE_DIR, extension['path']['lookup'] || 'extensions')
Expand Down
23 changes: 12 additions & 11 deletions lib/teracy-dev/settings/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative '../logging'
require_relative '../util'
require_relative '../extension/manager'

module TeracyDev
module Settings
Expand All @@ -15,16 +16,23 @@ def initialize
end
@@instance = self
@logger = Logging.logger_for(self.class.name)
@extensionManager = Extension::Manager.new
end

# build teracy-dev, entry extension and extensions setting levels
# then override: entry extension => extensions => teracy-dev
# the latter extension will override the former one to build extensions settings
def build_settings(entry_dir_path)

@logger.debug("build_settings: #{entry_dir_path}")
teracy_dev_settings = build_teracy_dev_settings()
entry_settings = build_entry_settings(entry_dir_path)
extensions_settings = build_extensions_settings(entry_settings)
# we use extensions config from entry overriding teracy-dev only to install and validate
entry_extensions = Util.override(teracy_dev_settings, entry_settings)['teracy-dev']['extensions']
@logger.debug("build_settings: entry_extensions: #{entry_extensions}")
@extensionManager.install(entry_extensions)

extensions_settings = build_extensions_settings(entry_extensions)

settings = Util.override(teracy_dev_settings, extensions_settings)
@logger.debug("override(teracy_dev_settings, extensions_settings): #{settings}")
Expand Down Expand Up @@ -58,15 +66,8 @@ def build_entry_settings(lookup_dir)
end


def build_extensions_settings(entry_settings)
system_settings = YAML.load_file(File.join(File.dirname(__FILE__), '../../../system.yaml'))
system_extensions = system_settings['teracy-dev']['extensions']
# we append extensions from system_settings here
@logger.debug("build_extensions_settings: system_extensions: #{system_extensions}")

extensions = entry_settings['teracy-dev'] ? entry_settings['teracy-dev']['extensions'] || [] : []
extensions = [system_extensions, extensions].flatten
@logger.debug("build_extensions_settings: #{extensions}")
def build_extensions_settings(extensions)
@logger.debug("build_extensions_settings: extensions: #{extensions}")
extensions_settings = []
extensions.each do |extension|
next if extension['enabled'] != true
Expand All @@ -78,7 +79,7 @@ def build_extensions_settings(entry_settings)
extensions_settings.reverse_each do |extension_settings|
settings = Util.override(extension_settings, settings)
end
@logger.debug("build_extensions_settings: #{settings}")
@logger.debug("build_extensions_settings: settings: #{settings}")
settings
end

Expand Down
18 changes: 0 additions & 18 deletions system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,3 @@ vagrant:
# - name: wisper
# version: ""
# state: installed # or uninstalled


teracy-dev:
extensions:
- _id: "0"
path:
lookup: extensions # we can configure where to lookup for the extension, "extensions" by default if no configured
extension: teracy-dev-core # extension_path, we'll lookup the extension by its lookup_path + extension_path
location: # auto download the extension into the lookup_path
git: https://github.com/hoatle/teracy-dev-core.git
# ref:
# tag:
branch: develop
require_version: ">= 0.1.0-SNAPSHOT"
enabled: true # when true, extension will be auto-downloaded if not available yet and will load this extension to be used
# extension must have manifest.yaml file to describe its name, version and optional description
# optional: config_default.yaml, teracy-dev-ext.rb will be auto loaded if available

0 comments on commit 4022471

Please sign in to comment.