adds(addon_loader) a generator that creates a js file with available addons

Signed-off-by: zmagod <zmago_devetak@yahoo.com>
This commit is contained in:
zmagod 2018-01-16 14:18:31 +01:00
parent fc5daabb73
commit 3e95503017

View file

@ -1,17 +1,28 @@
# This code fetch the components from the addons but only in the root of the
# addon/**/client folder.
TARGET_ROOT = "#{Dir.pwd}/app/javascript/src/componentLoader/components".freeze
begin
# clear previous build
FileUtils.rm_f Dir.glob("#{TARGET_ROOT}/*")
available_addons = []
Dir.foreach('addons/') do |path|
addons_client_root = "addons/#{path}/client"
next unless Dir.exist? addons_client_root
available_addons << path
File.symlink("#{Dir.pwd}/#{addons_client_root}", "#{TARGET_ROOT}/#{path}")
end
# generate a file with available addons
if available_addons.any?
file_name = "#{Dir.pwd}/app/javascript/src/componentLoader/availableAddons.js"
# remove if already exists
FileUtils.rm_f Dir.glob(file_name)
File.new(file_name, 'w+')
File.open(file_name, 'w') do |file|
file.write("export default #{available_addons};")
end
end
# handles error on the platforms that does not support symlink
# http://ruby-doc.org/core-2.2.0/File.html#symlink-method
rescue