Skip to content

Commit

Permalink
Merge pull request #35 from CanalTP/hotfix/2.3.1
Browse files Browse the repository at this point in the history
hotfix/2.3.1
  • Loading branch information
RachikAbidi authored Nov 2, 2020
2 parents 4ad8b77 + 1eb953d commit 139edb4
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 45 deletions.
62 changes: 42 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,56 @@

Cordova plugin for using Navitia SDK iOS & Android

## Installation
## Requirements

This plugin uses native SDKs. Since those SDKs are private, you will need to get access credentials to our [artifactory](https://kisiodigital.jfrog.io). This plugin uses Cocoapods to manage dependencies for iOS, please install it first: https://cocoapods.org.

## Credentials configuration

Use this command to install the plugin
Once you have credentials to access our [artifactory](https://kisiodigital.jfrog.io), one further step is required before installing the plugin. Please follow one of these steps to configure the credentials properly.
The `<YOUR_ARTIFACTORY_USERNAME>` and `<YOUR_ARTIFACTORY_PASSWORD>` should be replaced with your username and password!

cordova plugin add cordova-plugin-navitia-sdk --variable ARTIFACTORY_USERNAME=username --variable ARTIFACTORY_PASSWORD=password
#### Using Config.xml preferences

In the Config.xml file of your project, add these lines:

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>
.
.
<preference name="KISIO_ARTIFACTORY_USERNAME" value="<YOUR_ARTIFACTORY_USERNAME>" />
<preference name="KISIO_ARTIFACTORY_PASSWORD" value="<YOUR_ARTIFACTORY_PASSWORD>" />
</widget>
```
or in the package.json file
```json
{
"cordova": {
"plugins": {
"cordova-plugin-navitia-sdk": {
"ARTIFACTORY_USERNAME": "username",
"ARTIFACTORY_PASSWORD": "password"
}
}
}
}

#### Using environment variables

Define two global environment variables as follows:
```
KISIO_ARTIFACTORY_USERNAME=<YOUR_ARTIFACTORY_USERNAME>
KISIO_ARTIFACTORT_PASSWORD=<YOUR_ARTIFACTORY_PASSWORD>
```

#### Using global properties files (MacOS users only)

##### iOS

In the Home directory, open `.netrc` file (if not found, create a new file) and add this line:
```
machine kisiodigital.jfrog.io login <YOUR_ARTIFACTORY_USERNAME> password <YOUR_ARTIFACTORY_PASSWORD>
``````
##### Android
In the `~/.gradle` directory, open `gradle.properties`file (if not found, create a new file) andd these lines:
```
kisio_artifactory_username=<YOUR_ARTIFACTORY_USERNAME>
kisio_artifactory_password=<YOUR_ARTIFACTORY_PASSWORD>
```
## Installation
Use this command to install the plugin `cordova plugin add cordova-plugin-navitia-sdk`
## Usage
Expand Down
87 changes: 70 additions & 17 deletions hooks/add_artifactory_conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,103 @@ module.exports = function(ctx) {
var package;
try {
package = require(ctx.opts.projectRoot + '/package.json');
} catch (err) { }
} catch (err) {
console.log(err);
}

var loadConfigXMLFile = function() {
try {
var fs = require('fs');
var xml2js = require('xml2js');
var fileData = fs.readFileSync("config.xml", 'ascii');
var parser = new xml2js.Parser();
var configFileJson = "";

parser.parseString(fileData.substring(0, fileData.length), function (err, result) {
configFileJson = result;
});

return configFileJson;
} catch (ex) {
console.log(ex)
}
}

var getRequestedPreferenceFromConfig = function(preferencesList, requestedPreferenceName) {
for (const preference of preferencesList) {
if (preference["$"].name === requestedPreferenceName) {
return preference["$"].value;
}
}

return null
}

const PLUGIN_ID = ctx.opts.plugin.id;
var configFileContent = loadConfigXMLFile();
var projectPreferences = configFileContent.widget.preference

var PLUGIN_ID = ctx.opts.plugin.id;
var getRequestedPreference = function(key) {
// Check in project preferences
var keyConfigPreference = getRequestedPreferenceFromConfig(projectPreferences, key);
if (keyConfigPreference) {
return keyConfigPreference;
}

// Check in environment variables
if (process.env[key]) {
return process.env[key]
}

var _getPreferenceValue = function(key) {
// Check in Package.json (project) file
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];
}

// Check in Config.xml (project) file
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;
}

// Check in plugin default preferences
var defaultPreferences = ctx.opts.plugin.pluginInfo.getPreferences();
if (defaultPreferences[key]) {
return defaultPreferences[key]
}

throw key + " is not found. Please make sure to follow instructions in : https://github.com/CanalTP/CDVNavitiaSDKUX#requirements";
}

if (ctx.opts.platforms.includes('android')) {
if (ctx.opts.cordova.platforms.includes('android')) {
// Android platform: add the authentification informations into the gradle.properties file in the project
console.log('➕ Adding authentication credentials to Android platform')
var gradlePropertiesPath = './platforms/android/gradle.properties';
var gradleProperties = fs.readFileSync(gradlePropertiesPath);
gradleProperties = gradleProperties.toString();
var gradleProperties = fs.readFileSync(gradlePropertiesPath);
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')}`;
gradleProperties += `\nkisio_artifactory_url=${getRequestedPreference('KISIO_ARTIFACTORY_URL')}`;
gradleProperties += `\nkisio_artifactory_username=${getRequestedPreference('KISIO_ARTIFACTORY_USERNAME')}`;
gradleProperties += `\nkisio_artifactory_password=${getRequestedPreference('KISIO_ARTIFACTORY_PASSWORD')}`;
gradleProperties += `\nkisio_artifactory_android_repo_release=${getRequestedPreference('KISIO_ARTIFACTORY_ANDROID_REPO_RELEASE')}`;
gradleProperties += `\nkisio_artifactory_android_repo_snapshot=${getRequestedPreference('KISIO_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')) {
if (ctx.opts.cordova.platforms.includes('ios')) {
// IOS platform: add the authentification informations into the .netrc file (on the home directory)
console.log('➕ Adding authentication credentials to iOS platform')
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`;
var machine = getRequestedPreference('KISIO_ARTIFACTORY_URL').match(/^https?:\/\/([^:\/?#]*)/)[1];
if (machine) {
var netrcLine = `machine ${machine} login ${getRequestedPreference('KISIO_ARTIFACTORY_USERNAME')} password ${getRequestedPreference('KISIO_ARTIFACTORY_PASSWORD')}\n`;
var netrcContent = '';
if (fs.existsSync(netrcPath)) {
var netrcContent = fs.readFileSync(netrcPath).toString() || '';
Expand All @@ -60,6 +112,7 @@ module.exports = function(ctx) {
} else {
netrcContent += netrcLine;
}

fs.writeFileSync(netrcPath, netrcContent, 'utf8');
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-navitia-sdk",
"version": "2.3.0",
"version": "2.3.1",
"description": "Cordova plugin for NavitiaSDK iOS & Android",
"cordova": {
"id": "org-kisio-plugins-navitia-sdk",
Expand Down
12 changes: 5 additions & 7 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-navitia-sdk" version="2.3.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.3.1" 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" />
<preference name="KISIO_ARTIFACTORY_URL" default="https://kisiodigital.jfrog.io/kisiodigital/" />
<preference name="KISIO_ARTIFACTORY_ANDROID_REPO_RELEASE" default="android-release" />
<preference name="KISIO_ARTIFACTORY_ANDROID_REPO_SNAPSHOT" default="android-snapshot" />
<hook src="hooks/add_artifactory_conf.js" type="before_plugin_install" />

<js-module name="NavitiaSDK" src="www/NavitiaSDK.js">
<clobbers target="NavitiaSDK" />
Expand Down

0 comments on commit 139edb4

Please sign in to comment.