How to bundle AsciiDoctor gems in a Cocoa app
Asked Answered
K

0

9

My app

I have a Mac app that uses AsciiDoctor under the hood to generate PDF and ePUB files. I use the Process class (formerly NSTask) to run the AsciiDoctor commands.

What I want

I want people to be able to use my app without having to manually install the AsciiDoctor Ruby gems from the Terminal.

Copying the gems to the app bundle

My first attempt was to install the AsciiDoctor gems in a custom folder on my Mac and add a Copy Files build phase to my Xcode project to copy the folder with the gems into the app bundle. Adding the gems to the app bundle worked on my machine but didn't work well on other machines. I couldn't create PDF or EPUB files on systems with a different version of Ruby than the version on my Mac that I used to install the gems. On a macOS 10.13 virtual machine, I was able to create a PDF file but not an EPUB file.

Installing the gems in the Application Support folder

My second attempt was to install the gems in my app's Application Support folder the first time someone launches the app. But that didn't even work on my machine. When I used the launch path usr/bin/ruby for the command-line process and the following argument list:

let argumentList = ["gem", "install", "-i", gemFolder.path, gem, "--pre"]

Where the variable gemFolder.path is the path to the Application Support folder and the variable gem is either "asciidoctor-pdf" or "asciidoctor-epub3".

I got the following error message from standard error when running the command-line process:

/usr/bin/ruby: No such file or directory -- gem (LoadError)

When I used the launch path gem or gem install, calling the Process method run threw an exception. Here are the error messages the exception threw.

Error Domain=NSCocoaErrorDomain Code=4 "The file “gem” doesn’t exist." UserInfo={NSFilePath=gem}

Error Domain=NSCocoaErrorDomain Code=4 "The file “gem install” doesn’t exist." UserInfo={NSFilePath=gem install}

Question

How do I include the AsciiDoctor gems in my app so people don't have to manually install the gems? Do I need to create an installer for the app?

Klara answered 11/2, 2019 at 22:35 Comment(3)
When I used the launch path gem or gem install, calling the Process method run threw an exception. — what exception?Hospitable
I updated the question with the exception messages.Klara
It should be /usr/bin/gem and ["install", "-i", gemFolder.path, gem, "--pre"] for arguments.Hospitable

© 2022 - 2024 — McMap. All rights reserved.