CLI publishes uni-app to WeChat Mini Program, how to publish the Mini Program without opening the WeChat Developer Tools?

Foreword:

        Xiao Cheng, quickly change this UI here, and push a version quickly after the modification, and wait for the test; Hey Xiao Cheng, this needs the customer to change it in this way, you quickly change it and push a version for the customer to wait and see! ! !

        The above passage is believed to be heard more or less every day by colleagues who do development, but the version release process of the applet is not like other cloud servers such as Huawei Cloud and Alibaba Cloud. After configuration, you can directly double-click the update through the .sh script. Or click to run through the pipeline Flow; for small programs, you need to click Publish -> then go to WeChat Developer Tools -> then (friends who use it for the first time suggest opening uniapp to develop WeChat small programs, from construction to online, this is relatively   basic Articles)......., all in all, the publishing process is complicated ;

         So can't WeChat applets have a simple publishing process like other cloud servers?

        Of course, today we will demonstrate how uniapp’s cli tool can publish WeChat applets without opening the WeChat developer tool; here is a note: the version of Hbuildx needs to be 3.1.5+ , if the version is too low, please update the version first; 

Table of contents

Closer to home, the text begins 

1. CLI overview

1. cli program

2. Hbuildx's cli

3. Basic command of cli

    View help documentation

    View cli version number

    Start/stop Hbuildx

    more command lines

2. CLI global variable configuration

 1. Windows configuration global environment variables

      ① Copy the HBuilderX installation directory path (that is, the upper-level directory where the HBuilderX.exe program is located)

 ② Right-click This PC (this computer) -> Properties (attributes) -> Advanced system settings (advanced system settings) -> Environment Variables (environment variables)

  ③[User variables], click [Edit], find the path, and enter the HBuilderX path.

 ④ Check whether the configuration is successful

 2. MacOSX configures global environment variables 

     ① Method 1: Add environment variables

     ② Method 2: Create an alias

     ③ Method 3: Create a soft connection

3. CLI releases uniapp-WeChat applet

1. cli command syntax

2. How to obtain the WeChat applet code upload key?

3. Use the cli tool to publish WeChat applets 

4. Failure during CLI upload

   1.  Error: {"errCode":-10008}   


 


Closer to home, the text begins 


 

1. CLI overview

HBuilderX cli command line tool, only applicable to HBuilderX 3.1.5+ version

1. cli program

What is cli     first ? CLI (command-line interface, command-line interface) is an interface where executable commands can be entered at the user prompt. CLI is an acronym for Command Line Interface, that is, a command line interface.

Are you a little confused when you read the text, but do you wake up instantly when you look at the picture below? That's right!

 

2. Hbuildx's cli

Why do you say it is the cli of Hbuildx?

        Because the current cli can only serve our Hbuildx! Developers can instruct HBuilderX to start, package, log in and other operations through the cli command line.

The location of the command line tool:

  • Windows: root directory of HBuilderX installation directory, cli.exe
  • MacOSX
    • formal edition /Applications/HBuilderX.app/Contents/MacOS/cli
    • Alpha version /Applications/HBuilderX-Alpha.app/Contents/MacOS/cli

Special Note: All command examples in this article use cli instead of cli.exe, please use it according to different operating systems.

Today we mainly demonstrate Windows. You can see the picture below. You can see the cli.exe file, or clear the path and enter cmd to open a black window. This is the location of the CLI currently serving our Hbuildx!

 

3. Basic command of cli

Through the introduction in the previous step, we have found the cli tool of Hbuildx, then we can do some basic operations through the cli; if it is not through my friend who opened in the second step, the current Hbuildx cli cannot be found globally . Later, I will take you to configure global environment variables;

    View help documentation

        To view the help documentation, you need to start Hbuildx first; otherwise, the following problem will appear

cli --help  // 查看帮助文档
cli help // 查看帮助文档

 

    View cli version number

 

cli ver

  

    Start/stop Hbuildx

 

# 启动HBuilderX程序
cli open

# 关闭HBuilderX程序
cli app quit

 

    more command lines

cli command details
User account operations, login, logout, etc. details
File operation, open the file and jump to the specified row and column details
Project operations, importing and closing projects details
app packaging details
uniCLoud operations, such as cloud function upload, etc. details
uniCloud front-end web hosting details

 

 

2. CLI global variable configuration

Through the above steps, we can successfully start the cli tool in the current Hbuildx installation directory ;

But our global CMD still can't find our cli tool. In this case, we need to configure it in the global environment variable

 1. Windows configuration global environment variables

      ① Copy the HBuilderX installation directory path (that is, the upper-level directory where the HBuilderX.exe program is located)

 

 ② Right-click This PC (this computer) -> Properties (attributes) -> Advanced system settings (advanced system settings) -> Environment Variables (environment variables)

  ③[ User variables ], click [ Edit ], find the path, and enter the HBuilderX path.

 

 Click New to copy the path copied in the first step just now

 

 ④ Check whether the configuration is successful

[ Window + R ] Enter cmd to open the command line window

#查看当前配置是否成功

输入 cli ver 

 

 2. MacOSX configures global environment variables 

     ① Method 1: Add environment variables

          Warning:  When modifying environment variables, please , if you have no experience, it is not recommended to modify environment variables.慎重 仔细

If your shell is bash, enter the terminal, edit the environment variable file ~/.bash_profile, and enter the following

If your shell is zsh, enter the terminal, edit the environment variable file ~/.zprofile, and enter the following 

export HX_HOME=/Applications/HBuilderX.app/Contents/MacOS/
export PATH=$HX_HOME:$PATH:.

 

     ② Method 2: Create an alias

        Open the terminal, and execute the following command according to the shell type:

# shell类型:bash
echo "alias cli='/Applications/HBuilderX.app/Contents/MacOS/cli'" >> ~/.bashrc && source ~/.bashrc

# shell类型:zsh
echo "alias cli='/Applications/HBuilderX.app/Contents/MacOS/cli'" >> ~/.zshrc && source ~/.zshrc

 

     ③ Method 3: Create a soft connection

        Open the terminal and execute the following command:

ln -s /Applications/HBuilderX.app/Contents/MacOS/cli /usr/local/bin/cli

 

3. CLI releases uniapp-WeChat applet

After the above understanding and learning, we have successfully started the cli tool through the global [cmd] , let's take a look at the syntax of cli to publish WeChat applets;

1. cli command syntax

# 仅编译uni-app项目到微信小程序,不发行
cli publish --platform mp-weixin --project 项目名称

# 编译uni-app项目到微信小程序,并发行小程序到微信平台
cli publish --platform mp-weixin --project 项目名称 --upload true --appid 小程序appid --description 发布描述 --version 发布版本 --privatekey 小程序上传密钥文件
parameter illustrate
--platform Mandatory, distribution platform (MP-WEIXIN)
--project Required, project name
--appid Required, WeChat applet appid
--subPackage Released as a mixed package, example: --subPackage xxx
--upload Whether to upload to the WeChat platform after packaging, it will only take effect when the value is true
--description Uploaded applet description
--privatekey WeChat code upload key file  details
--version The version number of the uploaded applet; optional. If not filled, the version number in manifest.json will be read

2.  How to obtain the WeChat Mini Program code upload key?

Open the official website of the WeChat public platform  , scan the QR code to log in, click [Development -> Development Management] on the left menu, and click the tab [Development Settings], as shown in the figure below:

 

3. Use the cli tool to publish WeChat applets 

  Open the cmd command line window, and then prepare the materials we prepared and the downloaded [upload key].

 Press Enter, and wait for a while (there is one more step, Hbuildx needs to download a plugin~~~)

 After the plug-in is downloaded and installed, we will repeat the steps of inputting materials just now

 

 


Look at the picture above, after our series of operations, it has been successfully uploaded!!!

If there is a failure in the middle of uploading, please check [4. Failures during uploading]


 

4. Failure during CLI upload

   1.  Error: {"errCode":-10008}   

  Solution: [Open the WeChat public platform--scan code to log in] --> [Development Management] --> [Small program code upload] --> [Configure IP whitelist]

 As shown below, it can be solved!


Conclusion:

        Both methods have advantages and disadvantages for us. It mainly depends on everyone's choice, which method to use! However, with the continuous advancement of technology, it is becoming more and more convenient for us to do development. At the same time, we must remember to study hard. After all, "there is a path in the mountain of books, and there is no limit to the sea of ​​learning and hard work"! ! !

        Come on, IT people passing by! ! !

Guess you like

Origin blog.csdn.net/weixin_56650035/article/details/125268171