Class: P2pStreamsChannel::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/p2p_streams_channel/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_p2pObject



8
9
10
11
# File 'lib/rails/generators/p2p_streams_channel/install_generator.rb', line 8

def copy_p2p
  empty_directory "vendor/javascript/p2p"
  directory "p2p", "vendor/javascript/p2p"
end

#create_initializerObject



26
27
28
# File 'lib/rails/generators/p2p_streams_channel/install_generator.rb', line 26

def create_initializer
  copy_file "initializer.rb", "config/initializers/p2p_streams_channel.rb"
end

#importmapObject



13
14
15
16
17
18
# File 'lib/rails/generators/p2p_streams_channel/install_generator.rb', line 13

def importmap
  return unless (importmap_path = Rails.root.join("config/importmap.rb")).exist?
  
  append_to_file importmap_path, %(\npin_all_from "vendor/javascript/p2p", under: "p2p"\n)
  append_to_file Rails.root.join("app/assets/config/manifest.js"), %(\n//= link_tree ../../../vendor/javascript .js\n)
end

#nodeObject



20
21
22
23
24
# File 'lib/rails/generators/p2p_streams_channel/install_generator.rb', line 20

def node
  return unless Rails.root.join("package.json").exist?

  run "yarn add p2p@file:vendor/javascript/p2p"
end