Weixin DevTools provides command line API and HTTP API for external calls. Developers can instruct the DevTools to perform operations, such as login, preview and upload, by using command lines or sending HTTP requests.

# Command Line

DevTools installed by calling the command line can execute files to complete operations such as login, preview, upload, and automated testing. Calls return a code of 0 for normal, and -1 for an error.

Location of the command line tools

macOS: <Installation Path>/Contents/MacOS/cli

Windows: <Installation Path>/cli.bat

# Launching DevTools via Command Line

-o, --open [projectpath]: Opening the DevTools without projectpath will only open the DevTools itself, while opening with projectpath will open the project within the path. The DevTools will automatically refresh the compilations each time it runs, and will automatically open the simulator and debugger. Projectpath cannot be a relative path. The project path must contain project.config.json in the correct format, including the appid and projectname fields.

Example:

# Open the DevTools
cli -o
# Open the project under the path  /Users/username/demo 
cli -o /Users/username/demo

# Specify the HTTP Service Port No. for DevTools

Minimum version: 1.02.1906042

--port <number>: This command must be used with other commands. If the DevTools is not opened, executing this command will open the DevTools and the HTTP service with a specified port no. If the DevTools is opened and its port no. is not the specified one, the execution stops and reports an error automatically.

Example:

cli --port 3000 -o

# Login from Command Line

The command line provides two login methods: one is to convert the login QR code into base64 and send it to the user, so the user can integrate it into their own system; and the other is to print the QR code in the command line.

-l, --login: Enable login logic.

--login-qr-output [format[@path]]: Specify the QR code output method. Available values for format include terminal (command line output), base64, and image. If a path is entered, the result will be output to the file of the specified path. If a path is not entered, the result will be output to the command line. If you do not use this option or use it without entering the format, the system prints on the command line by default.

--login-result-output <path>: Output the login result to the specified file

Example:

# Log in, print the login QR code in the terminal
cli -l
# Log in, print the QR code in  base64  format in the terminal
cli -l --login-qr-output base64
# Log in, convert the QR code into  base64  and save it to the file  /Users/username/code.txt
cli -l --login-qr-output base64@/Users/username/code.txt
# Log in and output the login result to the file /Users/username/result.json
cli -l --login-result-output /Users/username/result.json

# Preview

You must be logged in to preview. If you are not logged in, you will be prompted to log in first. The QR code preview can be printed by the command line or converted to base64. Project configurations such as ES6 are read from project.config.json.

-p, --preview <project_root>: Preview code. project_root specifies the project root path.

--preview-qr-output [format[@path]]: Specify the QR code output method. The semantics are the same as the login option --login-qr-output.

--preview-info-output <path>: When specified, additional information for this preview, such as the code package size and sub-package size information, will be output in JSON format to the specified path.

--compile-condition '<json>': Specify custom compilation conditions. Two fields can be specified for the JSON condition. pathName indicates the opened page and defaults to the homepage if left blank. query indicates the page parameter.

Example:

# Preview, print the login QR code in the terminal
cli -p /Users/username/demo
# Preview, convert the QR code into  base64  and save it to the file  /Users/username/code.txt
cli -p /Users/username/demo --preview-qr-output base64@/Users/username/code.txt
# Preview and save information such as the size of the preview code package to  /Users/username/info.json
cli -p /Users/username/demo --preview-info-output /Users/username/info.json
# Preview, specify custom compilation conditions, pathName
cli --compile-condition '{"pathName":"pages/index/index","query":"x=1&y=2"}'

# Automatic Preview

You must be logged in for automatic preview. If you are not logged in, you will be prompted to log in first.

--auto-preview <project_root>: Automatic preview code. project_root specifies the project root path.

--auto-preview-info-output <path>: When specified, additional information for this preview, such as the code package size and sub-package size information, will be output in JSON format to the specified path.

Example:

# Preview and save information such as the size of the preview code package to  /Users/username/info.json
cli --auto-preview /Users/username/demo --auto-preview-info-output /Users/username/info.json

# Upload Code

You must be logged in to upload the code. If you are not logged in, you will be prompted to log in first.

The information required to upload the code includes the project root directory, version number, and available version notes.

-u, --upload <version@project_root>: Upload code. Version specifies the version number, and project_root specifies the project root path.

--upload-desc <desc>: Notes when uploading code.

--upload-info-output <path>: When specified, additional information for this upload, such as the code package size and sub-package size information, will be output in JSON format to the specified path.

Example:

# Upload the project under the path /Users/username/demo , whose version no. is  1.0.0 and version notes are  initial release
cli -u 1.0.0@/Users/username/demo --upload-desc 'initial release'
# Upload and save information such as the size of the code package to  /Users/username/info.json
cli -u 1.0.0@/Users/username/demo --upload-desc 'initial release' --upload-info-output /Users/username/info.json

# Build an NPM

You can build an NPM via the command line.

--build-npm <project_root>: Build according to the configuration in project.config.json. NPMs built for operations and the menu bar must match. --build-npm-compile-type <type>: Manually specify the compilation type ("miniprogram" | "plugin") and the path (miniprogramRoot or pluginRoot). This has a higher priority than the values in project.config.json.

Example:

cli --build-npm /Users/username/demo

# Close the Current Project Window

You can close the project window via the command line.

--close <project_root>: Automatically close the opened project_root project.

Example:

# Close the specified project
cli --close /Users/username/demo

Note: When closing the project, a pop-up window will appear, prompting whether to block it. If not, the project will be closed in 3 seconds.

# Close Weixin DevTools

You can quit Weixin DevTools via the command line.

--quit: Quit Weixin DevTools

# Quit Weixin DevTools
cli --quit

Note: When quitting the Weixin DevTools, a pop-up window will appear, prompting whether to block it. If not, the DevTools will be closed in 3 seconds.