Introduction
Getting started with a new project should be as simple as possible, even for someone who is not technical. As a maintainer, you must make sure that anyone can clone your project and get it up and running in a few minutes.
After you clone a project, you should follow two steps:
- Setup
- Start
In this example, the project is a web application, but it works for other projects too.
Setup
You should have a small bash script called bin/setup in every project. You
could use Ruby
opens a new window
for the script if that’s
what you prefer.
Rails
opens a new window
has had a bin/setup since 2014
opens a new window
and so should your project! This is the default ./bin/setup
opens a new window
in a Rails application.
Thoughtbot
opens a new window
wrote a great article about
their bin/setup convention:
./bin/setup
opens a new window
At OmbuLabs
opens a new window
, one of our latest bin/setup scripts
looks like this:
In order for our script to work, you must have a .env.sample file that
has some default values for your .env file. Every project you start must
have a .env file with environment configuration. Why?
Read here
opens a new window
We use Ruby opens a new window for our setup script because all of our development environments have been setup with this script: OmbuLabs Setup opens a new window
If you are using Rails, starting an application is simple:
But, what if you want to use something else? Let’s say you want to use Sinatra opens a new window with Shotgun opens a new window . Then you would need to start the server like this:
If you are using Bundler opens a new window , then you would need to run it like this:
bundle exec shotgun config.ru
What if you want to use Foreman opens a new window ?
You get the point. There are way too many ways to start a web application. We
need to standardize this into something flexible like ./bin/start.
One of our latest bin/start scripts looks like this:
From now on, all the web applications that we build at OmbuLabs opens a new window will be able to get started like this:
It won’t matter if we use Foreman, Sinatra,
Cuba
opens a new window
, Rails, Shotgun, or whatever.
bin/start will know how to get the application started in a development
environment.
Why
I love how simple it can be to tell anyone to clone the project and run these steps:
cd path/to/project
./bin/setup
./bin/start
A web designer that has no experience with Ruby/Rails can setup and start a web application in a few minutes.
I’m a big fan of Convention over Configuration opens a new window . Also, I hate it when it takes me half a day to setup a new application in my environment. It should never take more than a few minutes.