npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

miniprogram-ci-tools

v1.4.0

Published

miniprogram ci tools

Readme

小程序 CI/CD 工具

用于小程序自动化上传、预览的命令行工具。

✨ 特性

  • 更改 PP、PR 配置
  • 编译 Less、Typescript
  • 上传代码到微信小程序平台。

🚀 快速开始

安装

npm install miniprogram-ci-tools -D

使用

确保接入项目是标准的小程序项目

# 在项目根目录下执行
dkt-upload upload --ver 1.0.0 --desc "这是一个新的版本"

参数说明

  • upload: 上传指令
  • --ver: (必填) 本次上传的版本号,如 1.0.0
  • --desc: (可选) 本次上传的版本描述
  • --path: (可选) 小程序项目路径,默认为当前目录

配置文件

本工具会读取项目根目录下的 ci.config.js 文件来获取小程序相关的配置。

ci.config.js 示例如下所示:

module.exports = {
  miniprogramRoot: './',

  // 环境: 定义小程序相关环境配置
  environments: {
    PP: {
      appid: 'wx1234567890abcd',
      env: 'PP',
    },
    PR: {
      appid: 'wx0987654321abcd',
      env: 'PR',
    },
  },

  // 更新:定义需要修改哪些文件(主要是更改项目里的 appid 和切换 pp、pr 环境的配置)
  update: {
    files: [
      {
        path: 'project.config.json',
        type: 'json',
        key: 'appid',
        value: '{{appid}}', // {{appid}} 会被替换为上面 environments 中对应环境的 appid
      },
      {
        path: 'config/evnConfig.js',
        type: 'regex',
        // 这个正则表达式会找到 `EVN: '...'` 并替换引号内的内容
        pattern: "(EVN:\\s*['\"])([^'\"]+)(['\"])",
        value: '{{env}}', // {{env}} 会被替换为对应环境的 env 名称
      },
    ],
  },

  // 编译:定义需要编译哪些文件(主要是 less 和 ts)
  compile: {
    cleanup: true, // 编译后删除源文件
    rules: [
      {
        type: 'less',
        glob: '**/*.less', // 匹配所有 .less 文件
      },
      {
        type: 'ts',
        glob: '**/*.ts',
      },
    ],
  },

  // 上传
  upload: {
    ignores: ['node_modules/**/*'],
    // miniprogram-ci 的上传设置(可在此进行覆盖)
    setting: {
      // minify: true,
      // minifyWXML: true,
      // minifyWXSS: true,
    }
  },
};

Jenkins 中推荐通过 credential 注入私钥,不再把私钥文件路径写死在仓库配置里。

  • privateKey: 直接传入私钥内容或私钥文件路径,也可以写成 process.env.xxx
  • 默认读取固定环境变量 MINIAPP_PRIVATE_KEY
  • 如果环境变量的值是一个文件路径,会直接作为私钥文件使用
  • 如果环境变量的值是私钥内容,会在运行时生成临时文件并在上传完成后清理

推荐在业务项目中直接使用:

module.exports = {
  environments: {
    PP: {
      appid: 'wx1234567890abcd',
      env: 'PP',
      privateKey: process.env.MINIAPP_PRIVATE_KEY,
    },
  },
};

示例 Jenkins Pipeline:

pipeline {
  agent any
  stages {
    stage('Upload') {
      steps {
        withCredentials([string(credentialsId: 'wx1234567890abcd', variable: 'MINIAPP_PRIVATE_KEY')]) {
          sh 'npx dkt-upload --env PP --version 1.0.0 --desc "Jenkins build"'
        }
      }
    }
  }
}

如果 Jenkins 中保存的是文件类型 credential,可以把 string(...) 改成 file(...),变量名仍然使用 MINIAPP_PRIVATE_KEY

注意事项

  • IP 地址已被添加到小程序的 IP 白名单中或者关闭了白名单限制。
  • 已从开发者后台下载了上传小程序的私钥,并配置到 Jenkins credential。