(file, command, argv, reducer)
| 8 | // Read the output of the command, break it into lines, and use the reducer to |
| 9 | // decide whether the file is an N-API module or not. |
| 10 | function checkFile (file, command, argv, reducer) { |
| 11 | const child = require('child_process').spawn(command, argv, { |
| 12 | stdio: ['inherit', 'pipe', 'inherit'] |
| 13 | }); |
| 14 | let leftover = ''; |
| 15 | let isNapi; |
| 16 | child.stdout.on('data', (chunk) => { |
| 17 | if (isNapi === undefined) { |
| 18 | chunk = (leftover + chunk.toString()).split(/[\r\n]+/); |
| 19 | leftover = chunk.pop(); |
| 20 | isNapi = chunk.reduce(reducer, isNapi); |
| 21 | if (isNapi !== undefined) { |
| 22 | child.kill(); |
| 23 | } |
| 24 | } |
| 25 | }); |
| 26 | child.on('close', (code, signal) => { |
| 27 | if ((code === null && signal !== null) || (code !== 0)) { |
| 28 | console.log( |
| 29 | command + ' exited with code: ' + code + ' and signal: ' + signal); |
| 30 | } else { |
| 31 | // Green if it's a N-API module, red otherwise. |
| 32 | console.log( |
| 33 | '\x1b[' + (isNapi ? '42' : '41') + 'm' + |
| 34 | (isNapi ? ' N-API' : 'Not N-API') + |
| 35 | '\x1b[0m: ' + file); |
| 36 | } |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | // Use nm -a to list symbols. |
| 41 | function checkFileUNIX (file) { |
no outgoing calls
no test coverage detected