Class: WebfaceGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- WebfaceGenerator
- Defined in:
- lib/generators/webface_generator.rb
Instance Method Summary collapse
- #add_node_modules_to_gitignore ⇒ Object
- #add_webface ⇒ Object
- #copy_package_json ⇒ Object
- #copy_unit_test_server ⇒ Object
- #create_symlinks ⇒ Object
- #create_webface_unit_test_dir ⇒ Object
- #install_node_modules ⇒ Object
Instance Method Details
#add_node_modules_to_gitignore ⇒ Object
47 48 49 50 |
# File 'lib/generators/webface_generator.rb', line 47 def add_node_modules_to_gitignore `echo "spec/webface/node_modules" >> #{@root_path}/.gitignore` unless File.read("#{@root_path}/.gitignore").include?("spec/webface/node_modules") `echo "app/assets/javascripts/node_modules" >> #{@root_path}/.gitignore` unless File.read("#{@root_path}/.gitignore").include?("app/assets/javascripts/node_modules") end |
#add_webface ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/webface_generator.rb', line 6 def add_webface @root_path = ["root_path"].present? ? ["root_path"] : Rails.root # We'll later change this to fetching webface.js as a node_module, but not now. gitmodules = File.readlines("#{@root_path}/.gitmodules") if File.file?("#{@root_path}/.gitmodules") if gitmodules.nil? || !gitmodules.join("\n").include?("webface.js.git") `rm -rf #{@root_path}/.git/modules/app/assets/javascripts/webface.js` `cd #{@root_path}/app/assets/javascripts/ && git submodule add [email protected]:hodl/webface.js.git` gitmodules = File.readlines("#{@root_path}/.gitmodules") if File.file?("#{@root_path}/.gitmodules") end gitmodules.each do |line| if line.include?("webface") && line.include?("path =") @webface_path = line.strip.sub(/\Apath = /, "") end end puts "Webface path is #{@webface_path}" end |
#copy_package_json ⇒ Object
52 53 54 55 |
# File 'lib/generators/webface_generator.rb', line 52 def copy_package_json copy_file "#{@root_path}/#{@webface_path}/package.json", "app/assets/javascripts/package.json" copy_file "#{@root_path}/#{@webface_path}/package-lock.json", "app/assets/javascripts/package-lock.json" end |
#copy_unit_test_server ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/webface_generator.rb', line 31 def copy_unit_test_server copy_file "webface_test_server.js", "spec/webface/test_server.js" copy_file "run_webface_test", "spec/webface/run_test" `chmod +x #{@root_path}/spec/webface/run_test` copy_file "mocha.css", "spec/webface/mocha.css" copy_file "mocha.pug", "spec/webface/mocha.pug" copy_file "test_utils.js", "spec/webface/test_utils.js" copy_file "webface.test.js", "spec/webface/webface.test.js" copy_file "webface_init.js", "spec/webface/webface_init.js" copy_file "test_animator.js", "spec/webface/test_animator.js" copy_file "my_component.test.js", "spec/webface/components/my_component.test.js" copy_file "application.js", "app/assets/javascripts/application.js" gsub_file "app/assets/javascripts/application.js", "path_to_webface", @webface_path.sub(/\A.*app\/assets\/javascripts\//, "") + "/lib" end |
#create_symlinks ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/generators/webface_generator.rb', line 57 def create_symlinks create_symlink("#{@root_path}/app/assets/javascripts", "#{@root_path}/spec/webface/source") create_symlink("#{@root_path}/app/assets/javascripts/node_modules", "#{@root_path}/spec/webface/node_modules") create_symlink("#{@root_path}/#{@webface_path}", "#{@root_path}/spec/webface/webface_source") create_symlink "#{@root_path}/app/assets/javascripts/package.json", "#{@root_path}/spec/webface/package.json" create_symlink "#{@root_path}/app/assets/javascripts/package-lock.json", "#{@root_path}/spec/webface/package-lock.json" end |
#create_webface_unit_test_dir ⇒ Object
26 27 28 29 |
# File 'lib/generators/webface_generator.rb', line 26 def create_webface_unit_test_dir `mkdir -p #{@root_path}/spec/webface/` `mkdir -p #{@root_path}/spec/webface/components/` end |
#install_node_modules ⇒ Object
65 66 67 |
# File 'lib/generators/webface_generator.rb', line 65 def install_node_modules puts `cd #{@root_path}/app/assets/javascripts && npm i` end |