Problem/Motivation

Initially, we'll assume that D2 is installed system-wide, but it'd be nice to install it within a Drupal codebase via Composer. This would simplify setup, and could allow installation of specific versions, etc.

Proposed resolution

A first pass could provide a class with some static methods to install/update D2, along the lines of DrupalProject\composer\ScriptHandler, that can be called from the scripts section of a project's composer.json.

D2 publishes releases for various OSes, architectures, etc. We should be able to install a standalone release into vendor/ by setting the PREFIX variable.

Later, we might want to consider splitting this off into a custom installer, or similar.

Comments

ergonlogic created an issue. See original summary.

ergonlogic’s picture

Title: Install D2 » Install D2 via Composer
ergonlogic’s picture

Status: Active » Postponed

Let's get a proof-of-concept working (#3565334: Generate SVG from D2 input) before proceeding on this.

ergonlogic’s picture

Version: » 1.0.x-dev
Status: Postponed » Active
ergonlogic’s picture

Adding the following to the root composer.json will download the release, and untar it to vendor/terrastruct/d2:

    "repositories": [
    [...]
        {
            "type": "package",
            "package": {
                "name": "terrastruct/d2",
                "version": "0.7.1",
                "dist": {
                    "url": "https://github.com/terrastruct/d2/releases/download/v0.7.1/d2-v0.7.1-linux-amd64.tar.gz",
                    "type": "tar"
                }
            }
        }
    ]

The compiled binary is located at d2-v0.7.1/bin/d2. It works nicely with our existing code, except that the path includes the version.

I tried adding a bin key (eg. "bin": ["d2-v0.7.1/bin/d2"]) to the above package definition (see: Composer Vendor Binaries), but to no avail. The idea would have been to then point our module code at vendor/bin/d2.

  • ergonlogic committed 497ee412 on 1.0.x
    feat: #3565332 Copy D2 binary into Composer bin directory, and use that...

  • ergonlogic committed 7637deb7 on 1.0.x
    docs: #3565332 Document how to install D2 w/ Composer
    
ergonlogic’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.