Automate the process of packaging and publishing applets

The existing problems in

  • The test cannot publish the version it wants.
  • The code of Vue is packaged into the code of wechat applet.
  • The packaged code cannot be pushed to the wechat developer platform.
  • After the build, you cannot test directly with the corresponding environment.

Associated dependencies and configurations

  1. Package into the format required by wechat

    1. Vue-cli-service uni-build installs the corresponding Vue scaffolding
    2. Operation and maintenance platform directly build into a fixed wechat package, regardless of the environment. The completed build file is in dist/dev/mp-weixin
        "build": "cross-env NODE_ENV=prod UNI_PLATFORM=mp-weixin vue-cli-service uni-build --report"."prod": "cross-env NODE_ENV=prod UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch"."stg": "cross-env NODE_ENV=stg UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch".Copy the code
  2. Push the packaged code to wechat platform

    1. Install miniprogram – ci
    2. In the development mp.weixin.qq.com/ development management/development Settings/applets code upload specified fixed IP whitelist
    3. In the development of mp.weixin.qq.com/ development management/development Settings/applets code upload generate applets code upload key
     const ci = require('miniprogram-ci');
     const config = require('./config.json'); // Release information
     const manifest = require('.. /manifest.json'); // Basic information of wechat applet
     let { wxVersion: version, wxDesc: desc } = config;
     const appid = manifest['mp-weixin'].appid;
     const cwd = process.cwd() + '/dist/dev/mp-weixin';
     if(! version) version ='v1.0.0';
     if(! desc) desc =new Date() + 'upload';
     const project = new ci.Project({
          appid: appid,
          type: 'miniProgram'.projectPath: cwd,
          privateKeyPath: process.cwd() + '/src/wxupload/private.wxea2e525a470f0b4d.key'./ / the secret key
          ignores: ['.. /node_modules/**/*']});Copy the code
    1. upload
        ci.upload({
            project,
            version,
            desc,
            setting: {
              minify: true,
        },
        }).then(res= > {
            console.log(res)
            console.log('Upload successful')
        }).catch(error= > {
             if (error.errCode == -1) {
              console.log('Upload successful')}console.log(error)
            console.log('Upload failed')
            process.exit(-1)})Copy the code
    1. Release completion is also with preview function, generated a TWO-DIMENSIONAL code image scan code use.
  3. So far the build, upload, publish and other functions have been completed.

use

  1. The o&M platform pulls the specified file branch package from the Git repository.
  2. After pulling, execute NPM build to generate packaged files based on the formal environment.
  3. The test needs to test the environment of the small program, release the need to select the corresponding environment.
  4. O&m platform replaces global environment variables specified by the foreground.
  5. Automatic release after replacement, automatic preview. The test can be accessed by previewing the QR code for specific applets.

The development process

  1. Vscode for development, from the corresponding environment, the default open hot update.
  2. Debug and preview with wechat applets.
  3. Fill in the current version number and version update description in the wechat profile.