Ember Engines通过ember-cli-rails进入Rails引擎

时间:2016-12-15 13:37:26

标签: ruby-on-rails ruby ember.js ember-cli ember-cli-rails

我们有一个高模块化的rails5应用程序,它在多个存储库中的rails引擎中分离,并作为ruby gems集成。

现在我们要使用ember-cli-rails介绍EmberJS。主rails应用程序包含frontend目录中的主要ember应用程序,而每个rails引擎在ember-engine目录中包含一个ember引擎(通过frontend)。

如何将模块的余烬引擎安装到主要的余烬引擎中?

1 个答案:

答案 0 :(得分:1)

由于到目前为止我还没有找到其他解决方案,我已经创建了一个初始化程序,它将所有rails引擎的ember引擎目录符号链接到消耗的ember引擎的node_modules中。消费轨道应用程序:

# Get the node_modules dir
nm_dir = Rails.root.join('frontend', 'node_modules')

# Delete existing symlinks
Dir.new(nm_dir.to_s).each { |entry| FileUtils.rm_rf(entry) if entry =~ /^.+\-frontend$/ }

# MODULES contains an array of the rails engine gem names
MODULES.each do |module_name|
  # Each module has a Manifest class, load that
  manifest = load_manifest(module_name)

  # Get the path to the frontend dir of the rails engine
  source = Pathname.new(manifest.method(:setup).source_location[0].split('/lib/')[0]).join('frontend').to_s

  # Symlink destination
  destination = nm_dir.join("#{module_name}-frontend").to_s

  # Symlink it
  FileUtils.symlink source, destination, force: true
end

这种方法可能不是很干净,但似乎有效。