Every javascript project worthy of mention, contains a file for managing dependencies, allowing it to be quickly integrated inside other applications via NPM, Node Package Manager, the dependency manager of node.js.

{
    "name": "ng-analytics",
    "devDependencies": {
        "karma": "0.12.*",
        "karma-cli": "*",
        "karma-phantomjs-launcher": "*",
        "karma-jasmine": "0.1.*",
        "phantomjs": "*",
        "bower": "*"
    }
}

This is only a basic example of what you are going to get: a set of meta-tags, needed to recognize the package; a set of dependencies, needed to the library operation; and a set of dependencies, dedicated to the application development, e.g. all information related to testing purposes is a dependency usually needed only while designing an application, to check the library functionality.

If you perform a good configuration of dependencies in your applications, you will be able to simplify their start-up, when using the related commands

$. npm install

You can extend the previous scenario, by adding your own commands, e.g. a useful shortcut to run testing operations or the development server.

{
    "name": "ng-analytics",
    "devDependencies": {
        "karma": "0.12.*",
        "karma-cli": "*",
        "karma-phantomjs-launcher": "*",
        "karma-jasmine": "0.1.*",
        "phantomjs": "*",
        "bower": "*"
    },
    "scripts": {
        "postinstall" : "./node_modules/.bin/bower install",
        "test": "./node_modules/.bin/karma start --single-run"
    }
}

Below you can find a list of most used hooks:

  • preinstall: Run BEFORE the package is installed
  • install, postinstall: Run AFTER the package is installed.
  • preuninstall, uninstall: Run BEFORE the package is uninstalled.
  • postuninstall: Run AFTER the package is uninstalled.
  • preupdate: Run BEFORE the package is updated with the update command.
  • update, postupdate: Run AFTER the package is updated with the update command.
  • pretest, test, posttest: Run by the npm test command.
  • prestop, stop, poststop: Run by the npm stop command.
  • prestart, start, poststart: Run by the npm start command.

Comments

comments powered by Disqus

cloudparty

Follow Us