{"id":15478417,"url":"https://github.com/ddmitov/camel-harness","last_synced_at":"2025-04-22T14:47:36.740Z","repository":{"id":57193296,"uuid":"65859283","full_name":"ddmitov/camel-harness","owner":"ddmitov","description":"Node.js - Electron - NW.js controller for Perl 5 scripts :dromedary_camel:","archived":false,"fork":false,"pushed_at":"2021-09-26T16:34:06.000Z","size":150,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-19T03:22:29.795Z","etag":null,"topics":["camel-harness","electron","node-js","nwjs","perl"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/camel-harness","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ddmitov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-16T23:01:15.000Z","updated_at":"2021-09-26T16:31:49.000Z","dependencies_parsed_at":"2022-09-15T22:30:38.612Z","dependency_job_id":null,"html_url":"https://github.com/ddmitov/camel-harness","commit_stats":null,"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddmitov%2Fcamel-harness","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddmitov%2Fcamel-harness/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddmitov%2Fcamel-harness/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddmitov%2Fcamel-harness/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddmitov","download_url":"https://codeload.github.com/ddmitov/camel-harness/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241726766,"owners_count":20009972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["camel-harness","electron","node-js","nwjs","perl"],"created_at":"2024-10-02T04:04:09.462Z","updated_at":"2025-03-03T19:30:46.119Z","avatar_url":"https://github.com/ddmitov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# camel-harness\n\n[![Travis CI Build Status](https://travis-ci.org/ddmitov/camel-harness.svg?branch=master)](https://travis-ci.org/ddmitov/camel-harness)\n[![Snyk Status](https://snyk.io/test/github/ddmitov/camel-harness/badge.svg)](https://snyk.io/test/github/ddmitov/camel-harness)\n[![Maintainability](https://api.codeclimate.com/v1/badges/b9431bac8e7b41daab6f/maintainability)](https://codeclimate.com/github/ddmitov/camel-harness/maintainability)\n\n[Node.js](http://nodejs.org/) - [Electron](http://electron.atom.io/) - [NW.js](http://nwjs.io/) package for asynchronous handling of [Perl](https://www.perl.org/) scripts\n\n## Quick Start\n\n``npm install camel-harness``  \n\n```javascript\nconst camelHarness = require(\"camel-harness\");\n\nlet perlTest = {};\nperlTest.script = \"/test/test.pl\";\n\nperlTest.stdoutFunction = function (stdout) {\n  console.log(stdout);\n};\n\ncamelHarness.startScript(perlTest);\n```\n\n## Core Dependency\n\n``child_process``\n\n## External Dependency\n\nPerl interpreter identified by filename on PATH or full pathname  \n\ncamel-harness npm package test will fail if no ``perl`` binary is available on PATH.  \n\n## API\n\nAll settings of a Perl script executed by camel-harness are stored in a JavaScript object with an arbitrary name and the following object properties:  \n\n* **script**  \n  ``String`` for Perl script full path or Perl code executed as an one-liner  \n  *This object property is mandatory.*  \n\n  ```javascript\n  perlTest.script = \"/full/path/to/test.pl\";\n  ```\n\n  The ``-e`` interpreter switch must be set when Perl code is executed in one-liner mode.  \n  Perl code must not be surrounded in single quotes and all double quotes must be escaped.  \n\n  One-liner example:  \n\n  ```javascript\n  let oneLiner = {};\n\n  oneLiner.interpreterSwitches = [];\n  oneLiner.interpreterSwitches.push(\"-e\");\n\n  oneLiner.script = \"use English; print \\\"Perl $PERL_VERSION\\\";\"\n\n  oneLiner.stdoutFunction = function (stdout) {\n    console.log(`${stdout}`);\n  };\n\n  camelHarness.startScript(oneLiner);\n  ```\n\n* **stdoutFunction**  \n  will be executed every time data is available on STDOUT  \n  The only parameter passed to the ``stdoutFunction`` is the STDOUT ``String``.  \n\n  ```javascript\n  perlTest.stdoutFunction = function (stdout) {\n    document.getElementById(\"DOM-element-id\").textContent = stdout;\n  };\n  ```\n\n* **stderrFunction**  \n  will be executed every time data is available on STDERR  \n  The only parameter passed to the ``stderrFunction`` is the STDERR ``String``.  \n\n  ```javascript\n  perlTest.stderrFunction = function (stderr) {\n    console.log(\"Perl script STDERR:\\n\");\n    console.log(stderr);\n  };\n  ```\n\n* **errorFunction**  \n  will be executed on Perl script error  \n  The only parameter passed to the ``errorFunction`` is the error ``Object``.  \n\n  The ``errorFunction`` can generate a message when Perl interpreter is not found:  \n\n  ```javascript\n  perlTest.errorFunction = function (error) {\n    if (error.code === \"ENOENT\") {\n      console.log(\"Perl interpreter was not found.\");\n    }\n  };\n  ```\n\n* **exitFunction**  \n  will be executed when Perl script has ended  \n  The only parameter passed to the ``exitFunction`` is the exit code ``String``.  \n\n  The ``exitFunction`` can generate a message when Perl script is not found:  \n\n  ```javascript\n  perlTest.exitFunction = function (exitCode) {\n    if (exitCode === 2) {\n      console.log(\"Perl script was not found.\");\n    }\n  };\n  ```\n\n* **perlInterpreter**  \n  ``String`` for a Perl interpreter: either filename on PATH or full pathname  \n  If no ``perlInterpreter`` is defined, ``perl`` binary on PATH is used, if available.  \n\n  ```javascript\n  perlTest.interpreter = \"/full/path/to/perl\";\n  ```\n\n* **interpreterSwitches**  \n  ``Array`` for Perl interpreter switches  \n\n  ```javascript\n  perlTest.interpreterSwitches = [];\n  perlTest.interpreterSwitches.push(\"-W\");\n  ```\n\n* **scriptArguments**  \n  ``Array`` for Perl script arguments  \n\n  ```javascript\n  perlTest.scriptArguments = [];\n  perlTest.scriptArguments.push(\"argument-one\");\n  perlTest.scriptArguments.push(\"argument-two\");\n  ```\n\n* **options**  \n  ``Object`` for Perl script options passed to the ``child_process`` core module.  \n  Click [here](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) for a full list of all available ``child_process`` options.\n\n* **options.cwd**  \n  ``String`` for a new Perl script current working directory  \n\n  ```javascript\n  perlTest.options = {};\n  perlTest.options.cwd = \"/full/path/to/current-working-directory\";;\n  ```\n\n* **options.env**  \n  ``Object`` for a new Perl script environment  \n\n  Script environment with an inherited PATH and a new variable:  \n\n  ```javascript\n  perlTest.options = {};\n  perlTest.options.env = {};\n  perlTest.options.env.PATH = process.env.PATH;\n  perlTest.options.env.TEST = \"test\";\n  ```\n\n* **options.detached**  \n  ``Boolean`` option for starting detached Perl processes like servers  \n\n  ``options.detached`` must be set to ``true`` and  \n  ``options.stdio`` must be set to ``\"ignore\"`` to  \n  start a detached process without receiving anything from it.  \n  A process detached with the above options can run even after its parent has ended.  \n\n  Example settings for a Perl server application:  \n\n  ```javascript\n  let perlServer = {};\n  perlServer.script = \"/path/to/perl-server-application\";\n\n  perlServer.options = {};\n  perlServer.options.detached = true;\n  perlServer.options.stdio = \"ignore\";\n\n  const camelHarness = require(\"camel-harness\");\n  camelHarness.startScript(perlServer);\n\n  perlServer.scriptHandler.unref();\n  ```\n\n* **inputData**  \n  ``String`` or ``Function`` supplying user data as its return value.  \n  ``inputData`` is written on script STDIN.  \n\n  ``inputData`` function with no dependencies:  \n\n  ```javascript\n  perlTest.inputData = function () {\n    let data = document.getElementById(\"input-box-id\").value;\n    return data;\n  }\n  ```\n\n## Interactive Scripts\n\ncamel-harness can also start and communicate with interactive scripts having their own event loops and capable of repeatedly receiving STDIN input. Use the following code to send data to an interactive script waiting for input on STDIN:\n\n```javascript\nlet data = document.getElementById(\"interactive-script-input\").value;\nperlTest.scriptHandler.stdin.write(data);\n```\n\ncamel-harness demo packages for [Electron](https://www.npmjs.com/package/camel-harness-demo-electron) and [NW.js](https://www.npmjs.com/package/camel-harness-demo-nwjs) include a Perl script that can be constantly fed with data from an HTML interface. Perl with the ``AnyEvent`` CPAN module has to be available on PATH.  \n\n## [Electron Demo](https://www.npmjs.com/package/camel-harness-demo-electron)\n\n## [NW.js Demo](https://www.npmjs.com/package/camel-harness-demo-nwjs)\n\n## [Credits](./CREDITS.md)\n\n## [License](./LICENSE.md)\n\nMIT 2016 - 2018  \nDimitar D. Mitov  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddmitov%2Fcamel-harness","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddmitov%2Fcamel-harness","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddmitov%2Fcamel-harness/lists"}