js-transformer / js-transformer
Call any js-transformer package through PHP
Fund package maintenance!
kylekatarnls
Open Collective
Tidelift
Installs: 203 961
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 0
Requires
Requires (Dev)
- codeclimate/php-test-reporter: >=0.3
- phpunit/phpunit: >=4.8 <6.0
This package is auto-updated.
Last update: 2024-08-17 17:02:56 UTC
README
PHP wrapper to call any js-transformer package
Installation
First, install js-transformer
with composer:
composer require js-transformer/js-transformer
Then add the following the jstransformer packages in the
extra.npm
section of your composer.json
file (if
you had not yet, the previous command should have created it
at current directory opened in your terminal).
So for example if you want to use stylus and less transformers, add the following:
"extra": { "npm": { "jstransformer-stylus": "^1.4.0", "jstransformer-less": "^2.6.0" } }
As you can see, you can use any semantic versioning as in npm or composer dependencies to specify which package version to use.
Then use:
composer install
to install npm packages via composer.
Usage
Call a transformer
$transformer = new JsTransformer(); $lessCode = ' a { .foo { color: red; } } '; echo $transformer->call('jstransformer-less', array($lessCode));
will display:
a .foo { color: red; }
And you can pass options, locals or as many arguments as the js-transformer can take:
$transformer = new JsTransformer(); $lessCode = ' a { .foo { color: red; } } '; $options = array( 'compress' => true, ); echo $transformer->call('jstransformer-less', array($lessCode, $options));
will display:
a .foo{color: red}
Check if a transformer is installed
$transformer = new JsTransformer(); if ($transformer->isInstalled('jstransformer-less')) { echo 'Less transformer is installed.'; } else { echo 'You need to install less transformer to use this package.'; }
Get node engine
This package use nodejs-php-fallback to install and execute node packages.
If you need it, you can get the nodejs-php-fallback instance:
if (!$transformer->getNodeEngine()->isNodeInstalled()) { echo 'nodejs should be installed for js-transformer to work.'; }