DEV Community

KartikJha
KartikJha

Posted on

1 3

Bundle github repos for offline sharing

Looking for a script that will archive the huge repo you've been wanting to archive well here it is...

bundle-repo.js

const chalk = require("chalk");
const { execSync, exec } = require("child_process");
// const fs = require('fs');

if (!process.argv[2] || !process.argv[3]) {
  console.log(
    chalk.red(
      "Usage: node bundle-repo OWNER REPO-STRING [BUNDLE-TARGET-DIR]\nExample: node bundle-repo 'twitter' 'main, side, boom'"
    )
  );
  return;
}

const prefix = "git@github.com:";

const finalDir = process.argv[4] ? process.argv[4] + "/" : "";

const getPath = (r) => (!finalDir ? "" : finalDir + r);

process.argv[3].split(",").forEach((r) => {
  execSync(
    `git clone ${prefix}${process.argv[2]}/${r.trim()} ${getPath(r.trim())}`
  );
  const a = execSync(`ls -la ${getPath(r.trim())}`);
  console.log(a.toString());
  if (a.toString().split('\n')[0].split(' ')[1] != 0) {
    execSync(
      `cd ${getPath(
        r.trim()
      )} && git bundle create ${r.trim()}.bundle --all && mv ${r.trim()}.bundle .. && cd .. && rm -rf ${r.trim()}`
    );
  }
});
Enter fullscreen mode Exit fullscreen mode

package.json

{
  "type": "module",
  "dependencies": {
    "chalk": "^3.0.0"
  }
}
Enter fullscreen mode Exit fullscreen mode

Before you get busy with it please follow this setup to avoid any operational glitches

  1. Setup SSH access for your github account which has access to the repos. Connect to github via SSH

  2. Create a string of comma seprated repo names like "repo1, repo2", the script has a usage example built in

  3. Pass the repo string and owner/organization string as input to the string like

node bundle-repo 'twitter' 'main, side, boom' [optional target directory]
Enter fullscreen mode Exit fullscreen mode

That's it you are good to go. Checkout the code on github

Thank you for reading :)

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs