Skip to content

Instantly share code, notes, and snippets.

@DamonOehlman
Last active June 13, 2021 20:22
Show Gist options
  • Save DamonOehlman/19b4025d08c93d0c890c2c33339ae262 to your computer and use it in GitHub Desktop.
Save DamonOehlman/19b4025d08c93d0c890c2c33339ae262 to your computer and use it in GitHub Desktop.
How to prepare for going offline

The following is an "oh noes, where's my Internet" guide to surviving as a coder with no or limited Internet. Primarily the guide is focused on those who will be doing JS development (and using npm as a package manager) but some of the advice is useful for other environments also.

Step 1. Clone all things

Tooling in this steps require that you have git installed, and use github for your repositories.

One thing I really like to do when I get a bit of time offline, is clean up an old repository that I once thought was useful. I rarely know about what project this might be in advance. As a result, I like to clone all the things from my personal github account.

To do this I recommend using multirepo, which is best installed (at the moment) like so:

npm install -g https://github.com/maxogden/multirepo

If you've used multirepo before you probably have your own process for this, but if not here's what I'd recommend:

  • create a new directory where you are going to clone everything too, say something like ~/code/offline/me

  • next, in that directory run multirepo pull

    You should see output similar to the following, prompting you for username, password and MFA token:

    [damo@djomac me]$ multirepo pull
    Your GitHub username: DamonOehlman
    Your GitHub password: ✔✔✔✔✔✔✔✔✔✔✔
    
    Your GitHub OTP/2FA Code (optional): ******
    

    If you hit an error during the github authentication it could be because you have used multirepo before and you have a personal access token that needs to be removed so you can reauthenticate.

    Using multirepo pull is a nice one-shot command that ensures you bring both clone and pull the repos from GitHub down to your local machine.

Step 2. Prefetch your dependencies

Assuming you are using npm for managing packages, this is something I've written a script for before for myself (and recently tweaked). To get this script (and some of it's friends) you can install using npm:

npm install -g djo-shell

This is simply a collection of bash scripts that I find useful from time to time. If you'd rather not install the package, then feel free to curl down the script itself.

Once the script is available, simply change directory to where your offline cloned repos exist ~/code/offline/me is where I put mine in this exercise, and run the following command:

npm-all-the-things

Alternatively, you can also use yarn:

yarn-all-the-things

What will happen now is the npm-all-the-things script will iterate through all the child directories of the directory you are in, and if it located a package.json file in that directory it will remove the node_modules directory, and will then do an npm install --min-cache 99999 in that directory. I had previously been using local-npm for going offline, but according to this deprecation notice the npm --min-cache option is just as good.

If you cloned a few repos, then this will generate a lot of output. Some of it useful, some of less so. It will, however, ensure that whatever remote dependencies are pulled down and cached. There will be some of your packages that will likely fail though (perhaps because you initially built it on a different platform, or it's just unloved). In these cases, the project folders will contain a .npm-resync-fail file (see the list below), which can give you a good idea of what projects you might need to fix before tweaking offline.

[damo@djomac me]$ find . -name .npm-resync-fail
./beandat/.npm-resync-fail
./deckem/.npm-resync-fail
./dilemma-server/.npm-resync-fail
./easyusb/.npm-resync-fail
./guidebook/.npm-resync-fail
./jsonite/.npm-resync-fail
./localo/.npm-resync-fail
./node-dilemma/.npm-resync-fail
./node-gh-controller/.npm-resync-fail
./nokku/.npm-resync-fail
./pull-portal/.npm-resync-fail
./rtc.io-guidebook/.npm-resync-fail
./skelesense/.npm-resync-fail
./talk-bedazzle-intro/.npm-resync-fail

Some good alternative options, are listed in this post also:

https://addyosmani.com/blog/using-npm-offline/

Contributing to another project

If you decide that you'd like to help out with another open source project over the weekend, then probably the simplest way to do this is to fork the project on github that you have been thinking about working with, and then running multirepo again.

Here's some output after I ran multirepo again after fixing a few of my old repos and also cloning choo:

[damo@djomac me]$ multirepo pull
Checking for repos with new pushes since 2016-05-27T10:10:08.385Z
Loading repo metadata from GitHub API (page 1)...
4 repo(s) with new pushes have been found
Pulling repo DamonOehlman/beandat...
Pulling repo DamonOehlman/jsonite...
Pulling repo DamonOehlman/djo-shell...
Cloning repo DamonOehlman/choo...
Cloned 1 new repos, skipped 0 existing repos, pulled 3 existing repos.

Then, just run npm-all-the-things again to pick up any new package installs.

@map7
Copy link

map7 commented Jun 1, 2016

@ahdinosaur
Copy link

hey cats, for a social network that works offline (over local wifi), check out Patchwork (built on scuttlebot)! i'll be bringing some flash drives with a copy in case anyone needs to install.

@DamonOehlman
Copy link
Author

DamonOehlman commented Jul 31, 2017

Folks - in the event that you are seeing a 401 response from the github api when running multirepo you probably have (like me) an old authentication token kicking around. So, just delete that (e.g. rm ~/.config/multirepo-github.json) and you should be ok.

@garrows
Copy link

garrows commented Aug 2, 2017

Be sure to check out the list of preinstalls too campjs/campjs-viii#41

@chris-sab
Copy link

Thank you for good reivew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment