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

@lzwme/git-repo-sync

v1.0.4

Published

a tool for git repo sync

Downloads

22

Readme

@lzwme/git-repo-sync

@lzwme/git-repo-sync

NPM version node version npm download GitHub issues GitHub forks GitHub stars

git 多仓库代码同步辅助工具。

应用场景:

当某个 npm 包在内部 npm 私域和 npmjs 上均有发布,但从内部向外部同步部署时,可能需要过滤敏感信息、替换一些不同的内容。 这个工作是重复且枯燥的,此时 grs 小工具或许能帮助到你。

特点:

  • 仓库文件同步
  • 支持文件内容匹配替换
  • 支持文件过滤
  • 支持执行自定义命令(配置文件)
  • 支持 git commit 提交记录同步(最近一条)
  • more...

示例:

初始化一个同步目录:

执行 grs 同步(无更新):

执行 grs 同步(有更新):

安装

# use npm
npm i -D @lzwme/git-repo-sync
# use yarn
yarn add -D @lzwme/git-repo-sync
# use pnpm
yarn add -D @lzwme/git-repo-sync

使用

命令行方式

可通过命令行执行,临时的进行手动同步:

grs --help
# 复杂的内容替换规则建议使用配置文件方式。新增 .grs.confg.js 配置文件,然后执行:
grs --debug
# 示例: 指定配置文件
grs -c .grs.config.js

也可结合 husky@7 配置至 git hooks 中,如 post-commit

# 在项目中安装 husky
yarn add -D husky
yarn husky install

# 创建 post-commit hook
yarn add .husky/post-commit "yarn grs -c .grs.config.js"

API 调用

提供了如下 API 调用方式:

import { grs } from '@lzwme/git-repo-sync';

const total = grs.sync({
  silent: true,
  git: {
    commit: true,
    rebase: true,
    push: true,
  }
});
console.log(total);

配置文件参考

// .grs.config.js
const path = require('path');

module.exports = {
  src: process.cwd(),
  dest: path.resolve(process.cwd(), `../${path.basename(process.cwd())}-sync`),
  silent: false,
  exclude: [/(\/|\\)\.git(\/|\\)/, 'dist', '.nyc', 'node_modules', '.grs.config.js'],
  include: ['src', 'package.json', 'readme.md'],
  replaceRules: [
    {
      /** 文件匹配规则,如不存在则表示匹配所有文件 */
      match: /README\.md/i,
      list: [
        {
          /** 匹配关键词,若为空则忽略 */
          from: '@test',
          /** 替换为 */
          to: '@lzwme',
        },
        {
          /** 匹配关键词,若为空则忽略 */
          from: /^\[.+\n/gm,
          /** 替换为 */
          to: '',
        },
      ],
    },
    {
      /** 文件匹配规则,如不存在则表示匹配所有文件 */
      match: /package\.json/i,
      list: [
        {
          /** 匹配关键词,若为空则忽略 */
          from: '@test',
          /** 替换为 */
          to: '@lzwme',
        },
      ],
    },
    {
      /** 文件匹配规则,如不存在则表示匹配所有文件 */
      match: null,
      list: [
        {
          from: 'https://gitlab.com/lzwme/fed-lint-helper',
          to: 'https://github.com/lzwme/fed-lint-helper',
        },
      ],
    },
  ],
  /** git 同步选项 */
  git: {
    /** 是否执行 commit */
    commit: true,
    /** 是否执行 rebase。适合多人协作的场景 */
    rebase: false,
    /** 是否执行 push */
    push: false,
    /** 是否跳过 git hooks。默认 false */
    noVerify: false,
  },
  /** 在 dest 同步目录执行的命令列表 */
  cmds: [],
};

开发

本地二次开发:

git clone https://github.com/lzwme/git-repo-sync
yarn install
npm link
yarn dev

或者 fork 本项目进行代码贡献。

欢迎贡献想法与代码。

License

@lzwme/git-repo-sync is released under the MIT license.

该插件由志文工作室开发和维护。