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

gitftw

v1.0.0

Published

Basic git commands wrapped in node for using in your workflows

Downloads

14

Readme

gitftw - Git For The Workflows

npm version Build Status Coverage Status Dependency Status devDependency Status

Basic git commands wrapped in node for using in your workflows. This includes grunt, gulp, your custom scripts, CI, etc...

http://jmendiara.github.io/gitftw/

Installation

npm install gitftw --save-dev

Basic Usage

var git = require('gitftw');

//Executes locally installed git with the parameters specified as an array
// > /usr/local/bin/git tag 
git(['tag'], function(err, output) {
  if (err) {
    console.error('Command failed with code %d: %s', err.code, err.message);
    return;
  }
  console.log(output); // "'v1.0.0\nv1.0.1\nv1.0.2'" 
});

Commands

There are some basic commands implemented for you, in a workflow developer friendly way.

var git = require('gitftw');

git.pull({
    remote: 'origin',
    branch: 'master',
    rebase: true
  }, cb);
  
git.add({
    files: ['README.md', 'package.json']
  }, cb);

//removing all local tags
git.getTags(function (err, tags) {
  if (err) {
    return cb(err);
  }
  console.log(tags);  //['v1.0.0', 'v1.0.1', 'v1.0.2']
  git.removeLocalTags({
      tags: tags
  }, cb);
})

All the commands can take 2 parameters, an optional options literal object, and the optional callback. A literal object helps you having configurations in a json, a grunt config, etc... even in a function! (read below)

More information on implemented commands, please refer to the documentation

Knowing what's happening under the hoods

Yes, it's important to see wat is doing an automated workflow. We have some events for you.

var git = require('gitftw');

//Add a listener to the issued git command. Output it
git.events.on('command', console.info);

//Add a listener to the result of the git command. Output it with > 
git.events.on('result', function(res) {
  console.log('> ' + res.split('\n').join('\n> '))
});

Sugar: Promises

git and its commands have a dual API, both the node callback style you have seen in the examples, and the promise style. Bluebird is used internally as the promises library

//removing all local tags
git.getTags()
  .tap(console.log) //['v1.0.0', 'v1.0.1', 'v1.0.2']
  .then(function (tags) {
    return git.removeLocalTags({
      tags: tags
    })
  });

Having promises internally and optionally outside simplifies the development of commands to manage concurrency when issuing git commands with a more functional style.

Why concurrency matters? Not having concurrency accessing the filesystem, where some commands can change its status, is very important for a predictable command sequence. Think on how you use git from the command line. We wanna make this tool for workflows as much predictable as possible. And the resolvable concept helps on both serialization and functional style development

DISCLAIMER for node fan-boys: frontenders are also developers. And are bored of your if(err) return cb(err); verbose style. And I've always wanted to code something dual :)

Advanced usage: Resolvables

You can use resolvables things when calling this library methods. Resolvable is something that have invariant primitives, including all its properties, now or in the future.

Which things are resolvables?

  1. A String, Number, Boolean primitives: string, 4, true

  2. A array of resolvables: ['string', resolvable]

  3. A literal object with resolvables properties: { foo: 'string', bar: resolvable }

  4. An object with a toString method

  5. An A+ promise (Q, bluebird, native...) that resolves to a resolvable: Promise.when('string')

  6. A function that returns resolvables function() { return 'string'; }

resolvables are resolved in serie. Once something is resolved, goes to resolve the next one. Never in parallel. This avoids race conditions in your workflows while maintaining your code clean.

It's easier than you think. The above remove all tags example with resolvables:

//removing all local tags
git.removeLocalTags({
  tags: git.getTags //Command that returns a promise for an array of strings
});

git.getTags, as it's used as a function parameter, will be called, resolved and assigned before git.removeLocalTags gets called.

Take a look to the tests.

License

MIT