mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 07:05:57 +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
|
TARGET_ROOT = "#{Dir.pwd}/app/javascript/src/componentLoader/components".freeze
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# clear previous build
|
# clear previous build
|
||||||
FileUtils.rm_f Dir.glob("#{TARGET_ROOT}/*")
|
FileUtils.rm_f Dir.glob("#{TARGET_ROOT}/*")
|
||||||
|
|
||||||
|
available_addons = []
|
||||||
Dir.foreach('addons/') do |path|
|
Dir.foreach('addons/') do |path|
|
||||||
addons_client_root = "addons/#{path}/client"
|
addons_client_root = "addons/#{path}/client"
|
||||||
next unless Dir.exist? addons_client_root
|
next unless Dir.exist? addons_client_root
|
||||||
|
available_addons << path
|
||||||
File.symlink("#{Dir.pwd}/#{addons_client_root}", "#{TARGET_ROOT}/#{path}")
|
File.symlink("#{Dir.pwd}/#{addons_client_root}", "#{TARGET_ROOT}/#{path}")
|
||||||
end
|
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
|
# handles error on the platforms that does not support symlink
|
||||||
# http://ruby-doc.org/core-2.2.0/File.html#symlink-method
|
# http://ruby-doc.org/core-2.2.0/File.html#symlink-method
|
||||||
rescue
|
rescue
|
||||||
|
|
Loading…
Add table
Reference in a new issue