How to Use the Shopify CLI to Build Shopify Apps

Timothy Ware on February 01, 2022

Shopify’s CLI (Command Line Interface) is one of the best tools for building Shopify apps

Shopify CLI helps Shopify Partners perform a number of important app-building tasks. This includes generating Node.js, PHP, and Ruby on Rails apps, as well developing app extensions, themes, and Shopify Scripts (currently in beta).

Shopify CLI also automates a number of these tasks, which shortens and simplifies the app-building cycle significantly.

In this guide we’ll cover some of the tasks you can perform with Shopify CLI and the benefits of this specific tool for app developers.

 

What is Shopify CLI for apps?

 CLI stands for Command Line Interface. CLI tools are scripts, programs, and libraries that have been created for a specific developmental purpose.

Shopify announced the beta release of the Shopify CLI for apps in November 2019. Their goal was to help developers speed up the app creation process and boost productivity.

How? By releasing a tool that could help in two ways: create a scaffolding for app code, and partially automate app development. 

The Shopify CLI for apps is currently on version 1.1. Since the beta release, there have been major improvements to its robustness, and it can now be installed easily across more platforms, including Windows 10. 

 

What are the benefits of using Shopify CLI? 

 Shopify CLI simplifies the entire app development process. It removes some of the major barriers to entry first-time developers face, rendering app development more accessible to all kinds of users.

It’s also designed to be highly flexible, so it can be used for a range of different types of apps.

These principles of flexibility, adaptability and accessibility manifest within a number of key design decisions:

  • CLI can be used on Windows as well as Mac

  • Developers install the program in whatever language is most comfortable to them

  • Tools are open source and don’t require escalating privileges

  • Operations don’t self-destruct; users are in full control of deleting files and projects

Let’s take a look at Shopify CLI in action!

All the data your Shopify Partners app needs

Know instantly how your Shopify app is performing, what’s working, what needs improving, and where to focus next.

 

How to use Shopify CLI

Shopify CLI for apps is a highly intuitive tool. Shopify and GitHub also provide detailed tutorials for every step of the way.

1. Installation

Shopify CLI can be installed on a number of different operating systems. The easiest way to do this is through your computer’s own command line. Here is a full list of software requirements.

2. Creating a project

 When you go to create an app in Shopify CLI, you will be prompted to input some key information about yourself, such as your organization, development store, and the type of app you want to make (here you have the option to build one with a node.js backend and React frontend, or use Ruby on Rails). Shopify will then create your app on the Shopify Partner Dashboard.

Take a look at this model from the Shopify website:

Next, Shopify CLI will run a tunnel for you with “shopify serve”. Your app is now accessible to the Internet via a “https” port, which is an authentication requirement for Shopify. This will then tunnel your app using ngrok, as well as run your server for local development.

3. App population for testing

So how do you know if it’s working?

Shopify CLI has a test function built in: you can populate your app exclusively for testing purposes. If you run the command ‘’shopify populate’’, you can choose to populate your app with products, customers, and draft orders.

4. Deployment

As the name suggests, the “shopify deploy” command deploys your app to external platforms. Currently, Heroku is the only available external platform, but more are in development (and by the time you’re reading this, might already be available!)

 

How Shopify built the Shopify CLI for apps

Shopify has built many tools to help its partners create apps for the Shopify App Store. That’s just one of the reasons we recently argued it is better to develop apps for Shopify than WooCommerce.

Some of the previous command line tools built by Shopify use Node, Go, and Ruby. Shopify ultimately settled on Ruby for the following reasons: 

  • Ruby is more approachable than Go.
  • It can be difficult to manage paths and installations for a Node-based tool, even though it has some great libraries for writing CLIs (yargs, ink, etc.)
  • Go would make it more difficult for Shopify Partners to contribute to the tool over time.
  • Shopify dev teams are already familiar with Ruby, and built the CLI-kit framework, and the CLI-UI collection of command line UI patterns using Ruby.

 

Using the Shopify CLI for themes

Shopify Partners can now use Shopify CLI for apps to safely download, develop, preview, and test changes within development themes before launch. Changes are instantly populated, so you can preview as you go. Once the theme is ready, it can be pushed and published directly from the command line.

You can also use CLI together with Shopify GitHub integration to add version control to any themes you’re developing. If you want to take a look at how that works, this tutorial takes you through all the steps of theme development.

What commands are available on Shopify CLI?

 Let’s run through some functions of Shopify CLI. Once you’ve created a Node.js app, the following commands are available:

  •  connect: This will connect or reconnect an existing project to a Shopify Partner organization and/or store. It will create or update the .env file and create the .shopify-cli.yml file.
    • Usage: shopify connect
  • create: This will create a new project.
    • Usage: shopify create [ node | rails ]
  • logout: This will log out of a currently authenticated Shopify Partner organization / store, or clear invalid credentials
    • Usage: shopify logout
  • version: This will print the version number.
    • Usage: shopify version
  • deploy: This will deploy the current Node project to a hosting service. Note that Heroku is currently the only option, but Shopify plans to add more in the future.
    • Usage: shopify deploy [ heroku ]
  • generate: This will generate code in your Node project. It supports generating new billing API calls, new pages, or new webhooks.
    • Usage: shopify generate [ billing | page | webhook ]
  • open: This will open your local development app in the default browser.
    • Usage: shopify open
  • populate: This will populate your Shopify development store with example customers, orders, or products.
    • Usage: shopify populate [ customers | draftorders | products ]
  • serve: This will start a local development node server for your project and a public ngrok tunnel to your localhost.
    • Usage: shopify serve
  • tunnel: This will start or stop an http tunnel to your local development app using ngrok.
    • Usage: shopify tunnel [ auth | start | stop ]

Improve your app development with Shopify CLI and Baremetrics

Shopify is the leading ecommerce platform today, thanks to its 1.7 million loyal merchants, as well as the 6,000 third-party apps currently for sale in the Shopify App Store.

Shopify is always striving to create a better, more streamlined process for its developers. Shared values based on accessibility, open communication and innovation is why Baremetrics built our integration for Shopify apps.

With our free trial, you can access the best of what both Baremetrics and Shopify have to offer: better app development and full financial insights, all in one place.

Timothy Ware

Tim is a natural entrepreneur. He brings his love of all things business to his writing. When he isn’t helping others in the SaaS world bring their ideas to the market, you can find him relaxing on his patio with one of his newest board games. You can find Tim on LinkedIn.