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!

No comments:

Post a Comment