Skip to content

Commit

Permalink
Merge pull request #31 from CanalTP/release/2.2.0
Browse files Browse the repository at this point in the history
Release/2.2.0
  • Loading branch information
RachikAbidi authored Jun 12, 2020
2 parents 3408990 + cf9c1d1 commit 550ace8
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 4 deletions.
27 changes: 26 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,32 @@ Cordova plugin for using Navitia SDK iOS & Android

## Installation

cordova plugin add cordova-plugin-navitia-sdk
Use this command to install the plugin

cordova plugin add cordova-plugin-navitia-sdk --variable ARTIFACTORY_USERNAME=username --variable ARTIFACTORY_PASSWORD=password

You can also add the plugin directly in the config.xml file
```xml
<widget>
<plugin name="cordova-plugin-navitia-sdk">
<variable name="ARTIFACTORY_USERNAME" value="username" />
<variable name="ARTIFACTORY_PASSWORD" value="password" />
</plugin>
</widget>
```
or in the package.json file
```json
{
"cordova": {
"plugins": {
"cordova-plugin-navitia-sdk": {
"ARTIFACTORY_USERNAME": "username",
"ARTIFACTORY_PASSWORD": "password"
}
}
}
}
```

## Usage

Expand Down
66 changes: 66 additions & 0 deletions hooks/add_artifactory_conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module.exports = function(ctx) {
var fs = require('fs');
var os = require('os');
var package;
try {
package = require(ctx.opts.projectRoot + '/package.json');
} catch (err) { }

var PLUGIN_ID = ctx.opts.plugin.id;

var _getPreferenceValue = function(key) {
if (package && package.cordova && package.cordova.plugins && package.cordova.plugins[PLUGIN_ID] && package.cordova.plugins[PLUGIN_ID][key]) {
return package.cordova.plugins[PLUGIN_ID][key];
}

var config = fs.readFileSync('config.xml').toString();
var confValue = config.match(new RegExp(`"${PLUGIN_ID}"(.(?!<\/plugin>))*?<variable name="${key}" value="(.*?)".*?<\/plugin>`, 'is'));
if (confValue && confValue[2]) {
return confValue[2];
} else {
var defaultPreferences = ctx.opts.plugin.pluginInfo.getPreferences();
return defaultPreferences[key] || null;
}
}

if (ctx.opts.platforms.includes('android')) {
// Android platform: add the authentification informations into the gradle.properties file in the project
var gradlePropertiesPath = './platforms/android/gradle.properties';
var gradleProperties = fs.readFileSync(gradlePropertiesPath);
gradleProperties = gradleProperties.toString();
if (gradleProperties) {
gradleProperties = gradleProperties.toString();
if (!gradleProperties.match('kisio_artifactory_url')) {
gradleProperties += `\nkisio_artifactory_url=${_getPreferenceValue('ARTIFACTORY_URL')}`;
gradleProperties += `\nkisio_artifactory_username=${_getPreferenceValue('ARTIFACTORY_USERNAME')}`;
gradleProperties += `\nkisio_artifactory_password=${_getPreferenceValue('ARTIFACTORY_PASSWORD')}`;
gradleProperties += `\nkisio_artifactory_android_repo_release=${_getPreferenceValue('ARTIFACTORY_ANDROID_REPO_RELEASE')}`;
gradleProperties += `\nkisio_artifactory_android_repo_snapshot=${_getPreferenceValue('ARTIFACTORY_ANDROID_REPO_SNAPSHOT')}`;
fs.writeFileSync(gradlePropertiesPath, gradleProperties, 'utf8');
}
} else {
console.error('gradle.properties file not found to add the kisio plugins dependencies');
}
}

if (ctx.opts.platforms.includes('ios')) {
// IOS platform: add the authentification informations into the .netrc file (on the home directory)
var netrcPath = os.homedir() + '/.netrc';
var machine = _getPreferenceValue('ARTIFACTORY_URL').match(/^https?:\/\/([^:\/?#]*)/)[1];
var netrcLine = `machine ${machine} login ${_getPreferenceValue('ARTIFACTORY_USERNAME')} password ${_getPreferenceValue('ARTIFACTORY_PASSWORD')}\n`;
if (machine) {
var netrcContent = '';
if (fs.existsSync(netrcPath)) {
var netrcContent = fs.readFileSync(netrcPath).toString() || '';
if (!netrcContent.match(new RegExp(`machine ${machine}`))) {
netrcContent += `\n${netrcLine}`;
} else {
netrcContent = netrcContent.replace(new RegExp(`machine ${machine}[ \n]login (.*?)[ \n]password (.*?)(?=\n|$)`, 'ism'), netrcLine);
}
} else {
netrcContent += netrcLine;
}
fs.writeFileSync(netrcPath, netrcContent, 'utf8');
}
}
};
55 changes: 55 additions & 0 deletions hooks/add_buildPhase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module.exports = function(ctx) {
var fs = require('fs');
var path = require('path');
var et = require('elementtree');
var xcode = require('xcode');

var PLUGIN_ID = ctx.opts.plugin.id;
var PLUGIN_NAME = ctx.opts.plugin.pluginInfo.name;

// Get the projet name
var config = path.join(ctx.opts.projectRoot, 'config.xml');
var config_contents = fs.readFileSync(config, 'utf-8').toString();
if (config_contents) {
config_contents = config_contents.substring(config_contents.indexOf('<'));
}
var configXmlData = new et.ElementTree(et.XML(config_contents));
var projectName = configXmlData.findtext('name');

// Get the xcode project
var projectPath = path.join(ctx.opts.projectRoot, '/platforms/ios/', projectName + '.xcodeproj/project.pbxproj');
var proj = xcode.project(projectPath);

proj.parseSync();
proj.addBuildPhase([], 'PBXShellScriptBuildPhase', `[${PLUGIN_ID}] Run Script ${PLUGIN_NAME}`, proj.getFirstTarget().uuid, {
shellPath: '/bin/sh',
shellScript: `
APP_PATH="$\{TARGET_BUILD_DIR}/$\{WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: $\{ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "$\{EXTRACTED_ARCHS[@]}"
rm "$\{EXTRACTED_ARCHS[@]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
`,
inputPaths: [
`"$(SRCROOT)/${projectName}/Plugins/${PLUGIN_ID}/${PLUGIN_NAME}.framework"`
]
});
fs.writeFileSync(projectPath, proj.writeSync());
};
8 changes: 6 additions & 2 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-navitia-sdk",
"version": "2.1.0",
"version": "2.2.0",
"description": "Cordova plugin for NavitiaSDK iOS & Android",
"cordova": {
"id": "org-kisio-plugins-navitia-sdk",
Expand All @@ -16,5 +16,9 @@
"navitia"
],
"author": "Kisio Digital",
"license": "GPL-3.0"
"license": "GPL-3.0",
"devDependencies": {
"elementtree": "0.1.7",
"xcode": "2.0.0"
}
}
11 changes: 10 additions & 1 deletion plugin.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-navitia-sdk" version="2.1.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="cordova-plugin-navitia-sdk" version="2.2.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>NavitiaSDK</name>

<preference name="ARTIFACTORY_USERNAME"/>
<preference name="ARTIFACTORY_PASSWORD" />
<preference name="ARTIFACTORY_URL" default="https://kisiodigital.jfrog.io/kisiodigital/" />
<preference name="ARTIFACTORY_ANDROID_REPO_RELEASE" default="android-release" />
<preference name="ARTIFACTORY_ANDROID_REPO_SNAPSHOT" default="android-snapshot" />
<hook src="hooks/add_artifactory_conf.js" type="before_prepare" />

<js-module name="NavitiaSDK" src="www/NavitiaSDK.js">
<clobbers target="NavitiaSDK" />
</js-module>
Expand All @@ -23,6 +30,8 @@
<pod name="NavitiaSDK" spec="1.4.3"/>
</pods>
</podspec>

<hook src="hooks/add_buildPhase.js" type="after_platform_add" />
</platform>

<platform name="android">
Expand Down

0 comments on commit 550ace8

Please sign in to comment.