H5P Guides

H5P Command Line Interface

The H5P Command Line Interface, from now called h5pcli, is a tool that simplifies the development process of HTML5 packages.

The latest instructions for getting started and documentation of the H5P CLI can always be found at the github repository: https://github.com/h5p/h5p-cli.

Installation

A prerequisite for making the h5pcli work is to have nodeJS installed, so if you haven't got this already, head on over to nodeJS first.

When you got npm the easiest way to install h5pcli is by running the following in your favourite command line interface:

npm install -g h5p

This makes npm install h5pcli globally, we have to install it globally to use it in our favourite shell or command line interface.To get the latest h5p version, you can also grab it at Github.

Usage

Now that you have installed h5pcli globally on your computer you can use it in your command line by typing h5p.

The main usage areas for the cli are git interactions with library repositories.

This will bring up the available commands:

We will take a closer look at each of the available commands in the following section.

Commands

h5p help <command>

If supplied a command, help will show a help message related to the usage of that command.

Example:

h5p help pack

 

h5p list

Lists an overview of all H5P libraries registered with the cli. This command is especially helpful in combination with the other commands because it lists the library name which is required as a parameter for several other commands.

Example:

h5p list

 

h5p get <library>

If supplied a library this command will get the library and all of its dependencies and make folders for each library that is fetched with their library name. If a folder with that library name already exists, it will be skipped.

h5p get h5p-summary

 

h5p status [-f]

This command shows the git status for every branch in current working directory.  The -f handle can be used to display which branch each library is on.

Example:

h5p status

 

h5p commit <message>

Commits to all repos in current working directory with the provided message.

Example:

h5p commit 'added norwegian translation to library'

 

h5p pull [<library>...]

Pulls all libraries in current working directory on their current branch. Given one or multiple libraries, separated by space, only the given ones will be pulled.

Example:

h5p pull h5p-summary

 

h5p push [<library>....] [--tags]

Pushes all repositories in working directory to their current branch. Given one or multiple libraries, separated by space, only the given ones will be pushed. By applying the --tags option, current tags associated with this commit will also be pushed.

Example:

h5p push h5p-summary --tags

 

h5p checkout <branch> [<library>...]

Given branch this command will checkout all repositories in current working directory that has this branch. If one or multiple libraries are given, only the given ones will be checked out.

Example:

h5p checkout master h5p-summary h5p-joubel-ui

 

h5p new-branch <branch> [<library>...]

If supplied with a branch this command will create the new branch both locally and remote if it does not exist. If multiple libraries are given, the new branch will be applied to all given libraries.

Example:

h5p new-branch my-new-branch h5p-summary h5p-joubel-ui

 

h5p rm-branch <branch> [<library>...]

If supplied with a branch this command will remove the specified branch both locally and remote if it exists. If multiple libraries are given, this action will be applied to all given libraries.

Example:

h5p rm-branch my-new-branch h5p-summary h5p-joubel-ui

 

h5p diff

Prints combined diff for all repositories in current working directory.

Example:

h5p diff

 

h5p merge <branch> [<library>...]

If supplied with a branch this command will merge the given branch into the current branch for all libraries where the given branch exists. If one or multiple libraries are given, this action will only be performed on these libraries.

Example:

h5p merge master

 

h5p pack <library> [<library2>...] [my.h5p]

If supplied with a library this command will pack target library into a .h5p file. Multiple libraries can be packed together by separating them by a space, which is highly recommended to get all dependencies a library depend on, packed together. A custom name for the  H5P can be chosen by including the name as the last option. This name must end in .h5p

Example:

h5p pack h5p-summary h5p-joubel-ui my-awesome-libraries.h5p

 

h5p increase-patch-version [<library>...]

If one or multiple libraries are supplied this command will automatically increase the libraries' patch version.

Example:

h5p increase-patch-version h5p-summary h5p-joubel-ui

 

h5p tag-version [<library>...]

If supplied with one or multiple libraries these libraries are tagged with current version numbers.

Example:

h5p tag-version h5p-summary h5p-joubel-ui

 

h5p create-language-file <library> <language-code>

If supplied with a library and a language code this command will create a standardized language file with the given language code from semantics. "Language" folder must exist in the current working directory for this command to work properly.

Example:

h5p create-language-file h5p-summary nb

h5p import-language-files <from-dir>

If a directory is supplied, this command will get all language files from the given directory.

Example:

h5p import-language-files h5p-summary

Full example

Following is a short example showing some of the potential of the h5pcli. In this example we will:

  1. List all h5p libraries
  2. Get a specific library ("Multiple Choice")
  3. Check out a new branch ("branch")
  4. Merge master into this branch
  5. Add Norwegian translation
  6. Increase the patch version
  7. Tag the version
  8. Commit the new changes
  9. Push the new changes to the remote repository

A quite time-consuming process made super easy by the cli:

h5p list
h5p get h5p-multi-choice
h5p checkout branch
h5p merge master h5p-multi-choice
h5p create-language-file h5p-multichoice nb
h5p increase-patch-version h5p-multichoice
h5p tag-version h5p-multi-choice
h5p status
h5p commit 'added norwegian translation to multichoice'
h5p push h5p-multi-choice

That's all! You are now ready to develop H5Ps with increased speed and focus on improving your content type, instead of tedious operations!