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

git-remote-update

v0.0.8

Published

A simple object to watch for git repo changes and update the local code

Downloads

9

Readme

git-remote-update

This library exposes a single object to watch for a remote git repo changes, and to update a local git repo. It is intended to work well with github.

Its process is quite simple, and was not designed to handle out-of-the-box situations where the updated code has received commits from another source than the one being watched. By the way, it is quite generic so it probably can be easily used to do so.

The git client used is the excellent nodegit.

Install

npm install git-remote-update --save

Use

const GitWatcher = require('git-remote-update');

Intended use case

You own a server, which hosts a process (a web service, a bot, etc).

You want to update the code on your server by using github (or any other remote git repo). Each time you push a change on the dedicated github repo from your personal computer, you want the server to update its code.

Do the following:

  • Create a repo on github and put your code in (including git-remote-update handlers)
  • Clone the repo on your server
  • On your server, start your script with forever; this is a client that will restart your script if it ends
  • On your code, there should be something like that, which will simply kill your script after an update is done (and forever will gently restart it):
const gw = new GitWatcher({
    git: './.git'
});

gw.on('ready', () => gw.watch());
gw.on('newerCommit', () => gw.update());
gw.on('updated', () => process.exit());

API

This library exposes the GitWatcher class. GitWatcher is a simple event emitter.

new GitWatcher(config)

The config is an object with the following values:

Option | Description | Default ------------ | ------------------------------------------------------------------------- | --------------- git | Location of the git file (relative to the script entry point, or fullpath) | './.git' remoteBranch | The branch to get update from | 'origin/master' localBranch | The branch to be updated | 'master'

fetch()

Look once at the remote branch.

watch(interval)

Call fetch each interval (in ms, default 30000), so it can look for changes on the repo over time. Returns a function that you can call to stop watching.

update()

Performs merge from remote branch to localBranch.

on(event, callback)

Call the callback function when the corresponding event is fired.

Event | Description | Callback parameters --------------- | ------------------------------------------------------------------------- | ------------------------- ready | The object is ready, so you can call fetch or watch | - comparison | A comparison is done, so you can make your own comparison function | remoteCommit, localCommit newerCommit | There is a more recent commit on the remote branch | remoteCommit, localCommit differentCommit | The last commit id on the remote branch is different from the local | remoteCommit, localCommit updated | Update is done | - error | An error happened | error

remoteCommit and localCommit are commit objects from nodegit, you can have documentation for them on nodegit website.