-
-
Notifications
You must be signed in to change notification settings - Fork 629
Expand file tree
/
Copy pathRakefile
More file actions
184 lines (163 loc) · 5.86 KB
/
Copy pathRakefile
File metadata and controls
184 lines (163 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# frozen_string_literal: true
require "bundler"
# Root Rakefile for monorepo-level tasks
#
# Package-specific task implementations live in the package Rakefiles and run
# with that package's bundle. The root Rakefile keeps compatibility wrappers for
# common root commands without loading package dependencies into the root bundle.
#
# This keeps the root bundle focused on lint/tooling/release gems while Rake still
# auto-loads monorepo-level tasks from ./rakelib/.
#
# Note: This is for development only. When the gem is installed in a Rails app,
# Rails::Engine handles rake task loading automatically from lib/tasks/.
# Define gem_root helper for use by rake tasks
def gem_root
File.expand_path("react_on_rails", __dir__)
end
@package_bundle_ready = false
def package_rake_task(task_name, *task_args)
task_invocation = if task_args.empty?
task_name.to_s
else
"#{task_name}[#{task_args.join(',')}]"
end
ensure_package_bundle
Dir.chdir(gem_root) do
Bundler.with_unbundled_env do
sh "bundle", "exec", "rake", task_invocation
end
end
end
def ensure_package_bundle
return if @package_bundle_ready
bundle_ready = Dir.chdir(gem_root) do
Bundler.with_unbundled_env do
system("bundle", "check", out: File::NULL, err: File::NULL)
end
end
if bundle_ready
@package_bundle_ready = true
return
end
puts "Installing react_on_rails bundle before delegated rake task..."
Dir.chdir(gem_root) do
Bundler.with_unbundled_env do
sh "bundle", "install"
end
end
@package_bundle_ready = true
end
def root_bundle_exec_in(directory, *command)
Bundler.with_unbundled_env do
Dir.chdir(directory) do
sh({ "BUNDLE_GEMFILE" => File.expand_path("Gemfile", __dir__) }, "bundle", "exec", *command)
end
end
end
def root_rubocop_paths
# Root lint covers repo-root tooling only; package-owned rakelib files stay under package RuboCop.
%w[Gemfile Rakefile rakelib script/pr-merge-ledger]
end
def define_package_task(task_name, *arg_names)
desc "Delegates to react_on_rails #{task_name}"
task task_name, arg_names do |_task, args|
package_rake_task(task_name, *arg_names.filter_map { |arg_name| args[arg_name] })
end
end
namespace :lint do
desc "Run root-bundle RuboCop on root tooling files"
task :rubocop do
root_bundle_exec_in(__dir__, "rubocop", *root_rubocop_paths)
end
desc "Auto-fix root-bundle RuboCop violations in root tooling files"
task :rubocop_autofix do
root_bundle_exec_in(__dir__, "rubocop", "-A", *root_rubocop_paths)
puts "Completed root RuboCop auto-fix"
end
end
# MAINTAINER NOTE: When adding a package Rake task that should work from the
# monorepo root, add it here so `rake <task>` delegates into the react_on_rails
# bundle.
# Audit drift:
# diff <(bundle exec rake -T | awk '{print $2}' | sort) \
# <(cd react_on_rails && bundle exec rake -T | awk '{print $2}' | sort)
%w[
all_but_examples
ci
default
docker
docker:eslint
docker:lint
docker:rubocop
docker:scss
dummy_apps
js_tests
lint:autofix
lint:eslint
lint:scss
node_package
prepare_for_ci
rbs:all
rbs:check
rbs:list
rbs:steep
rbs:validate
run_rspec
run_rspec:all_but_examples
run_rspec:all_dummy
run_rspec:dummy
run_rspec:dummy_no_turbolinks
run_rspec:gem
run_rspec:shakapacker_examples
run_rspec:shakapacker_examples_basic
run_rspec:shakapacker_examples_basic-react16
run_rspec:shakapacker_examples_basic-react17
run_rspec:shakapacker_examples_basic-react18
run_rspec:shakapacker_examples_basic-server-rendering
run_rspec:shakapacker_examples_basic-server-rendering-react16
run_rspec:shakapacker_examples_basic-server-rendering-react17
run_rspec:shakapacker_examples_basic-server-rendering-react18
run_rspec:shakapacker_examples_latest
run_rspec:shakapacker_examples_pinned
run_rspec:shakapacker_examples_react16
run_rspec:shakapacker_examples_react17
run_rspec:shakapacker_examples_react18
run_rspec:shakapacker_examples_redux
run_rspec:shakapacker_examples_redux-server-rendering
shakapacker_examples
shakapacker_examples:clobber
shakapacker_examples:clobber_basic
shakapacker_examples:clobber_basic-react16
shakapacker_examples:clobber_basic-react17
shakapacker_examples:clobber_basic-react18
shakapacker_examples:clobber_basic-server-rendering
shakapacker_examples:clobber_basic-server-rendering-react16
shakapacker_examples:clobber_basic-server-rendering-react17
shakapacker_examples:clobber_basic-server-rendering-react18
shakapacker_examples:clobber_redux
shakapacker_examples:clobber_redux-server-rendering
shakapacker_examples:gen_all
shakapacker_examples:gen_basic
shakapacker_examples:gen_basic-react16
shakapacker_examples:gen_basic-react17
shakapacker_examples:gen_basic-react18
shakapacker_examples:gen_basic-server-rendering
shakapacker_examples:gen_basic-server-rendering-react16
shakapacker_examples:gen_basic-server-rendering-react17
shakapacker_examples:gen_basic-server-rendering-react18
shakapacker_examples:gen_redux
shakapacker_examples:gen_redux-server-rendering
].each { |task_name| define_package_task(task_name) }
desc "Run root-bundle RuboCop only; full lint: cd react_on_rails && bundle exec rake lint"
task lint: ["lint:rubocop"] do
puts "For full package lint: cd react_on_rails && bundle exec rake lint"
end
desc "Auto-fix full package lint; broader than root rake lint (ESLint, Prettier, Stylelint, RuboCop)"
task autofix: ["lint:autofix"]
define_package_task("run_rspec:run_rspec", :packer)
define_package_task("shakapacker:update_version", :version)
define_package_task("update_changelog", :mode_or_tag)
# NOTE: Monorepo-level rake tasks from ./rakelib/ are auto-loaded by Rake.
# Do NOT explicitly load them here, as that would cause tasks to be defined twice
# and their bodies would run twice (Rake appends duplicate task definitions).