Is there a wildcard mechanism for including sources in node -gyp

I am writing a binding.gyp file for my new module node.js. I have all the source files in the src/ subdirectory. I would like to use them all when creating the module. Instead of modifying binding.gyp every time I add a new cpp file, I would like to list all cpp files through some kind of template. Does node-gyp support? Something like the following (which doesn't work

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

I looked at https://code.google.com/p/gyp/wiki/InputFormatReference but did not find anything useful.

+7
source share
2 answers

It revealed

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

Mark this link

Update

The solution above is not portable across platforms. Here is the 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 ( ls ) ls with Javascript code, which uses the node fs module to display the contents of the directory.

+19
source

An even more portable version (which is independent of node, but rather python):

 "< !@ (python -c \"import os; print '\n'.join(['%s' % x for x in os.listdir('.') if x[-3:] == '.cc' and 'test' not in x])\")" 
-one
source

All Articles