mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 05:04:35 +08:00
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:
parent
fc5daabb73
commit
3e95503017
1 changed files with 14 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue