Using CLI to create, build, and manage MobileFirst project artifacts

improve this page | report issue

Overview

IBM MobileFirst Platform Foundation provides a Command Line Interface (CLI) tool to easily create, manage, push, and register MobileFirst client and server artifacts. The CLI tool enables you to use your preferred code editors or alternative IDEs.

By using the CLI, you can create and manage the following types of applications: Classic MobileFirst hybrid applications, Cordova-based applications (iOS and Android) using the MobileFirst JavaScript SDK as a plug-in, and native applications that use the MobileFirst Native SDK (iOS, Android, Windows Universal, Windows Phone Silverlight).

You can also create, register, and manage MobileFirst adapters to either local or remote MobileFirst Server instances, and administer projects from the command line or via REST services, or from the MobileFirst Operations Console.

For more information regarding SDK integration in native applications, see the tutorials in the Hello World category.

For more information regarding SDK integration in Cordova applications, see the Integrating MobileFirst Platform Foundation SDK in Pure Cordova Applications tutorial.

Learn more about the MobileFirst CLI in the "MobileFirst Platform Command Line Interface" topic, in the user documentation.

Topics

Installing the Command Line Interface

Before continuing with this tutorial, download the MobileFirst CLI Installer.

Installation and setup instructions are provided in the download page.
The CLI Installer adds the installation folder to your path environment variable so that you can run CLI commands from any directory.

Creating MobileFirst back-end projects

Back-end projects are used for managing hybrid applications, adapters, and other server-side entities. Create a MobileFirst back-end project by using either of these commands:

  • mobilefirst create
  • mfp create

~/projects $ mfp create MyProject
A MobileFirst project was successfully created at /Users/cli-user/projects/MyProject

Managing MobileFirst Server instances

The instance of the Liberty development server is created in the default user directory. For example:
/Users/cli-user/.ibm/mobilefirst/7.1.0.00-build-number/server.

Server commands

Managing a running server

  • mfp start - Starts the server.
  • mfp stop - Stops the server.
  • mfp status - Gives the status of the server, whether it is running or not, its process ID, and the used port number.
  • mfp config - Prompts you to select which configuration setting to change. Available options: default browser, preview type (simple or Mobile Browser Simulator), and more.
  • mfp preview [ --noshell|-n] - Displays a preview of the current application or environment in your default browser.
  • mfp restart - Restarts the local test server.
  • mfp console - Opens the MobileFirst Operations Console in your default web browser.

Managing server definitions

  • mfp server add - Adds a new server definition.
  • mfp server edit - Edits an existing new server definition.
  • mfp server info - Returns information about the existing server or about all servers.
  • mfp server remove - Removes a server definition

Managing client and server artifacts

  • mfp push - A superset of commands allowing for different actions, depending on the current location
    • If called at the root of a MobileFirst back-end project or a Cordova project, the command registers client and server artifacts (.wlapps, .adapters and .war files) in the server.
    • If called at the root of a native project, the command generates required configuration files and registers the application in the server.
    • Additional push commands are also available: --nosend, --password, --minify, and --concatenate. Use mfp help push to learn more.

Creating hybrid applications and environments

Hybrid applications

Before creating the hybrid application, first navigate to the MobileFirst project directory: cd MyProject.
To create a hybrid application, use the mfp add hybrid command. The generated hybrid application is placed inside the apps folder of the current project.

~/projects $ cd MyProject
~/projects/MyProject $ mfp add hybrid MyHybridApp
A new hybrid app was added at /Users/cli-user/projects/MyProject/apps/MyHybridApp

Environments

Use the mfp add environment command to add an environment to the application. You can use this command in the project directory if the project contains only one app. Otherwise, select which app to add the environment to, or call the command from inside the directory of the hybrid app to which the environment should be added.

~/projects/MyProject $ mfp add environment
[?] To which hybrid app would you want to add environments? (Use the arrow keys.)
❯ MyHybridApp
  OtherHybridApp

By using the Interactive Mode, you can select one or more environments to add:

~/projects/MyProject/apps/MyHybridApp $ mfp add environment
[?] What environments you want to add to the hybrid app? (Press the Space key to select.)
❯⬡ iPhone
 ⬡ iPad
 ⬡ Android phone and tablets
 ⬡ BlackBerry 6 and 7 (deprecated)
 ⬡ BlackBerry 10
 ⬡ Windows Phone Silverlight 8
 ⬡ Windows Universal
(Move up and down to reveal more choices.)

To add environments in Direct Mode:

~/projects/MyProject $ mfp add environment iphone,android --app MyHybridApp
A new android environment was added at /Users/cli-user/projects/MyProject/apps/MyHybridApp/android
A new iphone environment was added at /Users/cli-user/projects/MyProject/apps/MyHybridApp/iphone

Application skins

To add an application skin from the CLI, use the mfp add skin command.

Interactive Mode prompts for the platform to target and name. The current working directory must be under an existing hybrid application, and at least one environment must already be added to this app.

~/projects/MyProject/apps/MyHybridApp $ mfp add skin
[?] What platform do you want to target? (Use arrow keys)
❯ Android phone and tablets
  iPhone
[?] What do you want to be your skin name suffix? Your skin folder name will be 'platform.<em><suffix></em>'
A new android skin was added at /Users/cli-user/projects/MyProject/apps/MyHybridApp

To add a skin in Direct Mode:

mfp add skin [--environment|-e android|blackberry|blackberry10|iphone|ipad <name>]

Adding optional features

To add optional features to a hybrid application from the CLI, use the mfp add feature command.

Interactive mode prompts for the features to add:

~/projects/MyProject/apps/MyHybridApp $ mfp add feature
[?] What feature do you want to install in this application? NOTE: Features you have already installed are not shown:
  FIPS 140-2
  IBM Tealeaf SDK
❯ JSONStore
<p>A new JSONstore feature was added at /Users/cli-user/projects/MyProject/apps/MyHybridApp<br />

In Direct Mode, you explicitly mention the feature:

~/projects/MyProject $ cd apps/MyHybridApp/
~/projects/MyProject/apps/MyHybridApp $ mfp add feature jsonstore
A new JSONStore feature was added at /Users/cli-user/projects/MyProject/apps/MyHybridApp

To remove optional features from a hybrid application by using the CLI, use the mfp remove feature command.
Interactive mode prompts for the features to remove:

~/projects/MyProject/apps/MyHybridApp $ mfp remove feature
[?] What feature do you want to uninstall from this application? NOTE: Features you have already uninstalled are not shown: (Use arrow keys)
❯ JSONStore
A JSONStore feature was removed from /Users/cli-user/projects/MyProject/apps/MyHybridApp

In Direct Mode you explicitly mention the feature:

mfp remove feature [fips|jsonstore|tealeaf]

Concatenation and minification

Applicable only for hybrid applications.

Concatenation is the process of merging web resources such as .js and .css files to reduce the amount of files in the application, while minification is process of obfuscating code, making it less readable and more secure.

To concatenate the web resources of a hybrid application, run the command:

~/projects/MyProject/apps/MyHybridApp $ mfp push --concatenate|-c

To minify the web resources of a hybrid application, run the command:

~/projects/MyProject/apps/MyHybridApp $ mfp push --minify|-m

Adding MobileFirst Native SDKs

The MobileFirst Native SDK is available for the following environments: iOS, Android, Windows Universal, and Windows Phone Silverlight.
Adding the Native SDK is possible by using either locally generated artifacts or CocoaPods and Gradle specifically for iOS and Android respectively.

  • If you choose to add the Native SDK by using the locally generated artifacts, first add to the project a NativeAPI "app" by using the mfp add command.
    This "app" is used in the server as a way to identify the client application.
  • If you choose to add the Native SDK by using CocoaPods or Gradle, first follow the tutorials in the Hello World category.
  • After the SDK is added, navigate to the root of the native project and run the command: mfp push.

    ~/projects/myNativeiOSProject $ mfp push

    Depending on the native project, different artifacts are created:

  • mobilefirst folder: Contains .wlapp files which are pushed and registered in the MobileFirst Server after the command is run.
  • worklight.properties (for iOS) or wlclient.properties (for Android and Windows Universal/Phone) containing project metadata.

By default, mfp push attempts to push and register the artifacts in the default server.
Run mfp push --nosend|-n to create the artifacts without also registering in the server.

Creating and testing adapters

To add an adapter, use the mfp adapter add command.

Interactive Mode:

~/projects/MyProject $ mfp adapter add
[?] What do you want to name your MobileFirst Adapter? MyHttpAdapter
[?] What type of adapter would you like? HTTP
[?] Create procedures for offline JSONStore? No
[?] Create procedures for USSD enablement? No
A new HTTP adapter was added at /Users/cli-user/projects/MyProject/adapters/MyHttpAdapter

Direct Mode:
mfp adapter add --type http , or -t for type. The types of adapters that can be added are HTTP, SQL, Cast Iron, SAP Netweaver Gateway, JMS, SAP Jco, and Java.

~/projects/MyProject $ mfp adapter add --type http TestAdapter
A new http adapter was added at /Users/cli-user/projects/MyProject/adapters/TestAdapter

Calling an adapter

Use mfp adapter call for Interactive Mode:

~/projects/MyProject $ mfp adapter call
[?] Which adapter do you want to use? MyHttpAdapter
[?] Which endpoint do you want to use? MyHttpAdapter/getStories
[?] Enter the comma-separated parameters: "world"
[?] How should the procedure be called? GET
Calling GET '/MyProject/adapters/MyHttpAdapter/getStories?params=["world"]'
Response:
{
  "statusCode": 200,
  "errors": [],
  "isSuccessful": true,
  "statusReason": "OK",
  "rss": {
    "feedburner": "http://rssnamespace.org/feedburner/ext/1.0",
    "channel": {
      "pubDate": "Thu, 26 Mar 2015 12:36:00 EDT",
      "title": "CNN.com - World",
      "description": "CNN.com delivers up-to-the-minute news and information on the latest top stories, weather, entertainment, politics and more.",
...

Or to call an adapter in Direct Mode:
mfp invoke [:[\"\"| --file|-f ]]

~/projects/MyProject $ mfp invoke MyHttpAdapter:getStories \"world\"
{
  "statusCode": 200,
  "errors": [],
  "isSuccessful": true,
  "statusReason": "OK",
  "rss": {
    "feedburner": "http://rssnamespace.org/feedburner/ext/1.0",
    "channel": {
      "pubDate": "Thu, 26 Mar 2015 12:36:00 EDT",
      "title": "CNN.com - World",
      "description": "CNN.com delivers up-to-the-minute news and information on the latest top stories, weather, entertainment, politics and more.",
...

Exporting and importing MobileFirst projects

Exporting

By using the export command, you can create a compressed file, which contains the entire MobileFirst project, or the optimized hybrid assets to use in a native application.

Exporting a project in Interactive Mode
mfp export - Running this command in the project root folder prompts you to enter the path and name of the compressed file to export to.
The resulting compressed file is intended to be shared with other MobileFirst developers. The compressed file contains source artifacts and everything another developer would need to build the missing artifacts.

~/projects/MyProject $ mfp export
[?] Where do you want to export the project? /Users/cli-user/Desktop
[?] What do you want to name your zip project? MyProject
Project successfully exported to /Users/cli-user/Desktop/MyProject.zip

Exporting a project in Direct Mode
mfp export [] - If run from the root folder of the project, direct mode takes one additional argument, which is the full path to the compressed file to create.

~/projects/MyProject $ mfp export /Users/cli-user/Documents/MyProject.zip
Project successfully exported to /Users/cli-user/Documents/MyProject.zip

Exporting hybrid assets in Interactive Mode

  1. First run the mfp build command to make sure that the app is built.
  2. Run the hybrid asset export within the environment folder of the existing hybrid app. Interactive mode asks whether to include the native libraries, the path, and file name of the compressed file to export to.
    The native libraries are built files. Native application IDEs need to ensure that the hybrid assets can be used in a native app.

~/projects/MyProject/apps/MyHybridApp/iphone $ mfp export
[?] Would you like to include the native libraries? Yes
[?] Where do you want to export the project? /Users/cli-user/Documents
[?] What do you want to name your zip project? MyiOSHybridApp
Project successfully exported to /Users/cli-user/Documents/MyiOSHybridApp.zip

Exporting hybrid assets in Direct Mode
mfp export [] [-i | --includeNativeLibs] - In direct mode, provide the full path to export hybrid assets. If the arguments -i or --includeNativeLibs are supplied, the native libraries are included.

~/projects/MyProject/apps/MyHybridApp/iphone $ mfp export /Users/cli-user/Documents/MyiOSHybridApp.zip -i
Project successfully exported to /Users/cli-user/Documents/MyiOSHybridApp.zip

Importing CLI-generated projects into MobileFirst Studio

  1. From Eclipse, select File > Import > General > Existing Projects into Workspace and click Next.
  2. Select the root folder of the project and click Finish.

For more information, see the topics about the Command Line Interface (CLI) in the user documentation.

Optimizing applications with CLI

You can reduce the size of your application, obfuscate its JavaScript, reduce its load time, or otherwise improve its performance by using minification and concatenation.

See the topic about optimizing applications with CLI, in the user documentation.

Helpful commands

  • mfp help – Shows how to use all the commands.
  • mfp help command-name - Shows help for a specific command.
  • mfp info – Returns the OS release, system memory, node.js version, and MobileFirst CLI version.
Last modified on August 22, 2016