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
27 28 29 |
# File 'lib/mermaid_cli.rb', line 27 def app_dir File.("../", __dir__) end |
#compile(src_path, dest_pdf_path) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mermaid_cli.rb', line 53 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
74 75 76 |
# File 'lib/mermaid_cli.rb', line 74 def config_path File.("../mermaid.json", __dir__) end |
#css_path ⇒ Object
70 71 72 |
# File 'lib/mermaid_cli.rb', line 70 def css_path File.("../mermaid.css", __dir__) end |
#ensure_latest_mermaid ⇒ Object
20 21 22 23 24 25 |
# File 'lib/mermaid_cli.rb', line 20 def ensure_latest_mermaid raise "Yarn not installed" unless yarn_installed? install_mermaid use_latest_mermaid_for_cli yield end |
#install_mermaid ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/mermaid_cli.rb', line 31 def install_mermaid puts "mermaid not installed. Installing..." unless mermaid_installed? Dir.chdir app_dir do system("yarn install") 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
44 45 46 |
# File 'lib/mermaid_cli.rb', line 44 def new_mermaid_path File.("../node_modules/mermaid/dist/mermaid.min.js", __dir__) end |
#old_mermaid_path ⇒ Object
40 41 42 |
# File 'lib/mermaid_cli.rb', line 40 def old_mermaid_path File.("../node_modules/mermaid.cli/mermaid.min.js", __dir__) end |
#puppeteer_config_path ⇒ Object
78 79 80 |
# File 'lib/mermaid_cli.rb', line 78 def puppeteer_config_path File.("../puppeteer.json", __dir__) end |
#use_latest_mermaid_for_cli ⇒ Object
48 49 50 51 |
# File 'lib/mermaid_cli.rb', line 48 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 |