@@ -4,6 +4,7 @@ namespace :gen do
44 require 'mgem'
55 require 'yaml'
66
7+ # mgem still uses old exists? method
78 class File
89 class << self
910 alias_method :exists? , :exist? unless method_defined? ( :exists? )
@@ -28,45 +29,52 @@ namespace :gen do
2829
2930 mgem_info . sort_by! { |g | g [ 'name' ] . downcase }
3031
31- File . open ( '_data/mgems.yml' , 'w' ) { |f | f . write ( mgem_info . to_yaml ) }
32- puts 'Written _data/mgems.yml'
32+ dest = File . join ( __dir__ , '_data' , 'mgems.yml' )
33+
34+ File . write ( dest , mgem_info . to_yaml )
35+ puts "Written #{ dest } "
3336 end
3437
3538 desc 'Regenerate API documentation from mruby source (clones latest release into mruby/)'
3639 task :mrbdoc do
3740 require 'json'
41+ require 'shellwords'
3842
3943 # Resolve latest stable release tag via gh CLI (mruby uses tags, not GitHub Releases)
40- tags = JSON . parse ( `gh api 'repos/mruby/mruby/tags?per_page=100'` )
41- tag = tags . map { |t | t [ 'name' ] } . find { |n | n . match? ( /^\d +\. \d +\. \d +$/ ) }
44+ tags = [ ]
45+ page = 1
46+ loop do
47+ batch = JSON . parse ( `gh api "repos/mruby/mruby/tags?per_page=100&page=#{ page } "` )
48+ break if batch . empty?
49+ tags . concat ( batch )
50+ break if batch . size < 100
51+ page += 1
52+ end
53+ tag = tags . map { |t | t [ 'name' ] } . find { |n | n . match? ( /^\d +\. \d +\. \d +$/ ) }
4254 raise "Could not determine latest stable mruby release tag" unless tag
4355 puts "Latest mruby release: #{ tag } "
4456
4557 # Clone mruby at the release tag (or skip if already at the right version)
4658 mruby_dir = File . join ( __dir__ , 'mruby' )
47- if Dir . exist? ( mruby_dir )
48- current_tag = `git -C #{ mruby_dir } describe --exact-match HEAD 2>/dev/null` . strip
49- if current_tag == tag
50- puts "mruby #{ tag } already cloned, skipping clone"
51- else
52- puts "mruby dir exists at #{ current_tag . empty? ? 'unknown version' : current_tag } , re-cloning at #{ tag } "
53- FileUtils . rm_rf ( mruby_dir )
54- sh "git clone --depth 1 --branch #{ tag } https://github.com/mruby/mruby.git #{ mruby_dir } "
55- end
59+ current_tag = Dir . exist? ( mruby_dir ) ? `git -C #{ Shellwords . escape ( mruby_dir ) } describe --exact-match HEAD 2>/dev/null` . strip : nil
60+ if current_tag == tag
61+ puts "mruby #{ tag } already cloned, skipping clone"
5662 else
57- sh "git clone --depth 1 --branch #{ tag } https://github.com/mruby/mruby.git #{ mruby_dir } "
63+ puts current_tag ? "mruby dir exists at #{ current_tag } , re-cloning at #{ tag } " : "Cloning mruby #{ tag } "
64+ FileUtils . rm_rf ( mruby_dir )
65+ sh "git clone --depth 1 --branch #{ Shellwords . escape ( tag ) } https://github.com/mruby/mruby.git #{ Shellwords . escape ( mruby_dir ) } "
5866 end
5967
6068 # Run mrbdoc (from yard-mruby) in the mruby directory — equivalent to doc:api
6169 Dir . chdir ( mruby_dir ) do
62- sh "BUNDLE_GEMFILE=#{ __dir__ } / Gemfile bundle exec mrbdoc"
70+ sh "env BUNDLE_GEMFILE=#{ Shellwords . escape ( File . join ( __dir__ , ' Gemfile' ) ) } bundle exec mrbdoc"
6371 end
6472
6573 # Copy generated docs into our docs/api/ directory
6674 dest = File . join ( __dir__ , 'docs' , 'api' )
6775 FileUtils . mkdir_p ( dest )
6876 FileUtils . cp_r ( Dir . glob ( "#{ mruby_dir } /doc/api/*" ) , dest )
69- puts "Copied mruby API docs to docs/api/ "
77+ puts "Copied mruby API docs to #{ dest } "
7078 end
7179
7280 desc 'Regenerate release data from GitHub API (_data/releases.yml)'
0 commit comments