FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
hlambda-core/src/utils/execScriptCommand.js at master · hlambda/hlambda-core · GitHub
hlambda
hlambda-core
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
hlambda-core
/
src
/
utils
/
execScriptCommand.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (57 loc) · 1.94 KB
Breadcrumbs
hlambda-core
/
src
/
utils
/
execScriptCommand.js
Copy path
File metadata and controls
70 lines (57 loc) · 1.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import
path
from
'path'
;
// import { exec, execSync } from 'child_process';
// import shellExec from 'shell-exec'; // Current version does not support custom cwd
import
*
as
childProcess
from
'child_process'
;
export
const
shellExec
=
(
cmdInput
,
opts
)
=>
{
const
executable
=
Array
.
isArray
(
cmdInput
)
?
cmdInput
.
join
(
';'
)
:
cmdInput
;
const
cwd
=
opts
?.
cwd
??
process
.
cwd
(
)
;
const
options
=
{
...
opts
,
stdio
:
'pipe'
,
cwd
,
}
;
const
{
platform
}
=
process
;
try
{
const
cmd
=
platform
===
'win32'
?
'cmd'
:
'sh'
;
const
arg
=
platform
===
'win32'
?
'/C'
:
'-c'
;
const
child
=
childProcess
.
spawn
(
cmd
,
[
arg
,
executable
]
,
options
)
;
return
new
Promise
(
(
resolve
)
=>
{
const
stdoutList
=
[
]
;
const
stderrList
=
[
]
;
if
(
child
.
stdout
)
{
child
.
stdout
.
on
(
'data'
,
(
data
)
=>
{
if
(
Buffer
.
isBuffer
(
data
)
)
return
stdoutList
.
push
(
data
.
toString
(
)
)
;
return
stdoutList
.
push
(
data
)
;
}
)
;
}
if
(
child
.
stderr
)
{
child
.
stderr
.
on
(
'data'
,
(
data
)
=>
{
if
(
Buffer
.
isBuffer
(
data
)
)
return
stderrList
.
push
(
data
.
toString
(
)
)
;
return
stderrList
.
push
(
JSON
.
stringify
(
data
)
)
;
}
)
;
}
const
getDefaultResult
=
(
)
=>
{
const
stderr
=
stderrList
.
join
(
'\n'
)
;
const
stdout
=
stdoutList
.
join
(
'\n'
)
;
return
{
stdout
,
stderr
,
cmd
:
executable
,
cwd
}
;
}
;
child
.
on
(
'error'
,
(
error
)
=>
resolve
(
{
...
getDefaultResult
(
)
,
error
}
)
)
;
child
.
on
(
'close'
,
(
code
)
=>
resolve
(
{
...
getDefaultResult
(
)
,
code
}
)
)
;
}
)
;
}
catch
(
error
)
{
return
Promise
.
reject
(
error
)
;
}
}
;
export
const
execScriptCommand
=
async
(
command
)
=>
{
const
cwd
=
path
.
resolve
(
'./metadata/'
)
;
// console.log(shellExec.default);
const
data
=
await
shellExec
(
command
,
{
cwd
}
)
.
then
(
(
dataObj
)
=>
{
return
dataObj
;
}
)
.
catch
(
(
error
)
=>
{
console
.
log
(
'[execScriptCommand]'
,
error
)
;
}
)
;
return
data
;
}
;
export
default
execScriptCommand
;
Back
|
FazBrowse Home
|
New Git URL