Reading for the great rejuvenation of the Chinese nation.
Antecedents to review
Continuous integration can be implemented using git hooks. The following is a question that will be addressed in this article:
Current release applets status
In the process of small program development, most developers open, are compiled through the developer tools, preview, upload, and then log in the small program background, release.
Perhaps little attention has been paid to the CI helper for small programs, miniProgram-CI.
miniprogram-ci
What is the
Miniprogram-ci is a compilation module of small program/small game project code extracted from wechat developer tools.
Developers do not need to open the small program developer tool, and independently use miniprogram-CI to upload and preview the small program code.
miniprogram-ci
What can do
Upload code
, corresponding to the small program developer tools uploadPreview code
, corresponding to the applets developer tool previewBuild the NPM
, corresponding to the applets developer tools: menu-Tools-Build NPMUpload cloud development cloud function code
, corresponding to applets developer tools to upload cloud function capabilitiesThe agent
To configure the network request proxy mode of miniProgram-CISupport for getting the recently uploaded version of sourceMap
Node script invocation and command line invocation are supported
How to useminiprogram-ci
Upload code
-
First, we need to configure the key and IP whitelist on wechat public platform.
Before using miniProgram-CI, you should visit “wechat public Platform-development-Development Settings”, download the code, upload the key, and configure the IP whitelist. Developers can choose to open the IP whitelist, and only the IP in the whitelist can call the relevant interface. We suggest that all developers enable this option by default to reduce the risk. The code upload key has the permission to preview and upload the code. The key will not be stored in the wechat public platform in plain text
-
Second, install the NPM package of miniProgram-CI in your project
npm install miniprogram-ci --save Copy the code
-
Third, create a file to write the upload code.
Before writing this code, you need to understand the concept of project objects. It can be understood as an abstraction of the entire small program, defined as follows:
interface IProject { appid: string // AppID of small program/small game project type: string / / the type of project, RMS miniProgram/miniProgramPlugin/miniGame/miniGamePlugin projectPath: string // The path of the project, that is, the directory where project.config.json is located privateKey: string // Private key, used for authentication when obtaining project attributes and uploading, downloaded after login on wechat public platform attr(): Promise<IProjectAttr> // Project properties, if privateKey is specified real project properties are used stat(prefix: string, filePath: string): IStat | undefined // prefix the stat of the filePath (filePath) in the specified directory, undefined if it does not exist getFile(prefix: string, filePath: string): Promise<Buffer> // Prefix filePath Buffer in the specified directory getFileList(prefix: string, extName: string): string[] // list of files under the prefix filePath (filePath) in a specific directory updateFiles: () = > void // Update the project file } Copy the code
Then you can implement an upload function, such as the code on the official document:
// upload.js / / reference miniprogram - ci const ci = require('miniprogram-ci') ;(async() = > {// Create the project object const project = new ci.Project({ appid: 'wxsomeappid'.type: 'miniProgram'.projectPath: 'the/project/path'.privateKeyPath: 'the/path/to/privatekey'.ignores: ['node_modules/**/*'],})// Perform the transfer action const uploadResult = await ci.upload({ project, version: '1.1.1'.desc: 'hello'.setting: { es6: true,},onProgressUpdate: console.log, }) // Prints the upload result console.log(uploadResult) })() Copy the code
We can place this code as a command in a package.json file
// package.json { "name":"miniProgram"."version":"1.0.0"."scripts": {"npm run upload": "node ./upload.js"}}Copy the code
In this way, we can execute NPM run upload after local development to complete the upload of the small program.
The same goes for preview.
Realize continuous integration of small programs
To implement continuous integration, use the post-Update hooks of Git hooks to configure the upload script for the applets.
Possible issues to consider — the ability to display a preview qr code at preview time.
conclusion
- Need to know
miniprogram-ci
package - Need to know
miniprogram-ci
Package, external APIupload
uploadpreview
previewpackNpm
Build the NPMgetDevSourceMap
Pull the recently uploaded version of sourceMap
One last word
- Move your rich little hands and “like it.”
- Move your rich little hands, “click here”
- All see here, might as well “add a follow” search wechat public account “javascript Advanced Programming”
- Might as well “forward”, good things to remember to share