Creates an oh-package.json5 file.
This command is used to create an oh-package.json5 file and initialize a package in the working directory.
During the command execution, an interaction interface is displayed for you to input basic information about the third-party library, such as the library name and version. ohpm creates an oh-package.json5 file in the working directory based on existing fields, dependencies, and selected options. The set fields and values will all be retained.
Besides creating the default oh-package.json5 file, you can append the -y or --yes parameter to the ohpm init command to skip the interaction interface.
The default content is as follows:
{
"name": "work_dir",
"version": "1.0.0",
"description": "",
"main": "Index.ets",
"author": "",
"license": "ISC",
"dependencies": {}
}
If there is no existing oh-package.json5 file in the current working directory, the name field in the new file is the name of the current working directory by default. If there is already an oh-package.json5 file, the new file overwrites the existing one, with the name field set to the same value as that in the existing file.
You can append the -g <group_name> or --group <group_name> parameter to the ohpm init command to create an oh-package.json5 file. The namespace of the name field is @group_name.
In ohpm 6.0.2.636 and later versions, you can append the --log_level <string> parameter to the ohpm init command to specify the log level (info, debug, warn, or error) for execution of the current command. If this parameter is not set, the log_level setting in the .ohpmrc file is applied.
In ohpm 6.0.2.636 and later versions, you can append the --debug parameter to the command to set the log level to debug for execution of the current command. This configuration takes effect only on the current command line and does not alter the log level configured in the .ohpmrc file. If this parameter is not set, the log_level setting in the .ohpmrc file is applied.
The oh-package.json5 file does not exist in the current working directory.
In D:\demo, run the following command:
ohpm init -y
The command output is as follows:
Wrote to D:\demo\oh-package.json5:
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "Index.ets",
"author": "",
"license": "ISC",
"dependencies": {}
} The oh-package.json5 file with the name field set to demo_name already exists in the current working directory.
In D:\demo, run the following command:
ohpm init -y
The command output is as follows:
Wrote to D:\demo\oh-package.json5:
{
"name": "demo_name",
"version": "1.0.0",
"description": "",
"main": "Index.ets",
"author": "",
"license": "ISC",
"dependencies": {}
} Create an oh-package.json5 file in which the name field is set to @group_name/demo instead of demo.
ohpm init -g group_name
The command output is as follows. The name field in the example is automatically displayed as @group_name/demo.
package name: (@group_name/demo)