mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 13:28:53 +08:00
refactor(addons_loader): Extract paths to variables / build mega-config file
- Create variables for the paths the script impacts - Create a file to host the configuration, import each add-on config and re-export them through a single object
This commit is contained in:
parent
583efbc9c4
commit
a5ecc1a36e
1 changed files with 14 additions and 14 deletions
|
@ -1,26 +1,26 @@
|
||||||
TARGET_ROOT = "#{Dir.pwd}/app/javascript/src/componentLoader/components".freeze
|
TARGET_ROOT = "#{Dir.pwd}/app/javascript/src/componentLoader".freeze
|
||||||
|
COMPONENTS_ROOT = "#{TARGET_ROOT}/components".freeze
|
||||||
|
UBER_CONFIG_PATH = "#{TARGET_ROOT}/availableAddons.js".freeze
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# clear previous build
|
# clear previous build
|
||||||
FileUtils.rm_f Dir.glob("#{TARGET_ROOT}/*")
|
FileUtils.rm_f Dir.glob("#{COMPONENTS_ROOT}/*")
|
||||||
|
FileUtils.rm_f Dir.glob(UBER_CONFIG_PATH)
|
||||||
|
File.new(UBER_CONFIG_PATH, 'w+')
|
||||||
|
enabled_addons = []
|
||||||
|
|
||||||
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.open(UBER_CONFIG_PATH, 'w') do |file|
|
||||||
File.symlink("#{Dir.pwd}/#{addons_client_root}", "#{TARGET_ROOT}/#{path}")
|
file.puts("import #{path} from \'./components/#{path}/config.js\';")
|
||||||
|
end
|
||||||
|
enabled_addons << "#{path}"
|
||||||
|
File.symlink("#{Dir.pwd}/#{addons_client_root}", "#{COMPONENTS_ROOT}/#{path}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# generate a file with available addons
|
File.open(UBER_CONFIG_PATH, 'a') do |file|
|
||||||
if available_addons.any?
|
file.puts("export default { #{enabled_addons.join(", ").gsub(/\"/, '')} };")
|
||||||
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
|
end
|
||||||
|
|
||||||
# handles error on the platforms that does not support symlink
|
# handles error on the platforms that does not support symlink
|
||||||
|
|
Loading…
Add table
Reference in a new issue