Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there wildcard mechanism for listing sources in node-gyp

Tags:

node-gyp

I'm writing binding.gyp file for my new node.js module. I have all my source files under src/ subdirectory. I would like to use all of them while building the module. Instead of modifying binding.gyp each time I add a new cpp file, I would like to list all cpp files through some wildcard mechanism. Does node-gyp support that? Something like following (which doesn't work

{
  'targets' : [
      {
          'target_name' : 'mymod',
          'sources' : 'src/*.cpp'
      }
   ]
}

I looked at https://code.google.com/p/gyp/wiki/InputFormatReference , but didn't find anything readily useful.

like image 293
Jayesh Avatar asked Mar 13 '13 22:03

Jayesh


1 Answers

Figured it out

{
  'targets' : [
      {
          'target_name' : 'mymod',
          'sources' : [ '<!@(ls -1 src/*.cpp)' ],
      }
   ]
}

Check out this link

Update

The solution above is not portable across platforms. Here's a portable version:

{
  'targets' : [
      {
          'target_name' : 'mymod',
          'sources' : [  "<!@(node -p \"require('fs').readdirSync('./src').map(f=>'src/'+f).join(' ')\")" ],
      }
   ]
}

Essentially it replaces the platform specific directory listing command (ls), by Javascript code that uses node's fs module to list the directory contents.

like image 99
Jayesh Avatar answered Oct 18 '22 12:10

Jayesh