# # Overview
Miniprogram-ci is a compilation module for the Weixin Mini Program / MiniGame project code extracted from the WeChat developer tool .
Developers can not open Weixin Mini Program developer tools, independent use of miniprogram-ci for Mini Program code upload, preview and other operations.
Miniprogram-ci supports uploading and previewing for Third Party Platform development from 1.0.28 and is invoked in the same way as normal development mode. View Details
# Key and IP whitelisting configuration
Before using miniprogram-ci, you should visit " WeChat Public Platform - Administration - Development Management - Development Settings - Weixin Mini Program Code Upload" to generate a Code Upload Key and configure IP whitelists The developer can choose to open the IP whitelist, only the IP in the whitelist can call the relevant interface. We recommend that all developers turn this option on by default to reduce the risk Code upload key has preview, upload code permissions, the key will not be stored in plain text on the WeChat public platform, once lost must be reset, please keep the developer

# function
Miniprogram-ci currently offers the following capabilities:
- Upload code, corresponding to Weixin Mini Program developer tool upload
- Preview code, corresponding to the Weixin Mini Program developer tool preview
- Build npm, corresponding to the Weixin Mini Program developer tool: Menu - Tools - Build npm
- Upload cloud development cloud function code, corresponding to the Weixin Mini Program developer tools upload cloud function capabilities
- Upload cloud hosting code, corresponding to Weixin Mini Program developer tool upload cloud hosting capabilities
- Upload cloud storage / static managed files for Weixin Mini Program Developer Tools - Cloud Development - Cloud storage and static managed document management
- Proxy, configure the network request proxy mode of miniprogram-ci
- Support for getting the most recently uploaded version of sourceMap
- Support node script invocation and command line invocation
# Script calls
npm install miniprogram-ci --save
# Project Objectives
Project objects are the main inputs to this module and can be implemented on their own according to the definitions below
Definition of Project Object:
interface IProject {
appid: string
type: string
projectPath: string
privateKey: string
attr(): Promise<IProjectAttr>
stat(prefix: string, filePath: string): IStat | undefined
getFile(prefix: string, filePath: string): Promise<Buffer>
getFileList(prefix: string, extName: string): string[]
updateFiles: () => void
}
| key | type | Introductions |
|---|---|---|
| appid | attribute | Weixin Mini Program / MiniGame Project AppID |
| type | attribute | Type of project, valid value miniProgram/miniProgramPlugin/miniGame/miniGamePlugin |
| projectPath | attribute | The path of the project, which is the directory where project.config.json is |
| privateKey | attribute | Private key, used for authentication when obtaining project attributes and uploading, downloaded on WeChat public platform |
| attr | Asynchronous methods | Property of the project, if privateKey is specified, the real project property is used |
| stat | Synchronization Method | A stat for a prefix filePath in a specific directory, or undefined if it does not exist |
| getFile | Asynchronous methods | Buffer of filePath under prefix in specific directory |
| getFileList | Synchronization Method | A list of files under the prefix filePath in a specific directory |
| updateFile | Synchronization Method | Update project files |
You can also create the object by specifying the project path
const ci = require('miniprogram-ci')
// Note: When calling newci.Project, make sure that the project code is already complete to avoid a file missing error during compilation.
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/privatekey/path',
ignores: ['node_modules/**/*'],
})
| key | type | Required to fill in | Introductions |
|---|---|---|---|
| appid | string | yes | Legal Weixin Mini Program / MiniGame AppID |
| projectPath | string | yes | Project Path |
| privateKeyPath | string | yes | The path of the private key |
| type | string | no | Display indicates the current project type, defaults to miniProgram, valid miniProgram/miniProgramPlugin/miniGame/miniGamePlugin |
| ignores | string[] | no | Specify rules that need to be ruled out |
# upload
const ci = require('miniprogram-ci')
;(async () => {
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/path/to/privatekey',
ignores: ['node_modules/**/*'],
})
const uploadResult = await ci.upload({
project,
version: '1.1.1',
desc: 'hello',
setting: {
es6: true,
},
onProgressUpdate: console.log,
})
console.log(uploadResult)
})()
# parameter
| key | type | Required to fill in | Introductions |
|---|---|---|---|
| project | IProject | yes | # Project objects |
| version | string | yes | Custom version number |
| desc | string | no | Custom Note |
| setting | object | no | # Compile the settings |
| onProgressUpdate | function | no | Progress update listening function |
| robot | number | no | Specify which ci droid to use, optional: 1 ~ 30 |
| threads | number | no | Specify the number of threads opened during the local compilation process |
# return
| key | type | Required to fill in | Introductions |
|---|---|---|---|
| subPackageInfo | Array<{name:string, size:number}> | no | Weixin Mini Program package information,nameis__FULL__``nameis__APP__ |
| pluginInfo | Array<{pluginProviderAppid:string, version: string, size:number}> | no | Weixin Mini Program Plug-in Information |
| devPluginId | string | no | In plugin development mode, the plugin id of the uploaded version |
# preview
const ci = require('miniprogram-ci')
;(async () => {
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/path/to/privatekey',
ignores: ['node_modules/**/*'],
})
const previewResult = await ci.preview({
project,
desc: 'hello', // 此备注将显示在“小程序助手”开发版列表中
setting: {
es6: true,
},
qrcodeFormat: 'image',
qrcodeOutputDest: '/path/to/qrcode/file/destination.jpg',
onProgressUpdate: console.log,
// pagePath: 'pages/index/index', // 预览页面
// searchQuery: 'a=1&b=2', // 预览参数 [注意!]这里的`&`字符在命令行中应写成转义字符`\&`
})
console.log(previewResult)
})()
# parameter
| key | type | Required to fill in | Introductions |
|---|---|---|---|
| project | IProject | yes | # Project objects |
| desc | string | no | Custom remarks, displayed in the Weixin Mini Program Assistant development list |
| setting | object | no | # Compile the settings |
| onProgressUpdate | function | no | Progress update listening function |
| robot | number | no | Specify which ci droid to use, optional: 1 ~ 30 |
| qrcodeFormat | string | no | Returns the QR code file format"image"or"base64",Default value"terminal"for debugging |
| qrcodeOutputDest | string | yes | QR code file saving path |
| pagePath: | string | no | Preview page path |
| searchQuery: | string | no | Preview page path startup parameters |
| scene | number | no | Default value1011, see Scenario Values List |
# return
| key | type | Required to fill in | Introductions |
|---|---|---|---|
| subPackageInfo | Array<{name:string, size:number}> | no | Weixin Mini Program package information,nameis__FULL__``nameis__APP__ |
| pluginInfo | Array<{pluginProviderAppid:string, version: string, size:number}> | no | Weixin Mini Program Plug-in Information |
# Building npm
Build npm](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html) functionality against [developer tools.
const ci = require('miniprogram-ci')
;(async () => {
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/path/to/privatekey',
ignores: ['node_modules/**/*'],
})
// 在有需要的时候构建npm
const warning = await ci.packNpm(project, {
ignores: ['pack_npm_ignore_list'],
reporter: (infos) => { console.log(infos) }
})
console.warn(warning)
// 可对warning进行格式化
/*
warning.map((it, index) => {
return `${index + 1}. ${it.msg}
\t> code: ${it.code}
\t@ ${it.jsPath}:${it.startLine}-${it.endLine}`
}).join('---------------\n')
*/
// 完成构建npm之后,可用ci.preview或者ci.upload
})()
| parameter | type | Required to fill in | Introductions |
|---|---|---|---|
| project | IProject | yes | Project Objectives |
| options.ignores | string[] | no | Specify rules that need to be excluded for building npm |
| options.reporter | function | no | Build a callback information |
# Pull the most recently uploaded version of sourceMap
const ci = require('miniprogram-ci')
;(async () => {
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/path/to/privatekey',
ignores: ['node_modules/**/*'],
})
await ci.getDevSourceMap({
project,
robot: 1,
sourceMapSavePath: './sm.zip'
})
})()
# parameter
| key | type | Required to fill in | Introductions |
|---|---|---|---|
| project | IProject | yes | # Project objects |
| robot | number | yes | Specify which ci droid to use, optional: 1 ~ 30 |
| sourceMapSavePath | string | yes | Paths saved |
# Build npm for custom node_modules location
Sometimes thenode_modulesthat need to be built might not be within the Weixin Mini Program project, so a new interface is provided to support this requirement.
For example, there are the following project structures
├── lib # lib目录存放要被构建的 node_modules
│ ├── node_modules
│ │ └── is-object
│ └── package.json
└── miniprogram-project # 这里是小程序项目路径
├── miniprogram # 我们希望最终把 miniprogram_npm 构建在 miniprogram/ 目录之下
│ ├── app.js
│ ├── app.json
│ ├── app.wxss
│ ├── pages
│ │ ├── index
│ │ └── logs
│ └── sitemap.json
└── project.config.json
So you can call it this way.
let packResult = await ci.packNpmManually({
packageJsonPath: './lib/package.json',
miniprogramNpmDistDir: './miniprogram-project/miniprogram/',
})
console.log('pack done, packResult:', packResult)
// Output pack done, packResult: {miniProgramPackNum: 0, otherNpmPackNum: 1, warnList: []}
The final project obtained
.
├── lib
│ ├── node_modules
│ │ └── is-object
│ └── package.json
└── miniprogram-project
├── miniprogram
│ ├── app.js
│ ├── app.json
│ ├── app.wxss
│ ├── miniprogram_npm # <--- 这就是构建出来的由 lib/node_modules 里 miniprogram_npm 了
│ ├── pages
│ └── sitemap.json
└── project.config.json
| parameter | type | Required to fill in | Introductions |
|---|---|---|---|
| options.packageJsonPath | string | yes | Path ofnode_modulescorresponding topackage.json |
| options.miniprogramNpmDistDir | string | yes | Target location ofminiprogram_npmTarget location |
| options.ignores | string[] | no | Specify rules that need to be ruled out |
# Upload cloud development cloud functions
The cloud function upload capability for](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html) cloud development ](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html) ](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/capabilities.html#%E4%BA%91%E5%87%BD%E6%95%B0) Developer Tools].
const ci = require('miniprogram-ci')
;(async () => {
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/path/to/privatekey',
ignores: ['node_modules/**/*'],
})
const result = await ci.cloud.uploadFunction({
project,
env: '云环境 ID',
name: '云函数名称',
path: '云函数代码目录',
remoteNpmInstall: true, // 是否云端安装依赖
})
console.warn(result)
})()
| parameter | type | Required to fill in | Introductions |
|---|---|---|---|
| project | IProject | yes | Project Objectives |
| env | string | yes | Cloud Environment ID |
| name | string | yes | Name of the cloud function |
| path | string | yes | Cloud Function Code Directory |
| remoteNpmInstall | boolean | no | Whether the cloud installation depends, the default is false |
RemoteNpmInstallAdditional note: true Cloud installation dependency, will not upload localnode_modules, falseFull volume uploads, including uploadingnode_modules.
# Upload cloud to develop static websites / cloud storage
Corresponding developer tools Cloud development Static website hosting](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/staticstorage/introduction.html) and upload capabilities in cloud storage](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/storage.html) .
Need to install the alpha version:npm install --save miniprogram-ci @ alpha
const ci = require('miniprogram-ci')
;(async () => {
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/path/to/privatekey',
ignores: ['node_modules/**/*'],
})
// 静态网站
const resultStatic = await ci.cloud.uploadStaticStorage({
project,
env: '云环境 ID',
path: '本地文件目录',
remotePath: '要上传到的远端文件目录',
})
// 云存储
const resultStorage = await ci.cloud.uploadStorage({
project,
env: '云环境 ID',
path: '本地文件目录',
remotePath: '要上传到的远端文件目录',
})
console.warn(resultStatic, resultStorage)
})()
| parameter | type | Required to fill in | Introductions |
|---|---|---|---|
| project | IProject | yes | Project Objectives |
| env | string | yes | Cloud Environment ID |
| path | string | yes | Local file directory |
| remotePath | boolean | no | The remote file directory to be uploaded |
# New cloud development cloud-hosted version
Cloud hosting New version capability for](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html) Cloud development ](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html) ](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/container/) Cloud hosting] [[TAG-1-NED]] Cloud hosting [[T@@
Need to install the alpha version:npm install --save miniprogram-ci @ alpha
const ci = require('miniprogram-ci')
;(async () => {
const project = new ci.Project({
appid: 'wxsomeappid',
type: 'miniProgram',
projectPath: 'the/project/path',
privateKeyPath: 'the/path/to/privatekey',
ignores: ['node_modules/**/*'],
})
const result = await ci.cloud.uploadContainer({
project,
env: '云环境 ID',
version: {
uploadType: 'package', // 上传方式
flowRatio: 0, // 流量比例
cpu: 0.25, // CPU 核心数
mem: 0.5, // 内存大小
minNum: 0, // 最小副本数
maxNum: 1, // 最大副本数
policyType: 'cpu', // 扩缩容条件
policyThreshold: 60, // 扩缩容阈值
containerPort: 80, // 容器监听端口
serverName: 'server', // 服务名称
versionRemark: 'ci', // 版本备注
envParams: '{}', // 环境变量
buildDir: '', // 构建目录
dockerfilePath: '' // Dockerfile 路径
},
containerRoot: 'the/path/to/container' // 需要上传的版本文件目录
})
console.warn(result)
})()
| parameter | type | Required to fill in | Introductions |
|---|---|---|---|
| project | IProject | yes | Project Objectives |
| env | string | yes | Cloud Environment ID |
| containerRoot | string | yes | Local container file directory |
| version.uploadType | string | yes | Upload type (package / repository / image) |
| version.flowRatio | number | yes | Default traffic ratio after new version |
| version.cpu | number | yes | Number of CPU cores (refer to container specifications ) |
| version.mem | number | yes | Memory size (refer to container specification ) |
| version.minNum | number | yes | Minimum number of copies |
| version.maxNum | number | yes | Maximum number of copies |
| version.policyType | string | yes | Expansion conditions, currently only supported: cpu |
| version.policyThreshold | number | yes | Enlarged tolerance threshold |
| version.containerPort | number | yes | Container listening ports |
| version.serverName | string | yes | Service Name |
| version.versionRemark | string | no | Version Notes |
| version.dockerfilePath | string | no | Dockerfile path |
| version.buildDir | string | no | Build a directory |
| version.envParams | string | no | Environmental variables |
# Proxy
Miniprogram-ci uses the get-proxy module to automatically get the proxy address.
If you do not apply theci.proxy (]]method or the--proxy]]parameter to specify a proxy, miniprogram-ci will fetch the https proxy address in the following order
- Get the
HTTPS_PROXY in the context variable - Gets the
https_proxy in the context variable - Get the
HTTP_PROXY in the context variable - Get the
http_proxy in the context variable - Get the
https-proxy for npm configuration - Get the
http-proxy for npm configuration - Gets the
proxy for the npm configuration - Add
servicewechat.comno_proxy`, miniprogram-ciNo network requests will be sent through proxies
const ci = require('miniprogram-ci')
ci.proxy('YOUR_PROXY_URL')
# Command line calls
npm install -g miniprogram-ci
#help
miniprogram-ci --help
#preview
miniprogram-ci \
preview \
--pp ./demo-proj/ \
--pkp ./private.YOUR_APPID.key \
--appid YOUR_APPID \
--uv PACKAGE_VERSION \
-r 1 \
--enable-es6 true \
--proxy YOUR_PROXY \
--qrcode-format image \
--qrcode-output-dest '/tmp/x.jpg' \
#upload
miniprogram-ci \
upload \
--pp ./demo-proj/ \
--pkp ./private.YOUR_APPID.key \
--appid YOUR_APPID \
--uv PACKAGE_VERSION \
-r 1 \
--enable-es6 true \
#pack-npm
miniprogram-ci \
pack-npm \
--pp ./YOUR_PROJECT/ \
--pkp ./private.YOUR_APPID.key \
--appid YOUR_APPID \
#pack-npm-manually
miniprogram-ci \
pack-npm-manually \
--pack-npm-manually-package-json-path PACKAGE_JSON_PATH \
--pack-npm-manually-miniprogram-npm-dist-dir DISTPATH
#cloudbase upload cloudfunction
miniprogram-ci cloud functions upload \
--pp ./YOUR_PROJECT/ \
--appid YOUR_APPID \
--pkp ./private.YOUR_APPID.key \
--env YOUR_CLOUD_ENV_ID \
--name YOUR_CLOUD_FUNCTION_NAME \
--path ./YOUR_CLOUD_FUNCTION_FOLDER_PATH/ \
--remote-npm-install true
#proxy
export HTTPS_PROXY = YOUR_PROXY_URL # 可以在shell脚本里声明临时proxy
miniprogram-ci \
upload \
--pp ./demo-proj/ \
--pkp ./private.YOUR_APPID.key \
--appid YOUR_APPID \
--uv PACKAGE_VERSION \
-r 1 \
--enable-es6 true \
--proxy YOUR_PROXY_URL # 也可以使用这个参数声明proxy
#get dev source map
miniprogram-ci \
get-dev-source-map \
--pp ./demo-proj/ \
--pkp ./private.YOUR_APPID.key \
--appid YOUR_APPID \
-r 1 \ # 获取具体哪个robot最近上传的版本的sourceMap
--source-map-save-path ./sourcemap.zip #保存路径,推荐zip结尾,最后得到的是一个zip包
# Compile settings
| key | type | Introductions |
|---|---|---|
| es6 | boolean | "es6 to es5" for Weixin Mini Program developer tools |
| es7 | boolean | "Enhanced Compilation" for Weixin Mini Program developer tools |
| minifyJS | boolean | Compress JS Code |
| minifyWXML | boolean | Compressing WXML code |
| minifyWXSS | boolean | Compressing WXSS code |
| minify | boolean | Compress all code, corresponding to the Weixin Mini Program developer tool "compress code" |
| codeProtect | boolean | Code protection for Weixin Mini Program developer tools |
| autoPrefixWXSS | boolean | Style autocompletion for Weixin Mini Program developer tools |
About Weixin Mini Program Developer Tools Code Compilation Options
# Third Party Platform Development
Miniprogram-cisupports the upload and preview of Third Party Platform development from1.0.28in the same way as in normal development mode.
When using the Third Party Platform development pattern, note that:
- Make sure that the correct
ext.json exists in the project - The key file is the key file for Third Party Platform bound development Weixin Mini Program
AppID - The IP whitelist is the development of Third Party Platform bindings Weixin Mini Program
AppID - Calling the incoming
AppIDis Third Party Platform bound to develop Weixin Mini ProgramappidFor the Third Party Platform development model, please refer to here