summaryrefslogtreecommitdiff
path: root/Rakefile
blob: 46842bf25a2f2a8f12713361b9dbff31c1f7c876 (plain)
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
require 'bundler/gem_tasks'

begin
  require 'rspec/core/rake_task'

  RSpec::Core::RakeTask.new(:spec)

  task :test => :spec
  task :default => :spec
rescue LoadError => e
  warn "#{e.path} is not available"
end

begin
  require 'rubocop/rake_task'

  RuboCop::RakeTask.new(:rubocop) do |t|
    t.options = ['--display-cop-names', '--fail-level', 'W']
  end

  task :default => :rubocop
rescue LoadError => e
  warn "#{e.path} is not available"
end

task :readme2md do
  require 'asciidoctor'
  require 'pandoc-ruby'

  docbook = Asciidoctor
    .load_file('README.adoc', header_footer: true, backend: 'docbook')
    .convert
  markdown = PandocRuby
    .convert(docbook, from: :docbook, to: :markdown_github)

  File.write('README.md', markdown)
end

namespace :build do
  desc 'Transcompile to JavaScript using Opal'
  task :js do
    require 'opal'

    builder = Opal::Builder.new(compiler_options: {
      dynamic_require_severity: :error,
    })
    builder.append_paths 'lib'
    builder.build 'asciidoctor/interdoc_reftext'

    out_file = 'dist/asciidoctor-interdoc-reftext.js'

    mkdir_p(File.dirname(out_file), verbose: false)
    File.open(out_file, 'w') do |file|
      template = File.read('src/asciidoctor-interdoc-reftext.tmpl.js')
      file << template.sub('//OPAL-GENERATED-CODE//') { builder.to_s }
    end
    File.binwrite "#{out_file}.map", builder.source_map
  end
end