How to run a NodeJS command before building a Go program?

I’m trying to build a rather complex Go program that requires multiple steps before it’s built.

One of the steps is to install a NodeJS command and run it. In bash, it’s literally a two-liner.

sudo npm i -g hogan.js
hulk ./web/mustache/*.html --outputdir ./web/templates/

How can I achieve that during the build process of a Snap?

You can override the build step of a part. So a simple example would be:

    override-build: |
      sudo npm i -g hogan.js
      hulk ./web/mustache/*.html --outputdir ./web/templates/
      snapcraftctl build

The above will run your commands, then run what would norin the override.mally be run in a build via snapcraftctl build

You can also break that out into a separate part, with its own build step, for organization purposes (and to avoid manually calling snapcraftctl build).

Note: don’t forget the pipe after the colon in override-build. That’s yaml for “include the below text as a blob of text”. If you leave it out, you’ll wind up with invalid yaml.

I’d like to use multiple parts since there’s multiple build steps in multiple languages. I also saw that we could use plugins, like a Go plugin and a NodeJS plugin, and I’d like to use those if possible

That sounds like a good plan!

If you need to order your steps, you can use “after”. For example:

    after: [my-node-part]

Yep, I was already going after the after part.

In the NodeJS plugin, I’m trying to have it install my dependency without having to use sudo npm install -g so it’s cleaner and doesn’t modify the system in unexpected ways, but there’s something wrong with my part.

    plugin: nodejs
      - hogan.js
    node-engine: 12/stable
      - hulk ./web/mustache/*.html --outputdir ./web/templates/

Failed to load plugin: properties failed to load for hulk: ‘source’ is a required property

What should I use for the source? There’s nothing about a source in the docs.

Also, when I add node-package-manager: npm, I get an error.

Failed to load plugin: properties failed to load for hulk: Additional properties are not allowed (‘node-package-manager’, ‘node-packages’, ‘npm-run’, ‘node-engine’ were unexpected)

Ah, dammit. I just didn’t understand what were parts. I got something better now.

base: core18
confinement: classic
      - git
      - go/stable
      - node/12/stable
    override-build: |
      npm install --global hogan.js
      npx hulk ./web/mustache/*.html --outputdir ./web/templates/
      go get -u
      ~/go/bin/rice embed-go
    source: .
    source-type: git
#    stage-snaps:
#      - ipfs/edge
#      - ipfs-cluster/edge
    plugin: go
    go-channel: stable

Okay, now the problem is how can I stage-snaps two snaps, one that’s classic and one that’s strict?