Class: MermaidCLI
- Inherits:
-
Object
- Object
- MermaidCLI
- Defined in:
- lib/mermaid_cli.rb
Instance Method Summary collapse
- #app_dir ⇒ Object
- #compile(src_path, dest_pdf_path) ⇒ Object
- #config_path ⇒ Object
- #css_path ⇒ Object
- #ensure_latest_mermaid ⇒ Object
- #install_mermaid ⇒ Object
- #mermaid_installed? ⇒ Boolean
- #new_mermaid_path ⇒ Object
- #old_mermaid_path ⇒ Object
- #puppeteer_config_path ⇒ Object
- #use_latest_mermaid_for_cli ⇒ Object
- #yarn_installed? ⇒ Boolean
Instance Method Details
#app_dir ⇒ Object
26 27 28 |
# File 'lib/mermaid_cli.rb', line 26 def app_dir File.("../", __dir__) end |
#compile(src_path, dest_pdf_path) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mermaid_cli.rb', line 52 def compile(src_path, dest_pdf_path) parts = [ "yarn", "run", "mmdc", "-i", src_path, "-C", css_path, "-c", config_path, "-p", puppeteer_config_path, "-o", dest_pdf_path ].map { |part| Shellwords.escape(part) } cmd = parts.join(" ") Dir.chdir app_dir do ensure_latest_mermaid { system cmd } end end |
#config_path ⇒ Object
73 74 75 |
# File 'lib/mermaid_cli.rb', line 73 def config_path File.("../mermaid.json", __dir__) end |
#css_path ⇒ Object
69 70 71 |
# File 'lib/mermaid_cli.rb', line 69 def css_path File.("../mermaid.css", __dir__) end |
#ensure_latest_mermaid ⇒ Object
20 21 22 23 24 |
# File 'lib/mermaid_cli.rb', line 20 def ensure_latest_mermaid raise "Yarn not installed" unless yarn_installed? install_mermaid if !mermaid_installed? yield end |
#install_mermaid ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/mermaid_cli.rb', line 30 def install_mermaid puts "mermaid not installed. Installing..." Dir.chdir app_dir do if system("yarn install") use_latest_mermaid_for_cli end end end |
#mermaid_installed? ⇒ Boolean
16 17 18 |
# File 'lib/mermaid_cli.rb', line 16 def mermaid_installed? File.exist?(old_mermaid_path) && File.exist?(new_mermaid_path) end |
#new_mermaid_path ⇒ Object
43 44 45 |
# File 'lib/mermaid_cli.rb', line 43 def new_mermaid_path File.("../node_modules/mermaid/dist/mermaid.min.js", __dir__) end |
#old_mermaid_path ⇒ Object
39 40 41 |
# File 'lib/mermaid_cli.rb', line 39 def old_mermaid_path File.("../node_modules/mermaid.cli/mermaid.min.js", __dir__) end |
#puppeteer_config_path ⇒ Object
77 78 79 |
# File 'lib/mermaid_cli.rb', line 77 def puppeteer_config_path File.("../puppeteer.json", __dir__) end |
#use_latest_mermaid_for_cli ⇒ Object
47 48 49 50 |
# File 'lib/mermaid_cli.rb', line 47 def use_latest_mermaid_for_cli puts "Upgrading mermaid for cli" FileUtils.cp(new_mermaid_path, old_mermaid_path) end |
#yarn_installed? ⇒ Boolean
6 7 8 9 10 11 12 13 14 |
# File 'lib/mermaid_cli.rb', line 6 def yarn_installed? yarn = `which yarn` puts "Yarn resolved to #{yarn}" if yarn.nil? || yarn == "" return false end true end |