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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wx-sab/fe-devops-tools

v2.0.1

Published

sab 开发平台自动化脚本仓库

Downloads

39

Readme

@wx-sab/fe-devops-tools

前端项目发布插件

Features

  • [x] 自动创建版本
  • [x] 自动发布对应环境
  • [x] 遵循 git 工作流
  • [x] drone 版本号动态传递
  • [x] 同一镜像多环境发布

TODOS:

  • [ ] 消息通知: 合并失败、构建失败、发布失败

使用

安装

pnpm add -D @wx-sab/fe-devops-tools

配置

自动读取 sab-deploy.config.ts 或者 sab-deploy.config.js 或者 sab-deploy.config.json 文件的配置

import { defineConfig } from '@wx-sab/fe-devops-tools'

export default defineConfig({
  // 开发平台对应的项目名
  projectName: string;
  // 开发平台对应的应用名
  appName: string;

  // 开发平台的账号密码
  // 默认 「前端发布专用」账号,14757609802
  accountId: string;
  password: string;

  // 发布的版本号,默认取 package.json的 version
  version: string;
  // 当前的分支
  branch: string;

  // 是否自动创建版本
  autoCreateVersion: boolean;

  // 需要自动发布的环境 Map, 分支 -> 环境
  /** 如下:
   * {
   * dev: "dp-dev",
   * qa: "dp-qa",
   * release: "dp-pre",}
   */
  autoReleaseEnvs: Record<string, string | string[]>;
  
  // 是否遵循 sab-fe 分支规范
  // http://10.101.7.31:10086/doc/23/
  // ../../source/git-flow.png
  enableSabGitFlow?: boolean;

  // 自动合并分支配置
  mergeBranch?: {
    // git 仓库的远程地址,请允许访问
    remote: string;
    // 允许操作远程仓库的 用户名和密码
    username: string;
    password: string;

    // 匹配分支
    matchBranch: {
      // 源分支
      sourceBranchs: string[];
      // 目标分支
      targetBranch: string;
    }
  };
  // 消息推送配置
  notify?: {
    // 暂时只支持钉钉机器人
    type: "dingtalk";
    // 钉钉机器人 token
    ddBotToken: string;
    // 钉钉机器人秘钥, 机器人安全设置页面,加签一栏下面显示的SEC开头的字符串
    ddBotSecret: string
  };
})

环境变量

| 变量名 | 说明 | 默认值 | | ---- | ---- | ---- | | DEVOPS_PLATFORM_ACCOUNTID | 开发平台用户名 | 无 | | DEVOPS_PLATFOEM_PASSWORD | 开发平台密码 | 无 | | DEVOPS_GIT_USERNAME | git用户名(如果需要自动合并功能的话) | 无 | | DEVOPS_GIT_PASSWORD | git密码(如果需要自动合并功能的话) | 无 |

指令

校验版本

  npx sab-deploy version-check --branch ${DRONE_BRANCH}

发布版本

  npx sab-deploy release --branch ${DRONE_BRANCH}

合并分支

npx sab-deploy merge-branch --branch ${DRONE_BRANCH}

通知推送

Git 工作流(试运行)

http://10.101.7.31:10086/doc/23/

./source/git-flow.png

约定

  • main/master分支: 主干分支,代码发布上线后需合并回该分支,并打上 tag
  • dev分支: 开发分支,所有当前正在开发的需求可以合到当前分支,会自动发布开发环境
  • ~~qa分支: 测试分支,提供给测试同学进行功能测试的分支,会自动发布到测试环境~~
  • release分支,最新的可上生产环境的分支,该分支的代码都是经过测试的可靠代码,该分支需手动发布
  • feature/* 分支,需求分支,当有新需求的时候从 release(推荐) 或者 master 新建的分支,在需求结束后合并进release分支,并删除
  • hotfix分支,修复分支,用于解决线上问题的分支,从master分支新建的分支,当验证完毕后合并 release并删除

参考 drone 配置

# 参考配置
kind: pipeline
name: dp-web-next
platform:
  os: linux
  arch: amd64

steps:
  # 自动合并分支
  - name: merge_branch
    image: alpine/git:v2.26.2
    commands:
      - git clone --single-branch -b dev http://oauth2:[email protected]/dp/dp-web-next.git
      - cd dp-web-next
      - git remote set-branches origin '*'
      - git fetch origin ${DRONE_COMMIT_BRANCH}
      - git merge --no-ff origin/${DRONE_COMMIT_BRANCH} -m '${DRONE_COMMIT_MESSAGE}'
      - git push origin dev
    volumes:
      - name: drone_home
        path: /root
    when:
      branch:
        - feature/*

  #自动校验版本
  - name: check_version
    image: node:16.18.1-alpine
    commands:
      # - npm config set registry https://registry.npmmirror.com
      - npm install -g pnpm@8
      - pnpm install
      - npx sab-deploy version-check --branch ${DRONE_BRANCH}
    volumes:
      - name: drone_cache
        path: /drone/src/.pnpm-store
    when:
      branch:
        - dev
        - qa
        - release

  # 校验版本
  - name: kmsp_validate
    image: kmsp/kmsp-plugin-drone:1.2.0
    settings:
      method: validate
      debug: true
      server: http://10.10.255.106:12330
    when:
      branch:
        - dev
        - qa
        - release

  # 前端构建
  - name: build
    image: node:16.18.1-alpine
    commands:
      # - npm config set registry https://registry.npmmirror.com
      - npm install -g pnpm@8
      - pnpm install
      - pnpm run build
    volumes:
      - name: drone_cache
        path: /drone/src/.pnpm-store # container path, must be an absolute path(pipeline default working directory is /drone/src https://docs.drone.io/pipeline/docker/syntax/workspace/)
    when:
      branch:
        - dev
        - qa
        - release

  # docker镜像构建
  - name: docker_build
    image: kmsp/docker:18.09
    settings:
      insecure: true
      password:
        from_secret: registry_password
      purge: true
      registry: 10.10.255.105:8000
      repo: 10.10.255.105:8000/kmsp-${DRONE_REPO_NAMESPACE}/${DRONE_REPO_NAME}
      username: admin
    when:
      branch:
        - dev
        - qa
        - release

  # feedback
  - name: kmsp_feedback
    image: kmsp/kmsp-plugin-drone:1.2.0
    settings:
      method: feedback
      server: http://10.10.255.106:12330
    failure: ignore
    when:
      status:
        - failure
        - success

  # 自动发布
  - name: auto-release
    image: node:16.18.1-alpine
    commands:
      # - npm config set registry https://registry.npmmirror.com
      - npm install -g pnpm@8
      - pnpm install
      - npx sab-deploy release --branch ${DRONE_BRANCH}
    volumes:
      - name: drone_cache
        path: /drone/src/.pnpm-store
    when:
      branch:
        - dev
        - qa
        - release

volumes:
  - name: drone_home
    host:
      path: /data/drone/home
  - name: drone_cache
    host:
      path: /data/drone/cache

trigger:
  branch:
    - dev
    - qa
    - release
    - feature/*
  event:
    - push