Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pôle IS
Outillage
prezbuilder
Commits
2554c7ec
Commit
2554c7ec
authored
May 05, 2020
by
Guillaume Perréal
Browse files
Améliore la gestion et l'affichage des appels aux programmes externes.
parent
e17ad22e
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/drawio.js
View file @
2554c7ec
import
{
callbackify
,
promisify
}
from
"
util
"
;
import
child_process
from
"
child_process
"
;
import
{
callbackify
}
from
"
util
"
;
import
exec
from
"
./exec
"
;
import
fs
from
"
fs
"
;
import
logger
from
"
gulplog
"
;
import
{
mkTempFile
}
from
"
./tempdir
"
;
...
...
@@ -9,8 +9,6 @@ import { withBinary } from "./optional";
const
PLUGIN_NAME
=
"
drawio
"
;
const
execFile
=
promisify
(
child_process
.
execFile
);
const
drawio
=
withBinary
(
"
DRAWIO_BINARY
"
,
"
drawio
"
,
...
...
@@ -33,23 +31,21 @@ const drawio = withBinary(
input
.
path
,
];
const
{
stdout
,
stderr
}
=
await
execFile
(
DRAWIO_BINARY
,
args
);
if
(
stdout
.
length
>
0
)
{
logger
.
info
(
PLUGIN_NAME
,
"
stdout:
"
,
stdout
);
}
if
(
stderr
.
length
>
0
)
{
logger
.
info
(
PLUGIN_NAME
,
"
command:
"
,
DRAWIO_BINARY
,
args
);
logger
.
info
(
PLUGIN_NAME
,
"
stderr:
"
,
stderr
);
}
await
exec
(
PLUGIN_NAME
,
DRAWIO_BINARY
,
args
);
logger
.
info
(
"
%s: %s -> %s
"
,
PLUGIN_NAME
,
input
.
relative
,
output
.
relative
);
output
.
contents
=
fs
.
createReadStream
(
output
.
path
,
{
encoding
:
"
UTF-8
"
,
});
logger
.
info
(
"
%s: generated %s
"
,
PLUGIN_NAME
,
output
.
relative
);
this
.
push
(
output
);
}
catch
(
error
)
{
throw
new
PluginError
(
PLUGIN_NAME
,
error
);
throw
new
PluginError
(
PLUGIN_NAME
,
error
,
{
showStack
:
true
}
);
}
})
);
...
...
lib/exec.js
0 → 100644
View file @
2554c7ec
import
{
execFile
}
from
"
child_process
"
;
import
logger
from
"
gulplog
"
;
/**
*
* @param {string} plugin_name
* @param {string} cmd
* @param {string[]} args
* @param {import("child_process").ExecFileOptions} opts
* @return {Promise<{ stdout: string|Buffer, stderr: string|Buffer }>}
*/
export
default
function
exec
(
plugin_name
,
cmd
,
args
,
opts
=
{})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
execFile
(
cmd
,
args
,
opts
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
!
error
)
{
logger
.
debug
(
"
%s: %s terminated successfully
"
,
plugin_name
,
cmd
);
return
resolve
({
stdout
,
stderr
});
}
logger
.
error
(
"
%s: %s failed: %s
"
,
plugin_name
,
cmd
,
error
.
message
);
logger
.
error
(
"
%s: command: `%s %s`
"
,
plugin_name
,
cmd
,
args
.
join
(
"
"
));
logger
.
error
(
"
%s: stdout:
\n
%s
"
,
plugin_name
,
stdout
.
toString
());
logger
.
error
(
"
%s: stderr:
\n
%s
"
,
plugin_name
,
stderr
.
toString
());
reject
(
error
);
});
});
}
lib/wkhtmltopdf.js
View file @
2554c7ec
import
{
callbackify
,
promisify
}
from
"
util
"
;
import
child_process
from
"
child_process
"
;
import
{
callbackify
}
from
"
util
"
;
import
{
createReadStream
}
from
"
fs
"
;
import
exec
from
"
./exec
"
;
import
logger
from
"
gulplog
"
;
import
{
mkTempFile
}
from
"
./tempdir
"
;
import
{
obj
}
from
"
through2
"
;
...
...
@@ -8,8 +8,6 @@ import path from "path";
import
PluginError
from
"
plugin-error
"
;
import
{
withBinary
}
from
"
./optional
"
;
const
execFile
=
promisify
(
child_process
.
execFile
);
const
PLUGIN_NAME
=
"
wkhtmltopdf
"
;
const
DEFAULT_OPTIONS
=
{
...
...
@@ -59,17 +57,13 @@ export const wkhtmltopdf = withBinary(
output
.
path
,
];
const
{
stdout
,
stderr
}
=
await
execFile
(
WKHTMLTOPDF_BINARY
,
execArgs
await
exec
(
PLUGIN_NAME
,
WKHTMLTOPDF_BINARY
,
execArgs
);
logger
.
info
(
"
%s: %s -> %s
"
,
PLUGIN_NAME
,
input
.
relative
,
output
.
relative
);
logger
.
info
(
"
%s: generated %s
"
,
PLUGIN_NAME
,
output
.
relative
);
if
(
stdout
.
length
>
0
)
{
logger
.
debug
(
PLUGIN_NAME
,
"
stdout:
"
,
stdout
);
}
if
(
stderr
.
length
>
0
)
{
logger
.
debug
(
PLUGIN_NAME
,
"
stderr:
"
,
stderr
);
}
output
.
contents
=
createReadStream
(
output
.
path
);
this
.
push
(
output
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment