Showing posts with label cordova. Show all posts
Showing posts with label cordova. Show all posts

Friday, December 16, 2016

Clone Cordova application using MobileFirst CLI

Hi folk,

Recently a customer asked me to help them creating a process of cloning configuration from mobile Cordova applications, from one version to another, using the IBM MobileFirst™ PlatformCommand Line Interface (CLI). The idea is to be able to automate the process in its continuous integration software development.

Currently the tool offers the cloning procedure from the operations console:





But MFP command-line does not have "clone" functionality today :/, who has said fear? :)

You can transfer an application configuration from a one server to another by using command-line tools or a REST API.

So, I have created a cloning functionality using nodejs-based program and mfpdev commands with the following business logic:

1) Pull the application descriptor JSON File:

Retrieves an existing app configuration from the server. The configuration includes the contents of the application descriptor, which uniquely identifies the app to the server and other information that is specific to the app. 
The configuration files are provided as compressed files (.zip format). 

2) Unzip artifacts zip file:

The .zip files are placed in the directory appName/mobilefirst and named as follows:
appID-platform-version-artifacts.zip

where:
appID is the application name,  
platform is one of android, ios, or windows
version is the version level of your app. 
For Cordova apps, a separate .zip file is created for each target platform.

3) Add version Application-Descriptor JSON File:

The application descriptor file is a JSON file that contains the description and configuration of your application. When you run an app that connects to a MobileFirst Server instance, the app must be registered with that server and configured.

4) Zip new artifacts zip file:
The .zip files are placed in the directory appName/mobilefirst and named as follows:
appID-platform-newversion-artifacts.zip

5) Modify the version in configuracion file (config.xml)

The Cordova configuration file is a mandatory XML file that contains application metadata, and is stored in the root directory of the app. The file is automatically generated when you create a Cordova application.

Information about this file in the Apache Cordova config.xml documentation.

6) Register application

Registers your app with a MobileFirst Server.

7) Push application

This command sends the .zip file to the MobileFirst Server. The client properties file myapp1/app/src/main/assets/mfpclient.properties is modified to reflect that the server that the app is registered.

Example - Clone version 1.0.1 to 2.0.0:

I have an app registered with the following versions:



In the app directory run following command:




$ node cloneApp.js local mfp jif.example.hellocordova android 1.0.1 2.0.0

When the process is finished, the new registered version must be displayed:



The source code can be downloaded from:
https://github.com/jorgeiglesiasfernandez/CloneApp
Note: Application authenticity and web resources will not be cloned. If you import an application that includes authenticity data, and if the application itself has been recompiled since the authenticity data was generated, you must refresh the authenticity data. For more information, see Configuring the application-authenticity security check.

Cheers!

Monday, November 14, 2016

IBM MobileFirst Platform 8.0 - Developing Applications (Adding the MobileFirst SDK to Cordova Applications)

Hi folk, again back with new developments. I will start a series of post about the development of applications for mobile devices based on IBM MobileFirst Platform.

The idea is to learn new concepts about: MobileFirst-provided APIs for Native, Cordova and Web applications, such as JSONStore and WLResourceReuest.
The MobileFirst Cordova SDK is provided as a set of Cordova plug-ins, and is registered at NPM.
NPM is the package manager for JavaScript.

Available plug-ins are:
  • cordova-plugin-mfp - The core SDK plug-in
  • cordova-plugin-mfp-push - Provides push notifications support
  • cordova-plugin-mfp-jsonstore - Provides JSONStore support
  • cordova-plugin-mfp-fips - Android only. Provides FIPS support
  • cordova-plugin-mfp-encrypt-utils - iOS only. Provides support for encryption and decryption
The Cordova platform versions supported by the MobileFirst plug-ins, are:
  • cordova-ios: >= 4.1.1 and < 5.0
  • cordova-android: >= 5.1.1 and < 6.0
  • cordova-windows: >= 4.3.2 and < 5.0
Prerequisites:
  • Apache Cordova CLI 6.x and MobileFirst CLI installed on the developer workstation.
  • A local or remote instance of MobileFirst Server is running.
  • Setting up your Cordova development environment.
Before you start, make sure that the MobileFirst Server is running.

Procedure:

1. Check Cordova version
$ cordova -v
6.1.1

2. Create Cordova project
$ cordova create MyHelloCordova jif.example.hellocordova MyHelloCordova --template cordova-template-mfp
Creating a new cordova project.
Retrieving cordova-template-mfp using npm...


Note:
“MyHelloCordova” is the folder name of the application
“jif.example.hellocordova” is the ID of the application
“MyHelloCordova” is the Name of the application
--template modifies the application with MobileFirst-specific additions
Because the application was configured using the MobileFirst template, the MobileFirst core Cordova plug-in is added automatically.



3. Change directory to Cordova project:
$ cd MyHelloCordova

4. Add one or more supported platforms to the Cordova project by using the Cordova CLI command: cordova platform add ios|android|windows. For example:
$ cordova platform add android

5. Registering the application to MobileFirst Server
$ mfpdev app register
Verifying server configuration...
Registering to server:'http://####.####.####.####:9080' runtime:'mfp'
Updated config.xml file located at: /Users/jorge/Development/Mobile/mfp/workspace/MyHelloCordova/config.xml
Run 'cordova prepare' to propagate changes.
Registered app for platform: android


Note: You can also register applications from the MobileFirst Operations Console

6. Propagate changes and run the example
$ cordova prepare
$ cordova emulate