From 34a016a7cbef35316499a9cb4800948e1ffa629d Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 8 Aug 2018 13:50:52 +0000 Subject: [PATCH] Vmdb::Plugins::AssetPath - add #node_modules, #development_gem?, .node_root AssetPath now knows about the path and name of each engine But to move node_modules outside of gem directories, we also need to know whether the developer will be doing chances in that particular engine or not - `#development_gem?` assumes anything installed in bundler gems will not get modified. This will enable the ui tasks to use a different node_modules path for gems, no longer polluting the gem dir. Non-development gems will use `manageiq/vendor/node_root//node_modules`, while anything *not* in bundler gems will end up with `node_modules` inside that engine's root. This only provides the info to the appropriate ui rake tasks. --- .gitignore | 1 + lib/vmdb/plugins/asset_path.rb | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 77a19a056e0..8b4948f7823 100644 --- a/.gitignore +++ b/.gitignore @@ -80,6 +80,7 @@ tmp/* # vendor/ vendor/bundle vendor/assets/bower_components/ +vendor/node_root/ # npm node_modules/ diff --git a/lib/vmdb/plugins/asset_path.rb b/lib/vmdb/plugins/asset_path.rb index 31ae5e80f2e..6574c8069ea 100644 --- a/lib/vmdb/plugins/asset_path.rb +++ b/lib/vmdb/plugins/asset_path.rb @@ -7,6 +7,7 @@ class AssetPath attr_reader :name attr_reader :path attr_reader :namespace + attr_reader :node_modules def self.asset_path(engine) engine.root.join('app', 'javascript') @@ -20,9 +21,25 @@ def initialize(engine) asset_path = self.class.asset_path(engine) raise "#{asset_path} does not exist" unless asset_path.directory? - @name = engine.name - @path = engine.root - @namespace = name.chomp("::Engine").underscore.tr("/", "-") + @name = engine.name + @path = engine.root + @namespace = name.chomp("::Engine").underscore.tr("/", "-") + @in_bundler_gems = engine.root.expand_path.to_s.start_with?(Bundler.install_path.expand_path.to_s) + + @node_modules = if @in_bundler_gems + self.class.node_root.join(@namespace) + else + @path + end.join('node_modules') + end + + def development_gem? + !@in_bundler_gems + end + + # also used in update:ui task to determine where to copy config files + def self.node_root + Rails.root.join('vendor', 'node_root') end end end