-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
73 lines (61 loc) · 2.31 KB
/
Rakefile
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
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "prettier"
require "prettier/rake/task"
RSpec::Core::RakeTask.new(:spec)
module Prettier
# Remove override of `Prettier::Rake::Task#run` once
# https://github.com/prettier/plugin-ruby/commit/ae8c13e0c468386fee941b4f49b2752ba8c40584
# is released.
def self.run(args)
quoted = args.map { |arg| arg.start_with?("-") ? arg : "\"#{arg}\"" }
command = "node #{BINARY} --plugin \"#{PLUGIN}\" #{quoted.join(" ")}"
opts = $stdin.tty? ? {} : { stdin_data: $stdin }
stdout, stderr, status = Open3.capture3({ "RBPRETTIER" => "1" }, command, opts)
$stdout.puts(stdout)
# If we completed successfully, then just exit out.
exitstatus = status.exitstatus
return exitstatus if exitstatus.zero?
if stderr.match?(%r{Cannot find module '/.+?/bin-prettier.js'})
# If we're missing bin-prettier.js, then it's possible the user installed
# the gem through git, which wouldn't have installed the requisite
# JavaScript files.
warn(<<~MSG)
Could not find the JavaScript files necessary to run prettier.
If you installed this dependency through git instead of from rubygems,
it does not install the necessary files by default. To fix this you can
either install them yourself by cd-ing into the directory where this gem
is located (#{File.expand_path("..", __dir__)}) and running:
`yarn install`
or
`npm install`
or
you can change the source in your Gemfile to point directly to rubygems.
MSG
else
# Otherwise, just print out the same error that prettier emitted, as it's
# unknown to us.
warn(stderr)
end
# Make sure we still exit with the same status code the prettier emitted.
exitstatus
end
module Rake
class Task < ::Rake::TaskLib
private
# Extend rake runner to check if we're not writing
def run_task
Prettier.run([(write ? "--write" : "--check"), source_files])
exit($CHILD_STATUS.exitstatus) if $CHILD_STATUS&.exited?
end
end
end
end
Prettier::Rake::Task.new { |t| t.source_files = "**/*" }
Prettier::Rake::Task.new do |t|
t.source_files = "**/*"
t.write = false
t.name = "prettier_check"
end
task default: :spec