thecodingmachine / nodejs-installer

An installer package that let's you install NodeJS and NPM as a Composer dependency.
107 stars 30 forks source link

Latest Stable Version Latest Unstable Version License Scrutinizer Code Quality

NodeJS installer for Composer

This is an installer that will download NodeJS and NPM and install them in your Composer dependencies. Installation is skipped if NodeJS is already available on your machine.

Why?

NodeJS is increasingly becoming a part of the tool-chain of modern web developers. Tools like Bower, Grunt, Gulp... are used everyday to build applications. For the PHP developer, this means PHP projects have build dependencies on NodeJS or Bower / NPM packages. The NodeJS-installer attempts to bridge the gap between NodeJS and PHP by making NodeJS easily installable as a Composer dependency.

Building on this package, other packages like koala-framework/composer-extra-assets can be used to automatically fetch Bower / NPM packages, run Gulp / Grunt tasks, etc...

How does it work?

Simply include this package in your composer.json requirements:

{
    "require": {
        "mouf/nodejs-installer": "~1.0"
    }
}

By default, if NodeJS is not available on your computer, it will be downloaded and installed in vendor/nodejs/nodejs.

You should access NodeJS and NPM using the scripts created into the vendor/bin directory:

Options

A number of options are available to customize NodeJS installation:

{
    "require": {
        "mouf/nodejs-installer": "~1.0"
    },
    "extra": {
        "mouf": {
            "nodejs": {
                "version": "~0.12",
                "targetDir": "vendor/nodejs/nodejs",
                "forceLocal": false
            }
        }
    }
}

Available options:

Custom script

The installer listens to the following composer scripts to be launched:

{
    "post-install-cmd": {
        // ...
    },
    "post-update-cmd": {
        // ...
    }
}

If you need to launch the installer manually, you can run the following command:

$ composer run-script download-nodejs