GithubHelp home page GithubHelp logo

mathieumg / npm-lifecycle-runner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cellule/npm-lifecycle-runner

0.0 2.0 0.0 10 KB

Execute npm lifecycle scripts under better conditions

License: MIT License

JavaScript 100.00%

npm-lifecycle-runner's Introduction

npm-lifecycle-runner

Description

The main purpose of this module is to run install scripts only when developping or in production. It also supports every other lifecycle.

Sometimes, in your project, you run npm install to get your modules. You also want to run some command to get setup for development. However, if you setup an install script

{
  "scripts": {
    "install": "somecommand"
  }
}

This command will get run also whenever anyone installs your module or when you have NODE_ENV=production.

Installation

$ npm install npm-lifecycle-runner

Usage

Create a file in the root of your project to run your installation script, ie: installScript.js.

Then you can require npm-lifecycle-runner and call it with the path to the root of your project, ie: __dirname and a list of commands you want to run.

For instance

var lifecycleRunner = require("npm-lifecycle-runner");

lifecycleRunner(__dirname, [
  {
    type: "devInstall",
    cmd: "echo You are now setup to develop"
  },
  {
    type: "prodInstall",
    cmd: "echo check https://github.com/Cellule/npm-lifecycle-runner for details"
  },
]);

Then add in your package.json

{
  "scripts": {
    "install": "node installScript.js"
  }
}

Api

  • require("npm-lifecycle-runner"): function(projectRoot, cmdsList)
    • projectRoot: String, path to the root of your project
    • cmdsList: Command | Command[], list of commands to execute
  • Command: String | { type?: String, cmd: String, onSuccess?: String | function(stdout, stderror) => void onError?: function(err, stdout, stderror) => void }, The command to run. If the command is a string it reprensents the command to run.
    • PossibleTypes: Optional. Default: "devInstall"
      • "devInstall": Runs the script when installing modules while developping, devDependencies will be available.
      • "prodInstall": Runs the script when installing for production or when another module install your module, devDependencies will be unavailable
      • "install": Runs the script on install regardless of development or production. Acts exactly like putting your command in the package.json
      • Every other npm lifecycle commands
    • onSuccess: Optional. If it's a string, it will output it if the command succeed. If it's a function, it will be called back with the output of the command.
    • onError: Optional. Callback with the error message and the output of the command. If this is missing, it will simply output the stderror in the console.
  • getLifecycle: function(projectRoot) => lifecycle. Exposed method to get the current lifecycle. Use require("npm-lifecycle-runner").getLifecycle(process.cwd())

npm-lifecycle-runner's People

Contributors

cellule avatar

Watchers

James Cloos avatar Mathieu M-Gosselin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.