forked from JaneaSystems/nodejs-mobile-cordova
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android: use helper script to call npm on macOS
On macOS, if Android Studio is not started through the command line, the PATH environment variable will probably not contain npm's location due to macOS environment variables in Windowed Applications not being the same. This commit adds a cordova hook to create a helper script that calls npm after adding the PATH elements that are available during the Cordova project's prepare step, so that npm can be called when the Gradle build is started by Android Studio.
- Loading branch information
1 parent
ff19463
commit 7fec514
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
install/hooks/android/after-prepare-create-macOS-builder-helper.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,28 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Adds a helper script to run "npm rebuild" with the current PATH. | ||
// This workaround is needed for Android Studio on macOS when it is not started | ||
// from the command line, as npm probably won't be in the PATH at build time. | ||
function buildMacOSHelperNpmBuildScript(context, platform) | ||
{ | ||
var platformPath = path.join(context.opts.projectRoot, 'platforms', platform); | ||
var platformAPI = require(path.join(platformPath, 'cordova', 'Api')); | ||
var platformAPIInstance = new platformAPI(); | ||
var wwwPath = platformAPIInstance.locations.www; | ||
var helperMacOSBuildScriptPath = path.join(wwwPath, 'build-native-modules-MacOS-helper-script.sh'); | ||
fs.writeFileSync( helperMacOSBuildScriptPath,`#!/bin/bash | ||
export PATH=$PATH:${process.env.PATH} | ||
npm $@ | ||
`, {"mode": 0o755} | ||
); | ||
} | ||
|
||
module.exports = function(context) | ||
{ | ||
if (context.opts.platforms.indexOf('android') >= 0) { | ||
if (process.platform === 'darwin') { | ||
buildMacOSHelperNpmBuildScript(context, 'android'); | ||
} | ||
} | ||
} |
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