@lowdefy/node-utils 4.0.0-alpha.23 → 4.0.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,29 +13,33 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { spawn } from 'child_process';
16
- async function spawnProcess({ logger , command , args , processOptions , silent }) {
17
- return new Promise((resolve, reject)=>{
18
- const process = spawn(command, args, processOptions);
19
- process.stdout.on('data', (data)=>{
20
- if (!silent) {
21
- data.toString('utf8').split('\n').forEach((line)=>{
22
- if (line) {
23
- logger.log(line);
24
- }
25
- });
26
- }
27
- });
28
- process.stderr.on('data', (data)=>{
29
- if (!silent) {
30
- data.toString('utf8').split('\n').forEach((line)=>{
31
- if (line) {
32
- logger.warn(line);
33
- }
34
- });
16
+ function createStdIOHandler({ lineHandler }) {
17
+ function handler(data) {
18
+ data.toString('utf8').split('\n').forEach((line)=>{
19
+ if (line) {
20
+ lineHandler(line);
35
21
  }
36
22
  });
23
+ }
24
+ return handler;
25
+ }
26
+ function spawnProcess({ args , command , processOptions , returnProcess , stdErrLineHandler , stdOutLineHandler =()=>{} , }) {
27
+ if (!stdErrLineHandler) {
28
+ stdErrLineHandler = stdOutLineHandler;
29
+ }
30
+ const process = spawn(command, args, processOptions);
31
+ process.stdout.on('data', createStdIOHandler({
32
+ lineHandler: stdOutLineHandler
33
+ }));
34
+ process.stderr.on('data', createStdIOHandler({
35
+ lineHandler: stdErrLineHandler
36
+ }));
37
+ if (returnProcess) {
38
+ return process;
39
+ }
40
+ return new Promise((resolve, reject)=>{
37
41
  process.on('error', (error)=>{
38
- reject(error);
42
+ stdErrLineHandler(error);
39
43
  });
40
44
  process.on('exit', (code)=>{
41
45
  if (code !== 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/node-utils",
3
- "version": "4.0.0-alpha.23",
3
+ "version": "4.0.0-alpha.26",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -41,7 +41,7 @@
41
41
  "test": "jest --coverage"
42
42
  },
43
43
  "dependencies": {
44
- "@lowdefy/helpers": "4.0.0-alpha.23",
44
+ "@lowdefy/helpers": "4.0.0-alpha.26",
45
45
  "fs-extra": "10.1.0"
46
46
  },
47
47
  "devDependencies": {
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "1bb110fb4432267efb199df926bae6bb735209ca"
56
+ "gitHead": "ef60e34f87b95204d103db4a65e4ba3c54a5a1b5"
57
57
  }