Skip to content

Commit

Permalink
plugin: add automatic native modules detection
Browse files Browse the repository at this point in the history
Adds automatic detection of native modules by looking for .gyp files
inside the nodejs-project modules.
  • Loading branch information
jaimecbernardo committed Jun 27, 2018
1 parent fea9773 commit 7dcbe77
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions install/hooks/ios/after-plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then
PREFERENCE_FILE_PATH="$CODESIGNING_FOLDER_PATH/www/NODEJS_MOBILE_BUILD_NATIVE_MODULES_VALUE.txt"
if [ -f "$PREFERENCE_FILE_PATH" ]; then
NODEJS_MOBILE_BUILD_NATIVE_MODULES="$(cat $PREFERENCE_FILE_PATH | xargs)"
fi
fi
if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then
# If build native modules preference is not set, try to find .gyp files
#to turn it on.
gypfiles=($(find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -type f -name "*.gyp"))
if [ \${#gypfiles[@]} -gt 0 ]; then
NODEJS_MOBILE_BUILD_NATIVE_MODULES=1
else
NODEJS_MOBILE_BUILD_NATIVE_MODULES=0
fi
Expand Down Expand Up @@ -80,6 +88,14 @@ if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then
NODEJS_MOBILE_BUILD_NATIVE_MODULES="$(cat $PREFERENCE_FILE_PATH | xargs)"
# Remove the preference file so it doesn't get in the application package.
rm "$PREFERENCE_FILE_PATH"
fi
fi
if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then
# If build native modules preference is not set, try to find .gyp files
#to turn it on.
gypfiles=($(find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -type f -name "*.gyp"))
if [ \${#gypfiles[@]} -gt 0 ]; then
NODEJS_MOBILE_BUILD_NATIVE_MODULES=1
else
NODEJS_MOBILE_BUILD_NATIVE_MODULES=0
fi
Expand Down
16 changes: 16 additions & 0 deletions src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ if (shouldRebuildNativeModules==null) {
}
}

if (shouldRebuildNativeModules==null) {
// If build native modules preference is not set, try to find .gyp files to turn it on.
shouldRebuildNativeModules="0";
def gyp_files_tree = fileTree(
dir: "${project.projectDir}/assets/www/nodejs-project/",
include: "**/*.gyp"
);
gyp_files_tree.visit { gypFile ->
if (!gypFile.isDirectory()) {
// It's a .gyp file.
shouldRebuildNativeModules="1";
gypFile.stopVisiting();
}
}
}

if ("1".equals(shouldRebuildNativeModules)) {

String npmCommandName = 'npm';
Expand Down

0 comments on commit 7dcbe77

Please sign in to comment.