-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ios: cache native modules override preference
Saves the NODEJS_MOBILE_BUILD_NATIVE_MODULES environment variable value to a file if it is defined during the Cordova prepare phase to be read by iOS during build time, similar to the way it is working for Android. It's also possible to create the file in www/ instead of using the environment variable.
- Loading branch information
1 parent
3d430ec
commit 29240cd
Showing
4 changed files
with
52 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
install/hooks/both/after-prepare-native-modules-preference.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Gets the platform's www path. | ||
function getPlatformWWWPath(context, platform) | ||
{ | ||
var platformPath = path.join(context.opts.projectRoot, 'platforms', platform); | ||
var platformAPI = require(path.join(platformPath, 'cordova', 'Api')); | ||
var platformAPIInstance = new platformAPI(); | ||
return platformAPIInstance.locations.www; | ||
} | ||
|
||
// Adds a file to save the contents of the NODEJS_MOBILE_BUILD_NATIVE_MODULES | ||
// environment variable if it is set during the prepare step. | ||
function saveBuildNativeModulesPreference(context, platform) | ||
{ | ||
var wwwPath = getPlatformWWWPath(context, platform); | ||
var saveBuildNativeModulesPreferencePath = path.join(wwwPath, 'NODEJS_MOBILE_BUILD_NATIVE_MODULES_VALUE.txt'); | ||
if (process.env.NODEJS_MOBILE_BUILD_NATIVE_MODULES !== undefined) { | ||
fs.writeFileSync(saveBuildNativeModulesPreferencePath, process.env.NODEJS_MOBILE_BUILD_NATIVE_MODULES); | ||
} | ||
} | ||
|
||
module.exports = function(context) | ||
{ | ||
if (context.opts.platforms.indexOf('android') >= 0) { | ||
saveBuildNativeModulesPreference(context, 'android'); | ||
} | ||
if (context.opts.platforms.indexOf('ios') >= 0) { | ||
saveBuildNativeModulesPreference(context, 'ios'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters