class Nor::FrontendGenerator

Attributes

frontend_path[R]

Public Class Methods

new(args, *options) click to toggle source
Calls superclass method
# File lib/generators/nor/frontend/frontend_generator.rb, line 6
def initialize(args, *options)
  super
  @frontend_path = File.join(destination_root, 'frontend')
end

Public Instance Methods

create_next_app() click to toggle source
# File lib/generators/nor/frontend/frontend_generator.rb, line 11
def create_next_app
  if revoke? && frontend_exist?
    say_status :remove, relative_to_original_destination_root(frontend_path)
    FileUtils.remove_dir(frontend_path, force: true)
  elsif frontend_exist?
    say_status('skipped', 'Create Next app: directory frontend already exist!')
  else
    run 'yarn create next-app frontend'
    inside frontend_path do
      gsub_file 'package.json', 'create-next-example-app', 'next-on-rails-frontend'
      gsub_file 'package.json', '"dev": "next dev"', '"dev": "node server.js"'
      if `which json`.present?
        run "json -I -f package.json -e 'this.license=\"MIT\"'"
        run "json -I -f package.json -e 'this.private=true'"
        run "json -I -f package.json -e 'this.version=\"0.1.0\"'"
      end
      remove_file 'components/head.js'
      remove_file 'components/nav.js'
      remove_file 'pages/index.js'
      remove_file 'next.config.js'
    end
  end
end
install_dependencies() click to toggle source
# File lib/generators/nor/frontend/frontend_generator.rb, line 35
def install_dependencies
  return if revoke?

  inside frontend_path do
    run 'yarn add next-compose-plugins @zeit/next-sass node-sass bootstrap compression express inflection lodash nookies nprogress next-on-rails next@8.1.0 react@16.8.6 react-dom@16.8.6'
    run 'yarn add --dev babel-eslint eslint eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-react eslint-plugin-standard prettier sass-lint'
  end
end
install_templates() click to toggle source
# File lib/generators/nor/frontend/frontend_generator.rb, line 44
def install_templates
  return if revoke?

  directory 'frontend'
end

Protected Instance Methods

frontend_exist?() click to toggle source
# File lib/generators/nor/frontend/frontend_generator.rb, line 52
def frontend_exist?
  File.exist?(frontend_path)
end
revoke?() click to toggle source
# File lib/generators/nor/frontend/frontend_generator.rb, line 56
def revoke?
  behavior == :revoke
end