2018-01-16 23:22:00 +08:00
|
|
|
TARGET_ROOT = "#{Dir.pwd}/app/javascript/src/componentLoader".freeze
|
|
|
|
COMPONENTS_ROOT = "#{TARGET_ROOT}/components".freeze
|
|
|
|
UBER_CONFIG_PATH = "#{TARGET_ROOT}/availableAddons.js".freeze
|
2018-01-13 00:14:27 +08:00
|
|
|
|
2018-01-15 15:44:59 +08:00
|
|
|
begin
|
|
|
|
# clear previous build
|
2018-01-16 23:22:00 +08:00
|
|
|
FileUtils.rm_f Dir.glob("#{COMPONENTS_ROOT}/*")
|
|
|
|
FileUtils.rm_f Dir.glob(UBER_CONFIG_PATH)
|
|
|
|
File.new(UBER_CONFIG_PATH, 'w+')
|
|
|
|
enabled_addons = []
|
2018-01-15 15:44:59 +08:00
|
|
|
|
2018-01-13 00:14:27 +08:00
|
|
|
Dir.foreach('addons/') do |path|
|
|
|
|
addons_client_root = "addons/#{path}/client"
|
|
|
|
next unless Dir.exist? addons_client_root
|
2018-01-16 23:22:00 +08:00
|
|
|
File.open(UBER_CONFIG_PATH, 'w') do |file|
|
|
|
|
file.puts("import #{path} from \'./components/#{path}/config.js\';")
|
|
|
|
end
|
|
|
|
enabled_addons << "#{path}"
|
|
|
|
File.symlink("#{Dir.pwd}/#{addons_client_root}", "#{COMPONENTS_ROOT}/#{path}")
|
2018-01-13 00:14:27 +08:00
|
|
|
end
|
2018-01-16 21:18:31 +08:00
|
|
|
|
2018-01-16 23:22:00 +08:00
|
|
|
File.open(UBER_CONFIG_PATH, 'a') do |file|
|
|
|
|
file.puts("export default { #{enabled_addons.join(", ").gsub(/\"/, '')} };")
|
2018-01-16 21:18:31 +08:00
|
|
|
end
|
|
|
|
|
2018-01-15 15:44:59 +08:00
|
|
|
# handles error on the platforms that does not support symlink
|
|
|
|
# http://ruby-doc.org/core-2.2.0/File.html#symlink-method
|
2018-01-16 17:54:11 +08:00
|
|
|
rescue
|
2018-01-15 15:44:59 +08:00
|
|
|
puts '[sciNote] Unable to load React components from addons!'
|
|
|
|
puts '[sciNote] Your system does not support symlink!'
|
|
|
|
end
|