Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hooks/before-prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function ($logger, $projectData) {
utils.setLogger(_log);

if (utils.targetsAndroid($projectData.projectDir)) {
utils.addIfNecessary($projectData.platformsDir);
utils.addIfNecessary($projectData.platformsDir, $projectData.appResourcesDirectoryPath);
}

function _log (str) {
Expand Down
18 changes: 9 additions & 9 deletions src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function checkForGoogleServicesJson(projectDir, resourcesDir) {
}
}

function addOnPluginInstall(platformsDir) {
function addOnPluginInstall(platformsDir, resourcesDir) {
if (buildGradleExists(platformsDir)) {
addIfNecessary(platformsDir);
addIfNecessary(platformsDir, resourcesDir);
}
}

function addIfNecessary(platformsDir) {
function addIfNecessary(platformsDir, resourcesDir) {
_amendBuildGradle(platformsDir, function(pluginImported, pluginApplied, fileContents) {
if (!pluginImported) {
fileContents.projectFileContents = _addPluginImport(fileContents.projectFileContents);
Expand All @@ -49,7 +49,7 @@ function addIfNecessary(platformsDir) {
return fileContents;
});

_copyGoogleServices(platformsDir);
_copyGoogleServices(resourcesDir, platformsDir);
}

function removeIfPresent(platformsDir) {
Expand Down Expand Up @@ -80,8 +80,8 @@ var _versionRegExp = '[^\'"]+';
var _pluginImportName = 'com.google.gms:google-services';
var _pluginApplicationName = 'com.google.gms.google-services';

function _copyGoogleServices(platformsDir) {
var srcServicesFile = path.join(platformsDir, '..', 'app', 'App_Resources', 'Android', 'google-services.json');
function _copyGoogleServices(resourcesDir, platformsDir) {
var srcServicesFile = path.join(resourcesDir, 'Android', 'google-services.json');
var dstServicesFile = path.join(platformsDir, 'android', 'app', 'google-services.json');
if (fs.existsSync(srcServicesFile) && !fs.existsSync(dstServicesFile) && fs.existsSync(path.join(platformsDir, 'android', 'app'))) {
// try to copy google-services config file to platform app directory
Expand Down Expand Up @@ -130,15 +130,15 @@ function _removePluginApplication(buildGradleContents) {
function _addPluginImport(buildGradleContents) {
var androidGradle = 'com.android.tools.build:gradle';
var insertBeforeDoubleQuotes = 'classpath "' + androidGradle;
var insertBeforeSingleQoutes = 'classpath \'' + androidGradle;
var insertBeforeSingleQuotes = 'classpath \'' + androidGradle;
var quoteToInsert = '"'
var matchedString = insertBeforeDoubleQuotes;
var ind = buildGradleContents.indexOf(insertBeforeDoubleQuotes);

if (ind === -1) {
ind = buildGradleContents.indexOf(insertBeforeSingleQoutes);
ind = buildGradleContents.indexOf(insertBeforeSingleQuotes);
quoteToInsert = '\'';
matchedString = insertBeforeSingleQoutes;
matchedString = insertBeforeSingleQuotes;
}

if (ind === -1) {
Expand Down
16 changes: 14 additions & 2 deletions src/scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ var projDir = hook.findProjectDir();
hook.postinstall();

if (projDir) {
utils.checkForGoogleServicesJson(projDir, path.join(projDir, 'app', 'App_Resources'));
utils.addOnPluginInstall(path.join(projDir, 'platforms'));
var resourcesDir;

try {
var globalPath = require('child_process').execSync('npm root -g').toString().trim();
var tns = require(path.join(globalPath, 'nativescript'));
var project = tns.projectDataService.getProjectData(projDir);
resourcesDir = project.appResourcesDirectoryPath;
} catch (exc) {
console.log('Push plugin cannot find project root. Project will be initialized during build.');
}
if (resourcesDir) {
utils.checkForGoogleServicesJson(projDir, resourcesDir);
utils.addOnPluginInstall(path.join(projDir, 'platforms'), resourcesDir);
}
}