MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / checkFile

Function checkFile

tools/check-napi.js:10–38  ·  view source on GitHub ↗
(file, command, argv, reducer)

Source from the content-addressed store, hash-verified

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.
10function 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.
41function checkFileUNIX (file) {

Callers 2

checkFileUNIXFunction · 0.85
checkFileWin32Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected