2017 © Pedro Peláez
 

composer-plugin nodejs-php-fallback

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

image

nodejs-php-fallback/nodejs-php-fallback

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 24 Versions
  • 21 % Grown

The README.md

NodejsPhpFallback

Latest Stable Version Build Status StyleCI Test Coverage Code Climate, (*1)

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available., (*2)

Usage

Edit composer.json to add nodejs-php-fallback to "require", your "npm" dependancies to "extra" and "NodejsPhpFallback\\NodejsPhpFallback::install"to both "post-install-cmd" and "post-update-cmd" in "scripts", (*3)

For example, to use node.js stylus and fallback to the php kylekatarnls/stylus port, use:, (*4)

...
"require": {
    "nodejs-php-fallback/nodejs-php-fallback": "*",
    "kylekatarnls/stylus": "*"
},
"extra": {
    "npm": {
        "stylus": "^0.54"
    }
},
"scripts": {
    "post-install-cmd": [
        "NodejsPhpFallback\\NodejsPhpFallback::install"
    ],
    "post-update-cmd": [
        "NodejsPhpFallback\\NodejsPhpFallback::install"
    ]
},
...

With this configuration, both node stylus and php kylekatarnls/stylus packages will be installed and updated when you update or install with composer if node is installed, else, only the php package will be., (*5)

So you can easily create a function that will try first to call the node package, then else the php one:, (*6)

use NodejsPhpFallback\NodejsPhpFallback;
use Stylus\Stylus;

function getCssFromStylusFile($stylusFile)
{
    $node = new NodejsPhpFallback();
    $fallback = function () use ($stylusFile) {
        $stylus = new Stylus();

        return $stylus->fromFile($stylusFile)->toString();
    };

    return $node->execModuleScript('stylus', 'bin/stylus', '--print ' . escapeshellarg($stylusFile), $fallback);
}

$css = getCssFromStylusFile('path/to/my-stylus-file.styl');

Here $css will contain CSS code rendered from your stylus file, no matter node is installed or not. So you can install node on your production environment to benefit of the last official version of a npm package but any one can test or develop your project with no need to install node., (*7)

Note: the PHP fallback can be a simple php function, not necessarily a call to a class or a composer package., (*8)

Settings

The extra.npm can be an object with npm required packages as key and versions for each of them as value (see https://docs.npmjs.com/misc/semver for version definition). You can also set it as an array of package names, it's the same as specify all packages dependancies with "*" version. Else if you need only one package and don't care about the version, just pass it as a string:, (*9)

Array configuration:, (*10)

"extra": {
    "npm": [
        "hamljs",
        "kraken-js"
    ]
},

String configuration:, (*11)

"extra": {
    "npm": "express"
},

Ask the user to confirm package install

You can use the npm-confirm setting to ask the user if he want to install one or more npm package. This should be used to make the user aware npm packages will be installed, and what for they are. This is also a way to not install optional packages if they are used in a user specific case., (*12)

"extra": {
    "npm": [
        "stylus",
        "less",
        "clean-css",
    ],
    "npm-confirm": {
        "stylus": "This package is needed if you have stylus files.",
        "less": "This package is needed if you have less files."
    }
},

With the configuration above, when the user will execute compoers update or composer install, he will be asked the following:, (*13)

The node package [stylus] can be installed:
This package is needed if you have stylus files.
Would you like to install/update it? (if you're not sure, you can safely press Y to get the package ready to use if you need it later) [Y/N] 

The node package [less] can be installed:
This package is needed if you have less files.
Would you like to install/update it? (if you're not sure, you can safely press Y to get the package ready to use if you need it later) [Y/N] 

Each of stylus and less packages will be installed only if the user enter Y on confirm or if he ran the command with the mode --no-interaction., (*14)

The clean-css package will be installed with no confirm., (*15)

The Versions

05/04 2018

dev-master

9999999-dev

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

05/04 2018

1.4.1

1.4.1.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

05/04 2018

1.4.0

1.4.0.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

03/11 2017

1.3.1

1.3.1.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

30/10 2017

1.3.0

1.3.0.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

30/10 2017

dev-ask-for-install

dev-ask-for-install

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

27/10 2017

1.2.12

1.2.12.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

25/07 2017

1.2.11

1.2.11.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

04/07 2017

1.2.10

1.2.10.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

25/06 2017

1.2.9

1.2.9.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

12/05 2017

1.2.8

1.2.8.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

11/05 2017

1.2.7

1.2.7.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

11/05 2017

1.2.6

1.2.6.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

01/08 2016

1.2.5

1.2.5.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

30/07 2016

1.2.4

1.2.4.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

25/07 2016

1.2.3

1.2.3.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

25/07 2016

1.2.2

1.2.2.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

25/07 2016

1.2.1

1.2.1.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

24/07 2016

1.2.0

1.2.0.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0
  • composer-plugin-api ^1.0

 

The Development Requires

by Kyle

23/07 2016

1.1.1

1.1.1.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0

 

The Development Requires

by Kyle

23/07 2016

1.1.0

1.1.0.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0

 

The Development Requires

by Kyle

22/07 2016

1.0.2

1.0.2.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Requires

  • php >=5.3.0

 

The Development Requires

by Kyle

22/07 2016

1.0.1

1.0.1.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Development Requires

by Kyle

22/07 2016

1.0.0

1.0.0.0

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

  Sources   Download

The Development Requires

by Kyle