By Your Command! Meet the Command Line Interface
chevron down

By Your Command! Meet the Command Line Interface

Today is another exciting landmark in the evolution of the Fitbit OS Software Development Kit (SDK). We’re proud to announce a major enhancement: an entirely new way to build apps and clock faces for Fitbit OS. We have created a command-line interface that is compatible with macOS, Windows, and Linux, and allows developers to build and install Fitbit OS projects while using their favorite code editors, and their preferred version control system. This update takes Fitbit OS app development beyond Fitbit Studio for the very first time.

To date, developers have built and published more than 1,100 apps and clock faces for Fitbit Ionic and Fitbit Versa using Fitbit Studio since its initial launch last fall. A Command Line Interface (CLI) has always been high on the requested features list among the developer community, as was the simulator we launched several months ago, and we’re delighted to make this CLI available starting today.

Highway to Shell

The CLI tools are comprised of the toolchain required to create apps and clock faces, and an interactive shell that allows developers to execute commands to build, install, and screenshot. The shell also provides source-mapped console logs and build output logs, much like what’s currently provided in Fitbit Studio.

Installation and logging is handled via the same developer bridge used by Fitbit Studio. Simply connect your Fitbit OS device, mobile phone, or the simulator to the developer bridge, and you’re ready to go.

Before You Begin

If you’re not already building applications using the Fitbit OS SDK, you’ll want to begin with our general Getting Started guide. It covers important things like user account and device setup — so don’t miss it. If you’re already familiar with Fitbit OS development using Fitbit Studio, you can dive straight into the CLI tools!

Prerequisites

All you need to get started is Node.js 8.x+ on macOS, Windows, or Linux.

Creating a New Project

Once you’ve installed the prerequisites, you can create a new project by executing single command.

npx create-fitbit-app <project-name>

This will install the Fitbit toolchain and shell, and will then take you through a few simple questions to generate the minimal scaffolding required for either an app or a clock face.

Building and Installing Your Project

Once you’ve created your new project, or added the required dependencies to an existing project, you can build and install your project.

npx fitbit-build
npx fitbit
fitbit$ install

Let’s Get Visual

One of the biggest benefits of the new CLI tools is the ability to use your preferred source code editor. Many tools such as Microsoft VSCode allow you to run a terminal shell directly within the editor, making it easy to execute the build and install commands, and view logs without leaving the editor.

Git This Party Started

Another huge benefit to the new CLI tools is the ability to use your preferred version control system, such as Git. By using a web based Git hosting service, such as Github, you can maintain a full history of the changes in your project and easily share your Fitbit OS projects with coworkers, friends, or even make it open source so anyone can benefit from it.

The Fitbit organization and OSS repository on Github contain a large number of open source projects that can easily be cloned and used as the starting point for a new project.

All the Modules!

We know what you’re thinking, npm packages would make my project amazing! In theory, yes, but in reality you would still be constrained by the device capabilities and memory limitations.

Imported modules should be small, and serve a single purpose. They should ideally be packaged as ES6 modules, so that any unused code can be automatically excluded.

The companion is less resource constrained, so you’re likely to have a better outcome using npm packages there.

Be aware that many existing npm packages are specifically designed for use in the browser, or node.js, but Fitbit OS is a different platform and modules may not behave as intended, cause build failures, or even crash your application on startup.

If you do create npm modules you’d like to share with the community, please use the package keyword "fitbitdev". Modules can only contain JavaScript at this time, CSS/SVG and other resources are not supported.

Thirsty for More?

We know you need more examples and further information, that’s why we’ve published a new CLI guide to quench your thirst for knowledge.

What’s Next

This is just the beginning of the CLI tools for Fitbit OS, over the coming months we’ll be continuing to expand and evolve them with new functionality and integrations.

Is this the end for Fitbit Studio? Nope! We added some enhancements and optimizations to the build process when we created the CLI tools, and we’ll be deploying an update to Fitbit Studio soon in order to bring those enhancements to everyone. After that, you’ll continue to see the regular updates to which you’ve become accustom.

We’re really excited to see how you use these new tools, build upon them, integrate them with other editors, and discover neat tips and tricks. If you build an integration or extension, or anything that could be useful to other developers, please share it on our SDK Community Forum, Twitter, or Discord.

Happy hacking!