@netlify/run-utils 4.0.2-rc → 4.0.2
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/lib/main.js +46 -0
- package/package.json +2 -1
package/lib/main.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import process from 'process'
|
|
2
|
+
|
|
3
|
+
import { execa, execaCommand } from 'execa'
|
|
4
|
+
|
|
5
|
+
// Run a command, with arguments being an array
|
|
6
|
+
export const run = function (file, args, options) {
|
|
7
|
+
const [argsA, optionsA] = parseArgs(args, options)
|
|
8
|
+
const optionsB = { ...DEFAULT_OPTIONS, ...optionsA }
|
|
9
|
+
const childProcess = execa(file, argsA, optionsB)
|
|
10
|
+
redirectOutput(childProcess, optionsB)
|
|
11
|
+
return childProcess
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Run a command, with file + arguments being a single string
|
|
15
|
+
export const runCommand = function (command, options) {
|
|
16
|
+
const optionsA = { ...DEFAULT_OPTIONS, ...options }
|
|
17
|
+
const childProcess = execaCommand(command, optionsA)
|
|
18
|
+
redirectOutput(childProcess, optionsA)
|
|
19
|
+
return childProcess
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Both `args` and `options` are optional
|
|
23
|
+
const parseArgs = function (args, options) {
|
|
24
|
+
if (Array.isArray(args)) {
|
|
25
|
+
return [args, options]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof args === 'object') {
|
|
29
|
+
return [[], args]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return []
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Allow running local binaries by default
|
|
36
|
+
const DEFAULT_OPTIONS = { preferLocal: true }
|
|
37
|
+
|
|
38
|
+
// Redirect output by default, unless specified otherwise
|
|
39
|
+
const redirectOutput = function (childProcess, { stdio, stdout, stderr }) {
|
|
40
|
+
if (stdio !== undefined || stdout !== undefined || stderr !== undefined) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
childProcess.stdout.pipe(process.stdout)
|
|
45
|
+
childProcess.stderr.pipe(process.stderr)
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/run-utils",
|
|
3
|
-
"version": "4.0.2
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Utility for running commands inside Netlify Build",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/main.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"author": "Netlify Inc.",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"prepublishOnly": "cd ../../ && npm run prepublishOnly",
|
|
14
|
+
"prebuild": "rm -rf lib",
|
|
14
15
|
"build": "cp -a src lib/"
|
|
15
16
|
},
|
|
16
17
|
"keywords": [
|