Mastering Electrode Native Platform Commands (with examples)
Electrode Native is a platform that empowers developers to create and manage native mobile applications using JavaScript. At the heart of Electrode Native lies its comprehensive command-line client, ern
, which facilitates everything from project creation to container transformation. In this article, we delve into several essential use cases of the ern
command to illustrate its functionality and provide practical examples.
Create a New ern
Application (MiniApp
)
Code:
ern create-miniapp application_name
Motivation:
Creating a new MiniApp
is often the initial step for developers when starting a new project in Electrode Native. A MiniApp
functions as a modular unit of code and is a core building block for any larger Electrode Native application. Beginning with a MiniApp
allows for testing new features in isolation and promotes reusable code segments.
Explanation:
create-miniapp
: This command instructsern
to initialize a newMiniApp
.application_name
: This argument specifies the name for the newMiniApp
. The name should follow standard naming conventions as it will be used as an identifier within Electrode Native.
Example Output:
Creating a new Electrode Native MiniApp 'application_name'...
MiniApp successfully created at /path/to/application_name
Run One or More MiniApps
in the iOS/Android Runner Application
Code:
ern run-ios|android
Motivation:
Running a MiniApp
within the interface of an iOS or Android runner is crucial for testing and development. This command allows developers to simulate how the MiniApp
behaves within a native environment before deploying the application widely. It serves as a practical debugging tool to ensure the MiniApp works as expected across different platforms.
Explanation:
run-ios|android
: This section of the command specifies the target platform. Omitting a specific MiniApp will result in the runner executing all existing MiniApps.
Example Output:
Launching MiniApp in Android Runner...
Successfully running on Android Emulator.
Create an Electrode Native Container
Code:
ern create-container --miniapps /path/to/miniapp_directory --platform ios|android
Motivation:
Containers are fundamental as they package MiniApps
into deployable units for native applications. Creating a container ensures that your MiniApps are properly organized and ready to be incorporated into larger applications. This workflow is important for maintaining efficiency and coherence in the development process.
Explanation:
create-container
: This segment triggers container creation.--miniapps /path/to/miniapp_directory
: Specifies the directory path where yourMiniApp
files are located.--platform ios|android
: Indicates which platform the container is being prepared for.
Example Output:
Building container for platform iOS...
Container created at /path/to/output_directory.
Publish an Electrode Native Container to a Local Maven Repository
Code:
ern publish-container --publisher maven --platform android --extra '{"groupId":"com.walmart.ern","artifactId":"quickstart"}'
Motivation:
Publishing containers to a local Maven repository is essential for shared access within development teams and facilitating centralized version control. This practice ensures that the exact version of a container can be consistently retrieved and utilized across various projects.
Explanation:
publish-container
: Initiates the process to publish the container.--publisher maven
: Designates Maven as the publishing repository.--platform android
: Indicates that the target platform is Android.--extra '{"groupId":"com.walmart.ern","artifactId":"quickstart"}'
: This JSON structured argument provides additional metadata to the Maven repository such asgroupId
andartifactId
, critical for artifact identification.
Example Output:
Publishing container to Maven repository...
Successfully published container with artifactId 'quickstart'.
Transform an iOS Container into a Pre-compiled Binary Framework
Code:
ern transform-container --platform ios --transformer xcframework
Motivation:
Transforming a container into a xcframework
is key for creating a pre-compiled version of an iOS application. This transformation facilitates distribution by reducing integration complexity, and it is generally recommended when you want to leverage the performance benefits of pre-compiled binaries.
Explanation:
transform-container
: Converts the container into another format.--platform ios
: Targets the iOS platform specifically.--transformer xcframework
: Specifies the transformation format (intoxcframework
).
Example Output:
Transforming container to xcframework...
Container successfully transformed into xcframework at /path/to/output_directory.
List All Installed Versions of Electrode Native
Code:
ern platform versions
Motivation:
Knowing the versions of Electrode Native that are installed on your system is vital for ensuring compatibility across projects and teams. This command allows developers to manage dependencies efficiently and understand the environment they are working within, aiding in debugging version-related issues.
Explanation:
platform versions
: Requests a list of all versions of Electrode Native currently installed on the system.
Example Output:
Electrode Native Versions:
- 0.40.0
- 0.39.0
- 0.38.1
Set a Logging Level
Code:
ern platform config set logLevel trace|debug
Motivation:
Adjusting the logging level is crucial for effective troubleshooting and debugging. More detailed logs can provide insight into complicated issues, helping developers to identify and correct errors. Setting appropriate logging levels helps in maintaining the balance between performance and insight.
Explanation:
platform config set logLevel
: This sequence allows you to configure the logging settings.trace|debug
: The desired logging level, wheretrace
provides the most detailed logs anddebug
is slightly less verbose but still detailed.
Example Output:
Setting log level to debug...
Log level successfully set to debug.
Conclusion:
The Electrode Native platform—and its ern
command-line interface—offers versatile options for mobile application development. From the initial creation of MiniApps
to the intricate transformation of iOS binaries, mastering these commands can greatly enhance productivity and streamline development processes within the Electrode Native environment. Understanding each command and its functional nuances ensures that developers can harness the full potential of Electrode Native to create efficient, scalable, and maintainable mobile applications.