decodelabs/overpass

简单的 node.js 桥接器

v0.2.7 2024-08-22 00:19 UTC

This package is auto-updated.

Last update: 2024-09-04 21:27:10 UTC


README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

简单的 PHP node.js 桥接器

Overpass 提供了一个简单的接口,用于安装依赖项和与原生 node.js 脚本交互。

DecodeLabs 博客 上获取新闻和更新。

安装

composer require decodelabs/overpass

用法

加载一个上下文开始工作

use DecodeLabs\Overpass\Context;

$context = new Context('path/to/project/');

或者使用 Overpass Veneer 前端从 cwd() 开始工作。Overpass 将在文件树中向上搜索最近的 package.json 文件。

use DecodeLabs\Overpass;

echo Overpass::$runDir; // Working directory
echo Overpass::$rootDir; // Parent or current dir containing package.json
echo Overpass::$packageFile; // Location  of package.json

Overpass::run('myfile.js'); // node myfile.js
Overpass::runScript('my-script'); // npm run my-script

Overpass::install('package1', 'package2'); // npm install package1 package2
Overpass::installDev('package1', 'package2'); // npm install package1 package2 --save-dev

桥接

Overpass 提供了一个简单的桥接系统,允许您定义自定义的 JavaScript,传递参数给它,并通过 node 消费结果。

// myfile.js
module.exports = function(input) {
    return 'hello ' + input;
}
use DecodeLabs\Overpass;

$result = Overpass::bridge('myfile.js', 'world'); // 'hello world'

许可

Overpass 使用 MIT 许可证。有关完整的许可证文本,请参阅 LICENSE