What does the CLI provide?
The features of jutro-cli can be separated into two categories:
- Migration scripts designed to upgrade an older version of jutro-app to the latest.
- 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.
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.
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
- Navigate to
- 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.
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
The CLI is made up of two parts: bin, and src.
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.
The commands registered under the bin directory then delegate the logic to files under
src directory contains logic for all the commands as well as helper functionality (logging etc).
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.
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.
- 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.
- 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
update-app script does the following:
- Gets the current version e.g 1.0.1
- Gets all available snapshots based on that version.
- Any snapshot with a version is greater than 1.0.1 e.g 2.0.1, 2.0.2
- Runs the migrations for each snapshot incrementally
- 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
- Running the migrations means running the available scripts described in the snapshot
- Migrating dependencies based on the package template
- Migrating metadata files based on the uiMetadataMigration scripts stored in the snapshot.
- Prompts the user to run
npm installbased on the newly migrated dependencies.