Skip to content

Commit 06a9c66

Browse files
committed
Add bin/gen-sig
1 parent d96f8b9 commit 06a9c66

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Gemfile.devtools

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
gem "rake", ">= 12.3.3"
66

7+
group :sig do
8+
gem "rbs"
9+
gem "rbs-inline"
10+
end
11+
712
group :test do
813
gem "simplecov", require: false, platforms: :ruby
914
gem "simplecov-cobertura", require: false, platforms: :ruby

bin/gen-sig

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "fileutils"
5+
require "pathname"
6+
7+
root_path = Pathname.new(File.expand_path("../", __dir__))
8+
9+
manifest_path = root_path.join("sig/manifest.yaml")
10+
manifest = manifest_path.exist? ? manifest_path.read : "dependencies: []"
11+
12+
FileUtils.rm_rf(root_path.join("sig"))
13+
14+
system "rbs-inline lib --opt-out --output=./sig"
15+
16+
EMPTY_COMMENT_BEFORE_CODE = /
17+
^[ \t]*\#[ \t]*\n
18+
(?=^[ \t]*[^#\s])
19+
/mx
20+
EMPTY_STRING = ""
21+
GENERATED_LINE = /^ *# Generated from .+.rb with RBS::Inline *$/
22+
RBS_COMMENT_BLOCK = /
23+
^[ \t]*\#[ \t]*@rbs.*\n
24+
(?:^[ \t]*\#.*\n)*
25+
/x
26+
27+
root_path.glob("sig/**/*.rbs").each do |file|
28+
contents = file.read
29+
30+
contents.gsub!(GENERATED_LINE, EMPTY_STRING)
31+
&.gsub!(RBS_COMMENT_BLOCK, EMPTY_STRING)
32+
&.gsub!(EMPTY_COMMENT_BEFORE_CODE, EMPTY_STRING)
33+
&.strip
34+
35+
if contents.nil? || contents.strip.empty?
36+
File.delete(file)
37+
else
38+
File.write(file, "#{contents}\n")
39+
end
40+
end
41+
42+
File.write(manifest_path, manifest)

0 commit comments

Comments
 (0)