Sha256: d82ff5e96ba5abb28167dd908482e235e7975a091c18566f8cf98c01b3b1b89d

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module SewingKit
  class InstallGenerator < Rails::Generators::Base
    source_root File.expand_path('templates', __dir__)
    class_option :skip_yarn, type: :boolean, default: false

    desc "This generator creates a sewing-kit config file."

    def initialize(args, *options)
      @application_name = Rails.application.class.module_parent.to_s.underscore
      super(args, *options)
    end

    def create_package_json
      package_json_path = "package.json"

      copy_file(package_json_path)
      gsub_file(package_json_path, "\${application_name}", @application_name)
    end

    def install_js_dependencies
      return if options.skip_yarn?

      say "Installing react and types dependencies"
      system("yarn add @shopify/sewing-kit")
    end

    def create_sk_config
      sk_config_path = "config/sewing-kit.config.ts"

      copy_file("sewing-kit.config.ts", sk_config_path)
      gsub_file(sk_config_path, "\${application_name}", @application_name)
    end

    def create_config_files
      copy_file("editorconfig", ".editorconfig")
      copy_file("eslintignore", ".eslintignore")
      copy_file("prettierignore", ".prettierignore")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sewing_kit-0.127.0 lib/generators/sewing_kit/install_generator.rb