Commit a8cfed21 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Met en place une exécution parallèle pour les filtres drawio, pandoc et wkhtmltopdf.

parent 0010bba8
import { callbackify } from "util";
import exec from "../util/exec";
import fs from "fs";
import logger from "gulplog";
import { mkTempFile } from "../util/tempdir";
import { obj } from "through2";
import parallel from "../util/parallel";
import PluginError from "plugin-error";
import { withBinary } from "../util/optional";
......@@ -14,8 +13,7 @@ const drawio = withBinary(
"drawio",
(DRAWIO_BINARY) =>
function drawio() {
return obj(
callbackify(async function (input) {
return parallel(async function (input) {
try {
const output = await mkTempFile(input);
output.extname = ".svg";
......@@ -47,8 +45,7 @@ const drawio = withBinary(
} catch (error) {
throw new PluginError(PLUGIN_NAME, error, { showStack: true });
}
})
);
});
}
);
......
import { callbackify, promisify } from "util";
import exec from "../util/exec";
import fs from "fs";
import { merge } from "merge-anything";
import { mkTempFile } from "../util/tempdir";
import { obj } from "through2";
import parallel from "../util/parallel";
import path from "path";
import PluginError from "plugin-error";
import { promisify } from "util";
const writeFile = promisify(fs.writeFile);
const exists = promisify(fs.exists);
......@@ -87,8 +87,7 @@ export default function pandoc(options = {}) {
);
const revealJSURLResolver = getRevealJSResolver(revealJSURL);
return obj(
callbackify(
return parallel(
/**
* @param {import("vinyl")} input
*/
......@@ -122,6 +121,5 @@ export default function pandoc(options = {}) {
this.push(output);
}
)
);
}
import { callbackify } from "util";
import { createReadStream } from "fs";
import exec from "../util/exec";
import { mkTempFile } from "../util/tempdir";
import { obj } from "through2";
import parallel from "../util/parallel";
import path from "path";
import PluginError from "plugin-error";
import { withBinary } from "../util/optional";
......@@ -46,8 +45,7 @@ export const wkhtmltopdf = withBinary(
(WKHTMLTOPDF_BINARY) =>
function wkhtmltopdf(options = {}) {
const { args } = Object.assign({}, DEFAULT_OPTIONS, options);
return obj(
callbackify(async function (input) {
return parallel(async function (input) {
try {
const output = await mkTempFile(getPDFOutput(input));
const execArgs = [
......@@ -64,7 +62,7 @@ export const wkhtmltopdf = withBinary(
throw new PluginError(PLUGIN_NAME, err, { filename: input.path });
}
})
);
;
}
);
......
import { cpus } from "os";
import { obj } from "through2";
import pMap from "p-map";
const concurrency = cpus().length;
/**
*
* @param {(file) => Promise<any>} mapper
* @return {import('stream').Transform}
*/
export default function parallel(mapper) {
const inputs = [];
return obj(
function collect(input, _enc, done) {
inputs.push(input);
done();
},
function mapAll(done) {
pMap(inputs, mapper.bind(this), { concurrency, stopOnError: false }).then(
() => done(),
error => done(error)
);
}
);
}
......@@ -2916,6 +2916,16 @@
"p-map": "^3.0.0",
"rimraf": "^3.0.0",
"slash": "^3.0.0"
},
"dependencies": {
"p-map": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz",
"integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==",
"requires": {
"aggregate-error": "^3.0.0"
}
}
}
},
"delayed-stream": {
......@@ -8308,9 +8318,9 @@
}
},
"p-map": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz",
"integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==",
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz",
"integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==",
"requires": {
"aggregate-error": "^3.0.0"
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment