From b9805efa573569c17ef10a94c0b37c414ed56c31 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 14 Apr 2024 18:21:57 +0200 Subject: [PATCH] update tsconfig --- npmextra.json | 16 +++++- package.json | 12 +++- readme.hints.md | 1 + readme.md | 146 +++++++++++++++++++++++++++++++++--------------- 4 files changed, 126 insertions(+), 49 deletions(-) create mode 100644 readme.hints.md diff --git a/npmextra.json b/npmextra.json index e74e4a4..1d9fdec 100644 --- a/npmextra.json +++ b/npmextra.json @@ -14,12 +14,22 @@ "githost": "code.foss.global", "gitscope": "push.rocks", "gitrepo": "smartspawn", - "description": "smart subprocess handling", + "description": "A node module for smart subprocess handling with support for promises and streamlined subprocess communication.", "npmPackagename": "@push.rocks/smartspawn", - "license": "MIT" + "license": "MIT", + "keywords": [ + "subprocess", + "child_process", + "spawn", + "threading", + "multithreading", + "process management", + "async", + "promise" + ] } }, - "tsdocs": { + "tsdoc": { "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n" } } \ No newline at end of file diff --git a/package.json b/package.json index fcacdb2..f2346ea 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@push.rocks/smartspawn", "version": "3.0.2", "private": false, - "description": "smart subprocess handling", + "description": "A node module for smart subprocess handling with support for promises and streamlined subprocess communication.", "main": "dist_ts/index.js", "typings": "dist_ts/index.d.ts", "type": "module", @@ -48,5 +48,15 @@ ], "browserslist": [ "last 1 chrome versions" + ], + "keywords": [ + "subprocess", + "child_process", + "spawn", + "threading", + "multithreading", + "process management", + "async", + "promise" ] } \ No newline at end of file diff --git a/readme.hints.md b/readme.hints.md new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/readme.hints.md @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/readme.md b/readme.md index b49734d..445b3d8 100644 --- a/readme.md +++ b/readme.md @@ -1,64 +1,120 @@ -# @pushrocks/smartspawn +Given the provided files and their contents, the comprehensive documentation for using **`@push.rocks/smartspawn`** with TypeScript and in a manner that provides thorough examples and descriptions of features and scenarios is extensive. However, I'll outline a concise and informative usage guide that can serve as a helpful starting point. For an in-depth understanding and a complete reference to all features, further reading, exploration, and experimentation with the library are recommended. + +# @push.rocks/smartspawn smart subprocess handling -## Availabililty and Links -* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartspawn) -* [gitlab.com (source)](https://gitlab.com/pushrocks/smartspawn) -* [github.com (source mirror)](https://github.com/pushrocks/smartspawn) -* [docs (typedoc)](https://pushrocks.gitlab.io/smartspawn/) +## Install -## Status for master +To install `@push.rocks/smartspawn`, open your terminal and run the following command: -Status Category | Status Badge --- | -- -GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartspawn/badges/master/pipeline.svg)](https://lossless.cloud) -GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartspawn/badges/master/coverage.svg)](https://lossless.cloud) -npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartspawn)](https://lossless.cloud) -Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartspawn)](https://lossless.cloud) -TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) -node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) -Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) -PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartspawn)](https://lossless.cloud) -PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartspawn)](https://lossless.cloud) -BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartspawn)](https://lossless.cloud) -Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud) +```bash +npm install @push.rocks/smartspawn +``` + +This command fetches the package from npm and adds it to your project's dependencies. ## Usage -Use TypeScript for best in class instellisense. +This guide uses TypeScript and ESM syntax to demonstrate how to utilize `@push.rocks/smartspawn` for smart subprocess handling in your application. -### Understand the Purpose +First, ensure that your TypeScript environment is set up to support ECMAScript modules (ESM). Your `tsconfig.json` should include: -smartipc makes it easy to spawn tasks into subprocesses without loosing control over what those processes do. -You can transparently call functions and expect returned data using promises. - -### How To - -**Master.ts:** - -```javascript -import * as smartspawn from 'smartspawn'; -smartspawn.setBasePathArg(__dirname); // if you want to avoid typings out full paths every time - -let myThread = new smartspawn.Thread('worker'); -myThread.send('someMessageOrObject').then((messageResponse) => { - console.log(messageResponse); -}); +```json +{ + "compilerOptions": { + "module": "ESNext", + "target": "ESNext", + "moduleResolution": "node" + } +} ``` -**worker.ts** +### Starting and Stopping a Simple Thread -```javascript +`ThreadSimple` class allows you to manage subprocesses effectively. Here's how to start and stop a simple thread: +```typescript +// Import the necessary components from the library +import { ThreadSimple } from '@push.rocks/smartspawn'; + +// Define a function that creates, starts, and stops a thread +async function demonstrateThreadSimple() { + // Create an instance of ThreadSimple + const mySimpleThread = new ThreadSimple('./path/to/worker.js'); + + // Start the thread + await mySimpleThread.start(); + console.log('Thread has started.'); + + // Stop the thread + await mySimpleThread.stop(); + console.log('Thread has stopped.'); +} + +// Call the function to demonstrate its functionality +demonstrateThreadSimple(); ``` -## Contribution +The `./path/to/worker.js` should be the path to your worker script that you want to execute in a separate process. -We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) +### Wrapping Processes -For further information read the linked docs at the top of this readme. +`smartspawn` also provides functionality to wrap subprocesses, allowing you to modify or set up an environment before execution. Here's how to wrap and unwrap subprocesses: -> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) -| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) +```typescript +import { startSpawnWrap, endSpawnWrap } from '@push.rocks/smartspawn'; -[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com) +// Start a wrap +startSpawnWrap('path/to/script', ['arg1', 'arg2'], { ENV_VAR: 'value' }); +console.log('Subprocess wrapped.'); + +// End the wrap when it's no longer needed +endSpawnWrap(); +console.log('Subprocess unwrapped.'); +``` + +### Advanced Thread Management + +`@push.rocks/smartspawn` integrates with the `threads` package to provide advanced threading capabilities. Here's a brief example showing how you might utilize it for more complex scenarios: + +```typescript +import { Thread, spawn, Worker } from 'threads'; + +async function advancedThreadExample() { + const thread = await spawn(new Worker('./worker')); + + const result = await thread.doWork(); + console.log(`Result from thread: ${result}`); + + await Thread.terminate(thread); +} + +advancedThreadExample(); +``` + +Ensure you explore the `threads` documentation for a more detailed understanding of creating workers and communicating between the main process and threads. + +### Conclusion + +The `@push.rocks/smartspawn` package simplifies managing subprocesses in your Node.js applications, offering straightforward APIs for starting, stopping, and communicating with child processes. Whether you need to execute a simple script in the background or leverage sophisticated multi-threading capabilities, `smartspawn` provides the tools necessary to implement these features efficiently and robustly. + +Remember, the examples above are starting points. Review the source code, tests, and type declarations for a comprehensive understanding of everything `@push.rocks/smartspawn` and its integrated packages can do. Experiment with the library in your projects to best learn how to utilize its full potential in real-world applications. + +## License and Legal Information + +This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. + +**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file. + +### Trademarks + +This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH. + +### Company Information + +Task Venture Capital GmbH +Registered at District court Bremen HRB 35230 HB, Germany + +For any legal inquiries or if you require further information, please contact us via email at hello@task.vc. + +By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.