Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

prepush

royriojas2kMIT3.1.11

Yet another prepush script that will run tasks defined in a config file

pre-push, prepush, hooks, git, hooks, enforce, git, workflow

readme

NPM Version Build Status

prepush

Yet another prepush module that will run tasks defined in a config file or in a package.json file, stashing anything that is not supposed to be pushed before run the scripts to avoid false positives

Motivation

All the other modules similar to this one were specifying the prepush tasks in the package.json file. While this is ok I needed to have it defined in a separated config file. Also I needed to have the option to interactively ask the user to decide what to do in case a push was done with a dirty state (uncommited/untracked files)

screenshot

You might also like: precommit. A module to install a script for the pre-commit git hook inspired by this module, and changelogx which also provide a script for the commit-msg git hook.

Install

# install it as a dev-dependency.
npm i --save-dev prepush

# install the hook, passing the path to the config. If none is provided it will try to use the `package.json`
./node_modules/prepush/bin/cli.js install -c ./path/to/your/config

Using a custom prepush.json

{
  "prepush" : [ "npm test" ]
}

or in your package.json file

{
  "prepush" : [ "grunt prepush" ]
}

or as an object in a custom.json file or in package.json add the following section

{
  "prepush" : {
    // the tasks to run
    "tasks" : [ "grunt prepush" ],
    // What to do in case of a dirty state
    // ask   => Show a prompt to the user to decide what to do, stash or fail.
    // fail  => Simply refuse to push something when you have uncommited/untracked files
    // stash => If there are uncommited/untracked files stash them, do the push and restore the stash
    //          This will also move untracked files into the stash
    "onDirtyState": "ask", // <== fail or stash,
    "coloredOuput" : true // <== true or false. If ommited it will try to use the env variable `__CLIX_COLORED_OUTPUT__` (from `clix` module)
  }
}

Important Be aware that if you cancel the program using CTRL+C then the stash might not be restored. So you will have to restore it manually. TODO: trap the SIGINT event and restore the stash transparently for the user.

cli usage

The following are the options available on the cli command that install/remove the hook. To pass options to the hook. Please use the prepush section on your config file or in the package.json file.

Yet another `prepush` module that will run tasks defined in a config file or in a package.json file, stashing anything that is not supposed to be pushed before run the scripts to avoid false positives!

========================================================
Usage: prepush -c [path/to/config/file] [install|remove]
========================================================

  -h, --help           Show this help
  -v, --version        Outputs the version number
  -q, --quiet          Show only the summary info - default: false
  --colored-output     Use colored output in logs
  -c, --config String  Path to your `prepush` config, if not provided will try to use the `package.json` file in your current working directory, expecting an
                       entry called `prepush`

Note: The colored-output in the cli is only for logs during installing/removing the hook.

If you want to enable the colored logs in the actual prepush hook, please include the option coloredOutput in your prepush section. Like this:

{
  "prepush": {
    // the tasks to run
    "tasks" : [ "grunt prepush" ],
    "onDirtyState": "ask",
    "coloredOuput" : true // or false
  }
}

The hook also honor the clix env variable to enable colored output __CLIX_COLORED_OUTPUT__ so if you set this variable in your environment you don't need to configure it in the prepush section.

Example

# install the hook and use the package.json prepush field
./node_modules/prepush/bin/cli.js install

# install the hook using a custom prepush.json file
./node_modules/prepush/bin/cli.js install -c ./path/to/prepush.json

# remove the hook
./node_modules/prepush/bin/cli.js remove

Usage in npm scripts

// in the scripts field
{
  "scripts": {
    "hook-install": "prepush install",
    "hook-remove": "prepush remove",
    "prepush" : "eslinter 'src/**/*.js'" // put here any script you want to run
  },
  "prepush" : {
    "tasks" : ["npm run prepush"]
  }
}

then in the command line you can do:

# install
npm run hook-install

# remove
npm run hook-remove

License

MIT

Changelog

Changelog

changelog

prepush - Changelog

v3.1.11

v3.1.10

  • Build Scripts Changes

v3.1.9

  • Other changes

v3.1.8

  • Bug Fixes

v3.1.7

  • Bug Fixes
    • only change cwd to gitDirectory if a git command is executed - 4cb8c47, royriojas, 16/12/2015 04:45:26

v3.1.6

  • Bug Fixes
    • properly detect the git directory to ensure the git commands will use the right git info - 6b110fe, royriojas, 16/12/2015 04:31:33

v3.1.5

  • Bug Fixes
    • Make it usable in case a GUI is used to control git and add ignoreBranch and applyToBranch options - 1489471, royriojas, 17/10/2015 22:30:16

v3.1.4

  • Build Scripts Changes
    • update clix dep to get nicer log output - 8e07a6c, royriojas, 11/08/2015 19:45:07

v3.1.3

  • Build Scripts Changes

v3.1.2

  • Build Scripts Changes
  • Documentation

v3.1.1

  • Build Scripts Changes
    • Modify install-hooks to add precommit module - 4659d0c, royriojas, 29/07/2015 04:31:30
  • Documentation

v3.1.0

  • Build Scripts Changes
    • make sure tests are executed during the pre-v script - 602e852, royriojas, 29/07/2015 04:26:35
  • Refactoring
    • only try to restore the stash if it was created - 144cd93, royriojas, 29/07/2015 04:15:28

v3.0.4

  • Build Scripts Changes

v3.0.3

  • Bug Fixes
    • Wrong error handling inside promises - ecefe26, royriojas, 25/07/2015 06:36:59

v3.0.2

  • Bug Fixes
    • Wrong error handling inside promises - c17c87e, royriojas, 25/07/2015 06:35:02

v3.0.1

v3.0.0

  • Build Scripts Changes
  • Features
    • Add the option to enable/disable colored output - 926fe55, royriojas, 25/07/2015 05:47:20
  • Documentation
    • Put back info about the custom config.json file - 77da2cd, royriojas, 25/07/2015 05:44:24
  • Refactoring

v2.0.4

hook

  • Fix prepush logic to calculate the dirty state and properly create the stash. Fix #2 - dc7d6d6, gsound, 02/04/2015 22:37:00

    • Dirty state does not consider empty folders anymore
    • Male sure the temporary is properly deleted after stash -

      v2.0.3

    • Documentation
  • Better error message when prepush property not found in config file. Related to #1 - fe20167, [Roy Riojas](https://github.com/Roy Riojas), 20/03/2015 20:21:59

v2.0.2

prepush tasks

  • Bug Fixes

    • Do not fail if the prepush tasks is not present. Fix #1 - e0bc489, [Roy Riojas](https://github.com/Roy Riojas), 20/03/2015 20:15:18

      Now a message explaining the error is presented to the user, letting him know how to fix the issue

v2.0.1

prepush tasks

  • Bug Fixes

    • Do not fail if the prepush tasks is not present - 495f5a8, [Roy Riojas](https://github.com/Roy Riojas), 20/03/2015 20:10:41

      Now a message explaining the error is presented to the user

v2.0.0

hook improvements

v1.0.7

hook

  • Features
    • The hook now will stash your changes previous to execute the prepush tasks - ec943e6, [Roy Riojas](https://github.com/Roy Riojas), 19/03/2015 06:13:53

v1.0.6

v1.0.5

v1.0.4

Promise issue

  • Enhancements
    • Make the prepush to load the json configuration file instead of replacing it inline - 57c556e, [Roy Riojas](https://github.com/Roy Riojas), 10/03/2015 04:38:44