If you need to upload and preview projects on your own business engineering pipeline without relying on developer tools, it is recommended to use Weixin Mini Program miniprogram-ci

The developer tool provides two interfaces, the command line and the HTTP service, for external call. The developer can login, preview, upload and so on through the command line or the HTTP request instruction tool.

# Command Line V2

Upgrade Instructions : Since1.02.202003092, the CLI & HTTP interface upgradev2version. In thev2-version, the older command is still available, but is deprecated and will be removed in the future. Use the v2 command.The v2 version adds cloud development management operation support, optimized command form, increased detailed state prompts, support for long-time command execution, and support for nationalization (Chinese and English choices).

Call the installed tools from the command line to execute files and perform login, preview, upload, automate testing, and more. A call returning code of 0 represents normal, and an error at -1.

To use the command line, note that you first need to open the service port in Settings -> Security Settings for the Developer Tools.

Where the command line tools are located:

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

Windows:< installation path > / cli.bat

# Command Index

You can usecli -hto view all commands, usecli --lang zh-hYou can use the Chinese version for help.

classification Effect command
help See Help cli -h
log in Login Tool cli login
Whether or not to log in to the tool cli islogin
Weixin Mini Program Code preview cli preview
Upload code cli upload
Automatic preview cli auto-preview
Turn on automation cli auto
Turn on automation cli auto-replay
Building npm cli build-npm
Clear the cache cli cache
Tools Window Startup Tool cli open
Open other items cli open-other
Close the project window cli close
Turn off the tool cli quit
Reconstruct file listening cli reset-fileutils
Cloud development Cloud development operations cli cloud -h
Operations related to cloud environments cli cloud env -h
Cloud Function Related Operations cli cloud functions -h
View list of cloud environments cli cloud env list
View a list of cloud functions cli cloud functions list
View Cloud Function Information cli cloud functions info
Upload cloud function cli cloud functions deploy
Incremental upload cloud function cli cloud functions inc-deploy
Download Cloud Functions cli cloud functions download

All commands can be followed by-hor--helpto view Help.

# General Options

# Project Options

command Introductions
--project Project Path
--appid Weixin Mini Program AppID or Third Party Platform AppID.If a --project is provided, the option ignores
--ext-appid Third Party Platform AppID was developed when it was developed.If a --project is provided, the option ignores

# Global Options

operation command Introductions
See Help -h, --help
Choose a language --lang Optional. En or zh. Default en
Specified port number --port Optional. Tool HTTP service port. If the tool does not start, it starts and starts the service at a given port number. If the tool is already started and the port is different, you need to exit the tool first and re-execute it.
Turn on debugging mode --debug Optional. Turn on debugging mode to output additional information to assist in locating problems

# Command documentation

# Login Tool

There are two ways to login: one is to convert the login code into base64 to the user, so that the user can integrate it into their own system. The second is to print the QR code in the command line.

--Qr-format, -f : optional option.Binary code format, options: terminal, image, base64. Default terminal

--Qr-size, -f : Optional option.Binary code size, only valid when qr-format = terminal, option: small, default.Default default (tool version 1.05.2105072 onwards)

--Qr-output, -o : Optional option.QR codes will be output to a given path

--Result-output, -r : Output login results to specified file

Examples:

# 登录,在终端中打印登录二维码
cli login
# 登录,在终端中打印登录 base64 形式的二维码
cli login -f base64
# 登录,二维码转成 base64 并存到文件 /Users/username/code.txt
cli login -f base64 -o /Users/username/code.txt
# 登录,并输出登录结果到文件 /Users/username/result.json
cli login -r /Users/username/result.json

# Are you already logged into the tool?

Query whether you have logged in to the tool

cli islogin

# preview

Help:cli preview -h

to make a choice

--Qr-format, -f : optional option.Binary code format, options: terminal, image, base64. Default terminal

--Qr-size, -f : Optional option.Binary code size, only valid when qr-format = terminal, option: small, default.Default default (tool version 1.05.2105072 onwards)

--Qr-output, -o : Optional option.QR codes will be output to a given path

--Info-output, -i : Optional option.The relevant information will be output to a given path

--Project : Project path

Examples:

# 预览,在终端中打印登录二维码
cli preview --project /Users/username/demo
# 预览,二维码转成 base64 并存到文件 /Users/username/code.txt
cli preview --project /Users/username/demo --qr-output base64@/Users/username/code.txt --qr-format base64
# 预览,并将预览代码包大小等信息存入 /Users/username/info.json
cli preview --project /Users/username/demo --info-output /Users/username/info.json
# 预览,指定自定义编译条件,pathName
cli preview --compile-condition '{"pathName":"pages/index/index","query":"x=1&y=2"}'

# Automatic preview

Help:cli auto-preview -h

The automatic preview must be logged in, and if you do not log in, you will be prompted to log in first.

--info-output: Once specified, additional information about this preview will be output to the specified path in JSON format, such as code package size, subpackage size information.

--Project : Project path

Examples:

# 预览,并将预览代码包大小等信息存入 /Users/username/info.json
cli auto-preview --project /Users/username/demo --info-output /Users/username/info.json

# Upload code

Help:cli upload -h

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

The upload code requires information such as the project root directory, version number, and optional version notes.

--Version, -v : Upload code, version specifies version number, project_root specifies project root path.

--Desc, -d : Comments when uploading code.

--info-output, -i : After specified, the additional information will be exported to the specified path in JSON format, such as code package size, subcontract size information.

--Project : Project path

Examples:

# 上传路径 /Users/username/demo 下的项目,指定版本号为 1.0.0,版本备注为 initial release
cli upload --project /Users/username/demo -v 1.0.0 -d 'initial release'
# 上传并将代码包大小等信息存入 /Users/username/info.json
cli upload --project /Users/username/demo -v 1.0.0 -d 'initial release' -i /Users/username/info.json

# Building npm

The command line triggers the npm build.

--Project : Project path --compile-type:Manually specify the build type ("miniprogram" | "plugin"), which is used to specify whether to go miniprogramRoot or pluginRoot, superior to project.config.json

Examples:

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

# Turn on automation

Open Weixin Mini Program automatic function, detailed description can click here view.

--Project : Open the specified project and turn on auto-activation.

`--Auto-port ': Specifies automatic listening ports.

`--Auto-account ': specify openid.

Examples:

cli auto --project /Users/username/demo --auto-port 9420

# Open an automated test window

Open the automated test window, and you can start playing back test cases that were previously recorded. The recording playback can be viewed by Click here . Minimum available tool version:1.05.2111232

--Project : Project path --Replay-all : Replay all

# 打开自动化测试窗口
cli auto-replay --project /Users/username/demo
# 打开自动化测试窗口并回放全部测试用例
cli auto-replay --project /Users/username/demo --replay-all

# Startup Tool

--Project : Optional, if you don't bring --project, just open the tool.If you have a project path, you open the project in the path, automatically compile refresh with each execution, and automatically open the emulator and debugger. A projectpath cannot be a relative path.The project path must contain the correctly formatted project.config.json with the AppID and projectname fields. --Pure-simulator : Optional.If the --pure-simulator parameter is not used, the default project edit window mode is used. If you use the --pure-simulator parameter, it is pure analog mode.Support MiniGame and Weixin Mini Program.

Examples:

# 打开工具
cli open
# 打开路径 /Users/username/demo 下的项目
cli open --project /Users/username/demo

# Open other items

You can open a file or folder in the tool as an "other" item with the cli command line. (Pure Editor Mode)

--Project : Required, specify open file or folder path, support absolute path and relative path

Examples:

# 打开指定项目,在「其他」项目窗口中打开
cli open-other --project /Users/username/demo

# Close the project window

Close the project window

--Project : Optional, if the specified project_root project is opened, it will be closed automatically

Examples:

# 关闭指定项目
cli close --project /Users/username/demo

Note: When the item is closed, there is a pop-up hint if it is blocked; If not blocked, it will shut down after 3 seconds

# Turn off the tool

Shut down the developer tools

# 关闭开发者工具
cli quit

Note: When you close the developer tools, there is a pop-up asking whether to block them; If not blocked, it will shut down after 3 seconds

# Reconstruct file listening

Reset the tool's internal file cache to re-listen to the project files.

--Project : Project path

# 需要确保先开启了项目的窗口
cli open --project /Users/username/demo
# 调用 reset-fileutils 可对开启的项目进行重建文件监听
cli reset-fileutils --project /Users/username/demo

# Clear tool cache

Help:clicache-h

--clean, -c : Cache type storage (data) / file (file) / seeion (login) / auth (authorization) / network (network) / compile (compile) / all (all)

Examples:

# clean all
cli cache --clean all --project /Users/xxx/miniprogram-10
# clean storage
cli cache --clean storage --project /Users/xxx/miniprogram-10

# Cloud development operations

Cloud development command help:cli cloud-h

Cloud Development Cloud environment command help:cli cloud env -h

Cloud Development Cloud function command help:cli cloud functions -h

In cloud development commands, unless otherwise specified, you can specify the--projectoption or-- AppID(if it is Third Party Platform then add--ext-appid) either way.

# View list of cloud environments

Help:cli cloud env list-h

Examples:

# 通过 --project 查看
cli cloud env list --project /Users/username/demo
# 通过 --appid 查看
cli cloud env list --appid wx1111111111111

# View a list of cloud functions

Help:cli cloud functions list -h

--Env, -e : cloud environment ID

Examples:

# 通过 --project 查看环境 test-123 下的线上云函数
cli cloud functions list --env test-123 --project /Users/username/demo
# 通过 --appid 查看环境 test-123 下的线上云函数
cli cloud functions list --env test-123 --appid wx11111111111111

# View Cloud Function Information

Help:cli cloud functions info -h

--Env, -e : cloud environment ID

--Names, -n : cloud function names, multiple cloud functions separated by spaces, example: cli cloud functions info --names func_a func_b

Examples:

# 通过 --project 查看环境 test-123 下的云函数 aaa, bbb 的信息
cli cloud functions info --env test-123 --names aaa bbb --project /Users/username/demo
# 通过 --appid 查看环境 test-123 下的云函数 aaa, bbb 的信息
cli cloud functions info --env test-123 --names aaa bbb --appid wx1111111111111

# Upload cloud function

Help:cli cloud functions deploy -h

--Env, -e : cloud environment ID

--Names, -n : Cloud function names, multiple separated by spaces.The folder with the same name will be found in the "cloudfunctionRoot" directory specified in project.config.json. If used, the --project option must be provided

--Paths, -p : Path to the cloud function directory that needs to be deployed, multiple separated by spaces.The function directory name is considered to be the function name. With this option, the cloud functions directory structure does not have to follow the way it must be in project.config.json "cloudfunctionRoot"

--Remote-npm-install, -r : Cloud installation dependency, node_modules will not upload after specifying the option

Examples:

# 上传云函数根目录下名为 func_a, func_b 的两个云函数至云环境 ENVID,开启云端安装依赖
cli cloud functions deploy --env ENVID -r --names func_a func_b --project /aaa/bbb/ccc
# 指定绝对路径目录上传,开启云端安装依赖
cli cloud functions deploy --env ENVID -r --paths /a/b/func_a /x/y/func_b --appid APPID

# Incremental upload cloud function

Help:cli cloud functions inc-deploy -h

--Env, -e : cloud environment ID

--Name, -n : The name of the cloud function that needs to be updated, and the path option should not be used with this option.The folder with the same name will be found in the "cloudfunctionRoot" directory specified in project.config.json. If used, the --project option must be provided

--Path, -p : Cloud function directory, using this option should not use the name option.The function directory name is considered to be the function name. With this option, the cloud functions directory structure does not have to follow the way it must be in project.config.json "cloudfunctionRoot"

--File, -f : The relative file / directory path that requires incremental updates. The path must be the path to the relative cloud function directory

Examples:

# 增量上传,指定云函数名
cli cloud functions inc-deploy --env ENVID --name func_a --file index.js --project /aaa/bbb/ccc
# 增量上传,指定云函数路径
cli cloud functions inc-deploy --env ENVID --path /aaa/func_a --file index.js --appid APPID

# Download Cloud Functions

Help:cli cloud functions download -h

--Env, -e : cloud environment ID

--Name, -n : Cloud function name

--Path, -p : Download location

Examples:

# 下载云函数 func_a 至 /xxx/yyy 目录
cli cloud functions download --env ENVID --name func_a --path /xxx/yyy --appid APPID