asciidoctor / asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
https://asciidoctor.github.io/asciidoctor-gradle-plugin/
Apache License 2.0
286 stars 122 forks source link

Mermaid diagram generation failure starting v3.3.0 #622

Open Xendar opened 3 years ago

Xendar commented 3 years ago

Hello,

I am using Gradle, Asciidoctor Gradle plugin, Asciidoctorj, and Mermaid to generate diagrams. Since an upgrade to version 3.3.2 of the plugin (but the issue appears starting 3.3.0) I get an error at generation time:

> Task :asciidoctor
Failed to generate image: node.EXE failed: C:\git_clones\my-project\node_modules\.bin\mmdc.cmd:1
@ECHO off
^

SyntaxError: Invalid or unexpected token
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
 :: cloud-deployment-openshift.adoc :: C:/git_clones/my-project/src/docs/asciidoc/C:/git_clones/my-project/src/docs/asciidoc/cloud-deployment-openshift.adoc:774 (uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb:build_block)

After some digging, I found out that this is due to the update of the asciidoctorj.diagram property in module-versions.properties from version 2.0.0 to 2.0.5.

Here is my setup (non relevant parts removed):

settings.gradle:

pluginManagement {
    plugins {
        id 'org.asciidoctor.jvm.convert' version '3.3.2'
        id 'com.github.node-gradle.node' version '3.1.1'
    }
}

rootProject.name = 'my-project'

build.gradle:

import org.gradle.internal.os.OperatingSystem

plugins {
  id 'org.asciidoctor.jvm.convert'
  id 'com.github.node-gradle.node'
}

group = 'com.mycompany'
version = project.property('version')

dependencies {
  compileOnly 'org.asciidoctor:asciidoctorj:2.5.2'
}

task copyAsciidocFonts(type: Copy) {
  from 'src/docs/asciidoc/styles/fonts'
  into "$buildDir/docs/asciidoc/fonts"
}

asciidoctor {
  dependsOn npmInstall
  finalizedBy copyAsciidocFonts
  baseDirFollowsSourceFile()
  asciidoctorj {
    modules {
      diagram.use()
    }
    fatalWarnings missingIncludes(), ~/Failed to generate image/, ~/callout list item index/, ~/no callout found/, ~/section title out of sequence/
    def mmdcCmd = OperatingSystem.current().isWindows() ? 'mmdc.cmd' : 'mmdc'
    options doctype: 'book'
    sources {
      include 'index.adoc'
    }
    def asciidoctorjAttributes = [
        'mmdc': "$rootDir/node_modules/.bin/$mmdcCmd",
        'mermaid-config': "$rootDir/config/asciidoc/mermaid-config.json",
        'source-highlighter': 'coderay'
    ]
    if (project.hasProperty('isCI')) {
      asciidoctorjAttributes['mermaid-puppeteer-config'] = "$rootDir/config/asciidoc/puppeteer-config.json"
    }
    attributes asciidoctorjAttributes
  }
}

package.json:

{
  "dependencies": {
    "@mermaid-js/mermaid-cli": "8.13.0"
  }
}

If I force the version of diagram module to the latest one the issue is fixed:

  asciidoctorj {
    modules {
      diagram.use()
      diagram.version = '2.2.1'
    }

Clearly, the issue is not on the Gradle plugin side, but then I think an update of the asciidoctorj.diagram property in module-versions.properties would help.

Can we update it to the latest version? No potential drawback/issue to consider?

ysb33r commented 1 year ago

Please try 4.0.0-alpha.1 and tell me if the problem still exists.