Jutro CLI for Developers

Aug 13, 2020 | Article

What does the CLI provide?

The features of jutro-cli can be separated into two categories:

  1. Migration scripts designed to upgrade an older version of jutro-app to the latest.
  2. Various useful scripts designed to make a Jutro consumer’s development easier (including some scripts that used to live within jutro-app.)

Jutro CLI uses the commander library to provide the CLI.

Migration Scripts

  • update – Updates jutro-cli itself.
  • update-app – Updates the dependencies in jutro-app’s package.json file and will (eventually) apply any code mods or other non-metadata application updates.
  • update-metadata-schema – Grabs the latest metadata schema definition available and copies it to the consumers jutro-app so they can reference it in their IDE.
  • ui-metadata – Migrates consumer metadata files based on migration steps defined in the CLI snapshots.

Other Scripts

  • i18n – Has several sub commands for extracting, merging, and generating translations and message keys.
  • write-build-info – Outputs a file containing config variables describing the current configuration (e.g. application name, version, jutro version, commit hash.)
  • add-ons – Other scripts that will enable optional Jutro features.

How to Run Jutro CLI

  1. Navigate to /packages/jutro-cli.
  2. Execute npm link.
  3. Navigate to the root of a created jutro application – it is really important to note that although the CLI can be executed globally, it is designed to work at the root level of a jutro app.
  4. Execute jutro-cli – this command will show all available CLI commands, which you can get help on from here.

Note that you can also execute npm unlink in /packages/jutro-cli, but then you’ll be unable to run the command until you either npm link again OR install the latest version of jutro-cli.

Structure of the CLI Code

Image of the structure of the Jutro CLI code

The CLI is made up of two parts: bin, and src.

bin directory

This directory stores the consumer-facing script registration. cli.js is the main entry point which invokes commander and registers the top level commands. Each top level command then delegates to a sub-directory under bin for lower level commands and options registration.

src directory

The commands registered under the bin directory then delegate the logic to files under src. The src directory contains logic for all the commands as well as helper functionality (logging etc).

Migration Scripts

To migrate consumer applications to newer versions we run migration scripts on the source of their app. As of now, we store the migration scripts under src/versions in what we call snapshots.

Snapshots

A snapshot stores migration scripts for a particular version of Jutro. It is a block that describes the changes necessary to move to that version from a previous version.

Snapshots contain:

  1. package-template.json
    1. This file contains the dependencies, dev-dependencies, and scripts that Jutro App contained as of the version of the snapshot. It is used to update the dependencies and scripts on the consumer application.
  2. uiMetadataMigration
    1. This directory contains the metadata migration scripts used to update consumer metadata files based on changes to Jutro components, or metadata structure.

Updating using Snapshots

The update-app script does the following:

  1. Gets the current version e.g 1.0.1
  2. Gets all available snapshots based on that version.
    1. Any snapshot with a version is greater than 1.0.1 e.g 2.0.1, 2.0.2
  3. Runs the migrations for each snapshot incrementally
    1. This means that we run the migration scripts for each snapshot, not just the latest. They are executed in order: 2.0.1 → 2.0.2 → etc
    2. Running the migrations means running the available scripts described in the snapshot
      1. Migrating dependencies based on the package template
      2. Migrating metadata files based on the uiMetadataMigration scripts stored in the snapshot.
  4. Prompts the user to run npm install based on the newly migrated dependencies.

Related Info

Video
Learn how Jutro floorplans help you organize content easily so you can create beautiful digital experiences on Guidewire.
Use Case
Want to build beautiful and engaging digital experiences for Guidewire? This page has everything you need to get started.
Blog
The best way to get started with Jutro is to know React. Here's a complete learning plan for JavaScript and ES6+ concepts.