Class: Trek::Generators::Install::YarnGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/generators/trek/install/yarn_generator.rb

Constant Summary collapse

YARN_VERSION =
"4.17.0"

Instance Method Summary collapse

Instance Method Details

#create_yarnrcObject



36
37
38
39
40
41
42
# File 'lib/generators/trek/install/yarn_generator.rb', line 36

def create_yarnrc
  if File.exist?(".yarnrc.yml")
    prepend_to_file ".yarnrc.yml", yarnrc_content
  else
    create_file ".yarnrc.yml", [yarnrc_content, ""].join("\n")
  end
end

#fix_bin_setupObject

The default bin/setup (generated by rails new -j esbuild) runs yarn install --check-files, but --check-files is not a valid flag under Yarn berry (the version we pin above), so it breaks bin/setup in CI. Drop the flag.



48
49
50
# File 'lib/generators/trek/install/yarn_generator.rb', line 48

def fix_bin_setup
  gsub_file "bin/setup", "yarn install --check-files", "yarn install"
end

#insert_gitignoreObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/trek/install/yarn_generator.rb', line 20

def insert_gitignore
  insert_into_file ".gitignore",
    <<~GITIGNORE

      # Yarn
      .pnp.*
      .yarn/*
      !.yarn/patches
      !.yarn/plugins
      !.yarn/releases
      !.yarn/sdks
      !.yarn/versions
      yarn-error.log
    GITIGNORE
end

#set_versionObject



16
17
18
# File 'lib/generators/trek/install/yarn_generator.rb', line 16

def set_version
  run "yarn set version #{YARN_VERSION}", abort_on_failure: true
end