spawno 2.1.1 → 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 +38 -43
- package/lib/index.js +26 -24
- package/package.json +7 -4
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
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
# spawno
|
|
21
21
|
|
|
22
|
-
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://www.npmjs.com/package/spawno) [](https://www.npmjs.com/package/spawno) [](https://www.codementor.io
|
|
22
|
+
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://www.npmjs.com/package/spawno) [](https://www.npmjs.com/package/spawno) [](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
|
|
23
23
|
|
|
24
24
|
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
|
|
25
25
|
|
|
@@ -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,20 +114,6 @@ spawn.promise("curl", ["ionicabizau.net"]).then(console.log)
|
|
|
109
114
|
|
|
110
115
|
|
|
111
116
|
|
|
112
|
-
## :question: Get Help
|
|
113
|
-
|
|
114
|
-
There are few ways to get help:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
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.
|
|
119
|
-
2. For bug reports and feature requests, open issues. :bug:
|
|
120
|
-
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
117
|
## :memo: Documentation
|
|
127
118
|
|
|
128
119
|
|
|
@@ -131,9 +122,9 @@ Creates the child process.
|
|
|
131
122
|
|
|
132
123
|
#### Params
|
|
133
124
|
|
|
134
|
-
- **
|
|
125
|
+
- **string** `command`: The command you want to run.
|
|
135
126
|
- **Array** `args`: The command arguments.
|
|
136
|
-
- **
|
|
127
|
+
- **object** `options`: The options to pass to the `spawn` function extended with:
|
|
137
128
|
- `output` (Boolean): If truly, the output will be piped in the
|
|
138
129
|
process stdout/stderr streams.
|
|
139
130
|
- `data` (String|Boolean): If `false`, the `stdin` stream will not be ended. By default this is an empty string.
|
|
@@ -142,9 +133,15 @@ Creates the child process.
|
|
|
142
133
|
#### Return
|
|
143
134
|
- **Process** The child process that was created.
|
|
144
135
|
|
|
145
|
-
### `spawno.promise()`
|
|
136
|
+
### `spawno.promise(command, args, options)`
|
|
146
137
|
The promise interface.
|
|
147
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
|
+
|
|
148
145
|
#### Return
|
|
149
146
|
- **Promise** The promise which will be eventually resolved with the following object:
|
|
150
147
|
- `code`
|
|
@@ -159,6 +156,24 @@ The promise interface.
|
|
|
159
156
|
|
|
160
157
|
|
|
161
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
|
+
|
|
162
177
|
|
|
163
178
|
|
|
164
179
|
|
|
@@ -201,26 +216,6 @@ Thanks! :heart:
|
|
|
201
216
|
|
|
202
217
|
|
|
203
218
|
|
|
204
|
-
## :dizzy: Where is this library used?
|
|
205
|
-
If you are using this library in one of your projects, add it in this list. :sparkles:
|
|
206
|
-
|
|
207
|
-
- `powershell`
|
|
208
|
-
- `diable`
|
|
209
|
-
- `spawn-npm`
|
|
210
|
-
- `electroner`
|
|
211
|
-
- `git-cloner`
|
|
212
|
-
- `git-status`
|
|
213
|
-
- `@zkochan/diable`
|
|
214
|
-
- `babel-it`
|
|
215
|
-
- `initial-commit-date`
|
|
216
|
-
- `fortran`
|
|
217
|
-
- `striking-clock`
|
|
218
|
-
- `git-change-author`
|
|
219
|
-
- `pull-from-source`
|
|
220
|
-
- `ship-release`
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
219
|
|
|
225
220
|
|
|
226
221
|
|
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
|
},
|
|
@@ -39,9 +40,11 @@
|
|
|
39
40
|
"menu/",
|
|
40
41
|
"cli.js",
|
|
41
42
|
"index.js",
|
|
43
|
+
"index.d.ts",
|
|
44
|
+
"package-lock.json",
|
|
42
45
|
"bloggify.js",
|
|
43
46
|
"bloggify.json",
|
|
44
47
|
"bloggify/"
|
|
45
48
|
],
|
|
46
49
|
"blah": {}
|
|
47
|
-
}
|
|
50
|
+
}
|