( workerFunction: WorkerFn<Options>, )
| 31 | ) => void; |
| 32 | |
| 33 | function wrapWorkerFn<Options>( |
| 34 | workerFunction: WorkerFn<Options>, |
| 35 | ): WorkerFnWithIO<Options> { |
| 36 | return ( |
| 37 | infile: Path, |
| 38 | outfile: Path, |
| 39 | options: Options, |
| 40 | callback: Callback<>, |
| 41 | ) => { |
| 42 | const contents = fs.readFileSync(infile); |
| 43 | workerFunction(contents, options, (error, result) => { |
| 44 | if (error) { |
| 45 | callback(error); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | try { |
| 50 | mkdirp.sync(dirname(outfile)); |
| 51 | fs.writeFileSync(outfile, JSON.stringify(result), 'utf8'); |
| 52 | } catch (writeError) { |
| 53 | callback(writeError); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | callback(null); |
| 58 | }); |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | module.exports = wrapWorkerFn; |
no test coverage detected
searching dependent graphs…