Bundle Management
Dependency
A basic bundle.json file needs to be enriched by bundle dependencies to implement more complex features. Bundle names and version numbers should be defined in the dependencies field of bundle.json.
{
"name": "my-bundle",
"version": "1.0.0",
"dependencies": {
"net": "1.0.0"
}
}
In this example, my-bundle depends on net 1.0.0. After you globally install the hpm-cli tool, run the following command to obtain bundle dependencies from the remote repository:
hpm install
Bundle dependencies are then stored in the ohos_bundles folder in the root directory of the current bundle. A tree structure illustrating the bundle and its dependencies will be generated. You need to run the following command in the root directory of the bundle:
username@server MINGW64 /f/showcase/demo/demo
$ hpm list
+--demo@1.0.0
| +--@huawei/media@1.0.2
| +--@demo/sport_hi3518ev300_liteos_a@1.0.0
| | +--@demo/app@4.0.1
| | | +--@demo/build@4.0.1
| | | +--@demo/arm_harmonyeabi_gcc@4.0.0
| | +--@demo/liteos_a@4.0.0
| | | +--@demo/third_party_fatfs@4.0.0
| | | +--@demo/arm_harmonyeabi_gcc@4.0.0
| | +--@demo/init@4.0.0
| | +--@demo/dist_tools@4.0.0
Alternatively, you can view the dependencies of the current bundle in a graph by running the following command:
hpm dependencies
A deps_visual folder is generated in the current directory. The folder contains the deps.html and deps-data.js files. After you open the deps.html file via a browser, you can view bundle dependencies illustrated by a graph, as shown in the following figure.
Each dependency type is indicated by a different color at the corresponding node. You can move the mouse pointer to a node to view the implied information.
Figure 1 Bundle dependencies
![bundle-dependencies](figures/bundle-dependencies.png)
HPM Command Reference
You can use the hpm-cli tool to manage the lifecycle of a bundle. The following table describes available HPM commands. (You can run the hpm -h command to get the command details).
Table 1 HPM commands
Function
|
Command
|
Description
|
Querying version information
|
hpm -V or hpm --version
|
Queries the hpm-cli version number.
|
Querying help information
|
hpm -h or hpm --version
|
Queries the command list and help information.
|
hpm -h
|
Queries command reference.
|
Creating a project
|
hpm init bundle
|
Creates a bundle project.
|
hpm init -t template
|
Creates a scaffolding project based on the template.
|
Installing bundles
|
hpm install or hpm i
|
Installs dependent bundles in the bundle.json file.
|
hpm install bundle@version
|
Installs bundles of a specified version.
|
Uninstalling bundles
|
hpm uninstall bundle
|
Removes dependent bundles.
|
hpm remove or hpm rm bundlename
|
Removes dependent bundles.
|
Viewing information
|
hpm list or hpm ls
|
Displays the bundle tree of available bundles and distributions.
|
hpm dependencies
|
Generates the dependency diagram (in HTML format) of available bundles and distributions.
|
Searching for bundles
|
hpm search name
|
Searches for bundles. --json is used to specify the search result in JSON format, and -type is used to set the target type, which can be bundle, distribution, or code-segment.
|
Setting HPM configuration items
|
hpm config set key value
|
Sets configuration items, such as the server address and network proxy.
|
hpm config delete key
|
Deletes configurations.
|
Updating bundle versions
|
hpm update
|
Updates the versions of dependent bundles.
|
hpm check-update
|
Checks whether version updates are available to dependent bundles.
|
Building
|
hpm build
|
Builds a bundle or distribution.
|
hpm dist
|
Packs a distribution, depending on the dist script in scripts of bundle.json.
|
Packing
|
hpm pack
|
Packs dependencies of local bundles.
|
Burning
|
hpm run flash
|
Burns the firmware, depending on the flash script in scripts of bundle.json.
|
Publishing
|
hpm publish
|
Publishes a bundle, which must be unique in the repository and has a unique version. (An account is required for login.)
|
Running extended commands
|
hpm run
|
Runs the commands in scripts defined in bundle.json. Multiple commands can be executed in batches by using &&.
|
Generating a key
|
hpm gen-keys
|
Generates a public-private key pair and configures the public key on the hpm server, achieving password-free hpm-cli login for bundle publishing.
|
Generating third-party open source notice
|
hpm gen-notice
|
Generates a joint file describing the notice on third-party open source based on the description of each bundle.
|