spawno 2.1.2 → 3.0.0
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.
- package/LICENSE +1 -1
- package/README.md +37 -25
- package/lib/index.js +26 -24
- package/package.json +4 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2016-
|
|
3
|
+
Copyright (c) 2016-26 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -74,7 +74,11 @@ yarn add spawno
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
```js
|
|
77
|
-
|
|
77
|
+
import path from "node:path";
|
|
78
|
+
import { fileURLToPath } from "node:url";
|
|
79
|
+
import spawn from "spawno";
|
|
80
|
+
|
|
81
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
78
82
|
|
|
79
83
|
spawn("ls", ["-l"], { cwd: __dirname }, (err, stdout, stderr) => {
|
|
80
84
|
console.log(err || stderr || stdout);
|
|
@@ -84,10 +88,11 @@ spawn("ls", ["-l"], { cwd: __dirname }, (err, stdout, stderr) => {
|
|
|
84
88
|
});
|
|
85
89
|
|
|
86
90
|
// Pipe the output in the stdout/stderr streams (this will not collect the output in memory)
|
|
87
|
-
|
|
88
|
-
cwd: __dirname
|
|
89
|
-
|
|
91
|
+
spawn("ping", ["ionicabizau.net"], {
|
|
92
|
+
cwd: __dirname,
|
|
93
|
+
output: true
|
|
90
94
|
});
|
|
95
|
+
|
|
91
96
|
// =>
|
|
92
97
|
// PING ionicabizau.net (109.107.37.233) 56(84) bytes of data.
|
|
93
98
|
// 64 bytes from cip-109-107-37-233.gb1.brightbox.com (109.107.37.233): icmp_seq=1 ttl=54 time=49.2 ms
|
|
@@ -96,7 +101,7 @@ let proc = spawn("ping", ["ionicabizau.net"], {
|
|
|
96
101
|
// 64 bytes from cip-109-107-37-233.gb1.brightbox.com (109.107.37.233): icmp_seq=4 ttl=54 time=46.3 ms
|
|
97
102
|
|
|
98
103
|
// Promise interface
|
|
99
|
-
spawn.promise("curl", ["ionicabizau.net"]).then(console.log)
|
|
104
|
+
spawn.promise("curl", ["ionicabizau.net"]).then(console.log);
|
|
100
105
|
```
|
|
101
106
|
|
|
102
107
|
|
|
@@ -109,23 +114,6 @@ spawn.promise("curl", ["ionicabizau.net"]).then(console.log)
|
|
|
109
114
|
|
|
110
115
|
|
|
111
116
|
|
|
112
|
-
|
|
113
|
-
## :question: Get Help
|
|
114
|
-
|
|
115
|
-
There are few ways to get help:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
|
|
120
|
-
2. For bug reports and feature requests, open issues. :bug:
|
|
121
|
-
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
117
|
## :memo: Documentation
|
|
130
118
|
|
|
131
119
|
|
|
@@ -134,9 +122,9 @@ Creates the child process.
|
|
|
134
122
|
|
|
135
123
|
#### Params
|
|
136
124
|
|
|
137
|
-
- **
|
|
125
|
+
- **string** `command`: The command you want to run.
|
|
138
126
|
- **Array** `args`: The command arguments.
|
|
139
|
-
- **
|
|
127
|
+
- **object** `options`: The options to pass to the `spawn` function extended with:
|
|
140
128
|
- `output` (Boolean): If truly, the output will be piped in the
|
|
141
129
|
process stdout/stderr streams.
|
|
142
130
|
- `data` (String|Boolean): If `false`, the `stdin` stream will not be ended. By default this is an empty string.
|
|
@@ -145,9 +133,15 @@ Creates the child process.
|
|
|
145
133
|
#### Return
|
|
146
134
|
- **Process** The child process that was created.
|
|
147
135
|
|
|
148
|
-
### `spawno.promise()`
|
|
136
|
+
### `spawno.promise(command, args, options)`
|
|
149
137
|
The promise interface.
|
|
150
138
|
|
|
139
|
+
#### Params
|
|
140
|
+
|
|
141
|
+
- **string** `command`: The command you want to run.
|
|
142
|
+
- **Array** `args`: The command arguments.
|
|
143
|
+
- **object** `options`: The options to pass to the `spawn` function.
|
|
144
|
+
|
|
151
145
|
#### Return
|
|
152
146
|
- **Promise** The promise which will be eventually resolved with the following object:
|
|
153
147
|
- `code`
|
|
@@ -162,6 +156,24 @@ The promise interface.
|
|
|
162
156
|
|
|
163
157
|
|
|
164
158
|
|
|
159
|
+
## :question: Get Help
|
|
160
|
+
|
|
161
|
+
There are few ways to get help:
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
|
|
166
|
+
2. For bug reports and feature requests, open issues. :bug:
|
|
167
|
+
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
165
177
|
|
|
166
178
|
|
|
167
179
|
|
package/lib/index.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var spawn = require("child_process").spawn,
|
|
4
|
-
procOutput = require("proc-output");
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import procOutput from "proc-output";
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* spawno
|
|
8
6
|
* Creates the child process.
|
|
9
|
-
*
|
|
10
7
|
* @name spawno
|
|
11
8
|
* @function
|
|
12
|
-
* @param {
|
|
9
|
+
* @param {string} command The command you want to run.
|
|
13
10
|
* @param {Array} args The command arguments.
|
|
14
|
-
* @param {
|
|
11
|
+
* @param {object} options The options to pass to the `spawn` function extended with:
|
|
15
12
|
*
|
|
16
13
|
* - `output` (Boolean): If truly, the output will be piped in the
|
|
17
14
|
* process stdout/stderr streams.
|
|
18
15
|
* - `data` (String|Boolean): If `false`, the `stdin` stream will not be ended. By default this is an empty string.
|
|
19
|
-
*
|
|
20
16
|
* @param {Function} cb The callback function.
|
|
21
17
|
* @returns {Process} The child process that was created.
|
|
22
18
|
*/
|
|
23
|
-
|
|
19
|
+
function spawno(command, args, options, cb) {
|
|
24
20
|
|
|
25
21
|
if (typeof args === "function") {
|
|
26
22
|
cb = args;
|
|
@@ -44,13 +40,14 @@ module.exports = function spawno(command, args, options, cb) {
|
|
|
44
40
|
options.input = options.input || "";
|
|
45
41
|
}
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
let showOutput = options.output;
|
|
44
|
+
let inputData = options.input
|
|
45
|
+
;
|
|
49
46
|
|
|
50
47
|
delete options.output;
|
|
51
48
|
delete options.input;
|
|
52
49
|
|
|
53
|
-
|
|
50
|
+
let proc = spawn(command, args, options);
|
|
54
51
|
|
|
55
52
|
if (showOutput) {
|
|
56
53
|
proc.stdout.pipe(process.stdout);
|
|
@@ -66,31 +63,36 @@ module.exports = function spawno(command, args, options, cb) {
|
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
return proc;
|
|
69
|
-
}
|
|
66
|
+
}
|
|
70
67
|
|
|
71
68
|
/**
|
|
72
69
|
* spawno.promise
|
|
73
70
|
* The promise interface.
|
|
74
|
-
*
|
|
75
71
|
* @name spawno.promise
|
|
76
72
|
* @function
|
|
73
|
+
* @param {string} command The command you want to run.
|
|
74
|
+
* @param {Array} args The command arguments.
|
|
75
|
+
* @param {object} options The options to pass to the `spawn` function.
|
|
77
76
|
* @returns {Promise} The promise which will be eventually resolved with the following object:
|
|
78
77
|
*
|
|
79
78
|
* - `code`
|
|
80
79
|
* - `stdout`
|
|
81
80
|
* - `stderr`
|
|
82
81
|
*/
|
|
83
|
-
|
|
84
|
-
return new Promise(
|
|
85
|
-
|
|
86
|
-
if (err) {
|
|
87
|
-
return reject(err);
|
|
88
|
-
}
|
|
82
|
+
const promise = (command, args, options) => {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
spawno(command, args, options, (err, stdout, stderr, code) => {
|
|
85
|
+
if (err) { return reject(err); }
|
|
89
86
|
resolve({
|
|
90
|
-
code
|
|
91
|
-
stdout
|
|
92
|
-
stderr
|
|
87
|
+
code,
|
|
88
|
+
stdout,
|
|
89
|
+
stderr
|
|
93
90
|
});
|
|
94
91
|
});
|
|
95
92
|
});
|
|
96
|
-
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
spawno.promise = promise;
|
|
96
|
+
|
|
97
|
+
export { promise };
|
|
98
|
+
export default spawno;
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spawno",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Easily work with child processes.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "lib/index.js",
|
|
7
|
+
"exports": "./lib/index.js",
|
|
6
8
|
"directories": {
|
|
7
9
|
"example": "example"
|
|
8
10
|
},
|
|
9
11
|
"dependencies": {
|
|
10
|
-
"proc-output": "^
|
|
12
|
+
"proc-output": "^2.0.0"
|
|
11
13
|
},
|
|
12
|
-
"devDependencies": {},
|
|
13
14
|
"scripts": {
|
|
14
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
16
|
},
|