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

@appflags/gitexporter

v1.5.3

Published

Utility for exporting private git repository commits to a open source public repository

Downloads

6

Readme

npm status gitexporter test status

gitexporter cli tool

You're in the right place if:

  • Do you have an open-source project with an open and closed part and you want to work in one git repo without git submodules?
  • Do you want to public some private GitHub repo directories?
  • You want to keep the authorship and history of the comments
  • You don't want to use git submodules

Others cases:

  • You are developing in a git mono repository and want to open-source some directories
  • You are developing some OpenSource project and want to disallow open some secret files

how it works ?

gitexporter create a new git repo from your existing repository with only allowed public files and dirs.

The gitexporter goes through the git commit tree and adds to a new repo only the allowed files.

Example

  • / -- monorepository root
  • /apps/service1 -- it's open source
  • /apps/optional-secure-service2 -- it's closed source
  • /gitexporter.config.json -- git exporter config file

gitexporter.config.json

{
    "forceReCreateRepo": true,
    "targetRepoPath": "my-open-source-repo",
    "sourceRepoPath": ".",
    "allowedPaths": ["apps/service1/*"],
    "ignoredPaths": ["apps/service1/.env", "apps/optional-secure-service2", "gitexporter.config.json"]
}

Just run npx gitexporter gitexporter.config.json and you will get a new git repository with just apps/service1 directory.

GITHUB ACTIONS CI EXAMPLE

  1. create a new user: sync-bot
  2. add new user ssh keys SSH_SYNC_BOT_PRIVATE_KEY: https://github.com/settings/keys
  3. add the user to org/private and org/open repo
  4. add SSH_SYNC_BOT_PRIVATE_KEY to org/private repo
  5. add CI files to org/private repo:

.github/workflows/gitexporter.yml

name: gitexporter
on:
  push:
    branches:
      - 'master'

jobs:
  gitexporter:
    name: Gitexporter
    runs-on: self-hosted
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ssh-key: ${{ secrets.SSH_SYNC_BOT_PRIVATE_KEY }}
      - name: Checkout org/private
        uses: actions/checkout@v2
        with:
          repository: 'org/private'
          fetch-depth: 0
          submodules: recursive
          ssh-key: ${{ secrets.SSH_SYNC_BOT_PRIVATE_KEY }}
          path: gitexporter.source
          ref: 'master'
      - name: Checkout org/open
        uses: actions/checkout@v2
        with:
          repository: 'org/open'
          fetch-depth: 0
          submodules: recursive
          ssh-key: ${{ secrets.SSH_SYNC_BOT_PRIVATE_KEY }}
          path: gitexporter.target
          ref: 'master'
      - name: gitexporter.sh
        run: |
          bash .github/workflows/gitexporter.sh gitexporter.source gitexporter.target
          cat gitexporter.source.log.json

.github/workflows/gitexporter.sh

#!/usr/bin/env bash
set -eo pipefail

if [[ -z "$1" || -z "$2" ]]; then
  echo "use $0 <source-git-repo> <target-git-repo>"
  exit 2
fi

SOURCE_FOLDER=$1
TARGET_FOLDER=$2

echo "[GITEXPORTER]"
cat > ${SOURCE_FOLDER}.config.json <<EOF
{
  "forceReCreateRepo": false,
  "followByNumberOfCommits": true,
  "syncAllFilesOnLastFollowCommit": true,
  "logFilePath": "${SOURCE_FOLDER}.log.json",
  "targetRepoPath": "${TARGET_FOLDER}",
  "sourceRepoPath": "${SOURCE_FOLDER}",
  "allowedPaths": [
    "*"
  ],
  "ignoredPaths": [
    "secret/*"
  ]
}
EOF

npx gitexporter ${SOURCE_FOLDER}.config.json

echo "[TARGET/SETUP]"
cd ${TARGET_FOLDER}
git branch -D master || echo "no branch master"
git checkout -B master $(git rev-parse HEAD)
echo "[TARGET/PUSH]"
git push origin master
cd -
echo "[END]"