H5P Command Line Interface
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.
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:
- help <command> Displays additional information
- list List all H5P libraries
- get <library> Clone library and all dependencies
- status [-f] Show the status for all your libraries
- commit <message> Commit to all repos with given message
- pull [<library>...] Pull the given or all repos
- push [<library>...] [--tags] Push the given or all repos
- checkout <branch> [<library>...] Change branch
- new-branch <branch> [<library>...] Creates a new branch(local and remote)
- rm-branch <branch> [<library>...] Removes branch(local and remote)
- diff Prints combined diff for all repos
- merge <branch> [<library>...] Merge in branch
- pack <library> [<library2>...] [my.h5p] Packs the given libraries
- increase-patch-version [<library>...] Increase the patch version
- tag-version [<library>...] Create a tag from the current version number
- create-language-file <library> <language-code> Creates language file
- import-language-files <from-dir> Get files from dir
We will take a closer look at each of the available commands in the following section.
If supplied a command, help will show a help message related to the usage of that command.
h5p help pack
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.
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
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.
Commits to all repos in current working directory with the provided message.
h5p commit 'added norwegian translation to 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.
h5p pull h5p-summary
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.
h5p push h5p-summary --tags
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.
h5p checkout master h5p-summary h5p-joubel-ui
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.
h5p new-branch my-new-branch h5p-summary h5p-joubel-ui
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.
h5p rm-branch my-new-branch h5p-summary h5p-joubel-ui
Prints combined diff for all repositories in current working directory.
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.
h5p merge master
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
h5p pack h5p-summary h5p-joubel-ui my-awesome-libraries.h5p
If one or multiple libraries are supplied this command will automatically increase the libraries' patch version.
h5p increase-patch-version h5p-summary h5p-joubel-ui
If supplied with one or multiple libraries these libraries are tagged with current version numbers.
h5p tag-version h5p-summary h5p-joubel-ui
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.
h5p create-language-file h5p-summary nb
If a directory is supplied, this command will get all language files from the given directory.
h5p import-language-files h5p-summary
Following is a short example showing some of the potential of the h5pcli. In this example we will:
- List all h5p libraries
- Get a specific library ("Multiple Choice")
- Check out a new branch ("branch")
- Merge master into this branch
- Add Norwegian translation
- Increase the patch version
- Tag the version
- Commit the new changes
- 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!